class hero :
# Class Attribute
planet = 'Asgard'
# Initializer / Instance Attributes
def __init__(self, name, age):
self.name = name
self.age = age
# instance method
def description(self):
return "{} is {} years old".format(self.name, self.age)
# instance method
def speak(self, sound):
return "{} says '{}'".format(self.name, sound)
# Instantiate the object
thor = hero("Thor", 36)
# call our instance methods
print(thor.description())
print(thor.speak("I am the son of God"))
print ("{} is form {}".format(thor.name, thor.planet))
No comments:
Post a Comment