+ 2
How to create an object in python and define a method with Parameters?
2 odpowiedzi
+ 7
class Animal:
def __init__(self, name, species):
self.name = name
self.species = species
def jump(self, hops):
print(self.name + " jumps " + str(hops) + " hops.")
cang = Animal("Goory", "Cangaroo")
cang.jump(4)
# Goory jumps 4 hops.
+ 1
Thanks