Horje
python code to demonstrate inheritance with animal class Code Example
python code to demonstrate inheritance with animal class
class Animal():
    def __init__(self, name, age):
        self.name = name
        self.age = age 

    def speak(self):
        print("I am", self.name, "and I am", self.age, "years old")


class Dog(Animal):
    def __init__(self, name, age)
        self.name = name
        self.age = age
        self.type = "dog"

    # Since we inherit from the animal class we can use the method speak on Dog objects


tim = Dog("Tim", 5)
tim.speak() # This will print "I am Tim and I am 5 years old"




Python

Related
how do i select a range of columns by index Code Example how do i select a range of columns by index Code Example
how to get tomorrow date in python Code Example how to get tomorrow date in python Code Example
python enumerate() Code Example python enumerate() Code Example
https://stackoverflow.com/questions/7066121/how-to-set-a-single-main-title-above-all-the-subplots-with-pyplot Code Example https://stackoverflow.com/questions/7066121/how-to-set-a-single-main-title-above-all-the-subplots-with-pyplot Code Example
fibonacci formula python Code Example fibonacci formula python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10