+ 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 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.
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