Python Editor

Python | Lesson3 | Classes


class Dog:
    def __init__(self, dogName, dogBreed):
        self.dogName = dogName
        self.dogBreed = dogBreed

    def bark(self):
        print("Woof Woof Woof!")

    def printdogName(self):
        print("dogName is {self.dogName} and dogBreed is {self.dogBreed}.")

dog1 = Dog("pppp", "Golden Retriever")
dog2 = Dog("bbbb", "Labrador Retriever")

dog1.bark()  
dog2.printdogName()


1 comment:

  1. class Cat:
    def __init__(self, catName, catBreed):
    self.catName = catName
    self.catBreed = catBreed

    def meow(self):
    print("Meow Meow Meow!")

    def printcatName(self):
    print("catName is {self.catName} and catBreed is {self.catBreed}.")

    cat1 = Cat("cccc", "Ginger")
    cat2 = Cat("kkkk", "Mix")

    cat1.meow()
    cat2.printcatName(

    - Srijan

    ReplyDelete