Creating Simple Classes and Objects in Python


Define a class and create instances of that class.

Source Code

class Dog:
    def __init__(self, name):
        self.name = name
    def bark(self):
        print(f"{self.name} says woof!")

my_dog = Dog("Rex")
my_dog.bark()
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments