📅  最后修改于: 2022-03-11 14:45:47.977000             🧑  作者: Mango
class Dog:
def bark(self):
print("Woof!")
def roll(self):
print("*rolling*")
def greet(self):
print("Greetings, master")
def speak(self):
print("I cannot!")
# Creating the Dog class instance and saving it to the variable
clyde = Dog()
clyde.bark() # --> Woof!
clyde.roll() # --> *rolling*
clyde.greet() # --> Greetings, master
clyde.speak() # --> I cannot!
# Creating another Dog instance
jenkins = Dog()
jenkins.bark() # --> Woof!
jenkins.roll() # --> *rolling*
# .. And other methods
# .. Infinite objects can be created this way, all implementing the same methods defined in our class