+ 2

How to create an object in python and define a method with Parameters?

25th Nov 2017, 9:17 PM
SaĂșl ChĂĄvez SĂĄnchez
SaĂșl ChĂĄvez SĂĄnchez - avatar
2 Answers
+ 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.
25th Nov 2017, 10:16 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 1
Thanks
25th Nov 2017, 11:49 PM
SaĂșl ChĂĄvez SĂĄnchez
SaĂșl ChĂĄvez SĂĄnchez - avatar