0
Python Classes
Why does this return None at the end? class Beginner_Pokemon(): Level = 5 Gender = 'Rather not say' def __init__(self,name,move_1,move_2): self.name = name self.move_1 = move_1 self.move_2 = move_2 def Moves(self): return print(f'Move 1: {self.move_1} \nMove 2: {self.move_2}') @classmethod def Pick_Gender(cls,New_Gender): cls.Gender = New_Gender Piplup = Beginner_Pokemon('Piplup','Pound','Leer',) Piplup.Pick_Gender('Female') print(Piplup.Moves())
3 ответов
+ 5
class Beginner_Pokemon():
Level = 5
Gender = 'Rather not say'
def __init__(self,name,move_1,move_2):
self.name = name
self.move_1 = move_1
self.move_2 = move_2
def Moves(self):
return f'Move 1: {self.move_1} \nMove 2: {self.move_2}'
@classmethod
def Pick_Gender(cls,New_Gender):
cls.Gender = New_Gender
Piplup = Beginner_Pokemon('Piplup','Pound','Leer',)
Piplup.Pick_Gender('Female')
print(Piplup.Moves())
+ 3
Oh ye forgot, accidently left print in it, so it printed and reurned nothing, thanks
0
Try above you are not returning anything from the Moves.