以下のソースの出力結果について教えてください。
python
1class Shape(): 2 def what_am_i(self): 3 print("I am a shape.") 4 5class Square(Shape): 6 square_list = [] 7 def __init__(self, s1): 8 self.s1 = s1 9 self.square_list.append(self.s1) 10 11 def calculate_perimeter(self): 12 return self.s1 * 4 13 14 def what_am_i(self): 15 super().what_am_i() 16 print("I am a Square.") 17 18a_square = Square(29) 19print(a_square.square_list) 20print(a_square.what_am_i()) 21another_square = Square(93) 22print(another_square.square_list) 23print(another_square.what_am_i()) 24
これに対する出力結果は以下です。
python
1[29] 2I am a shape. 3I am a Square. 4None 5[29, 93] 6I am a shape. 7I am a Square. 8None
print(a_square.what_am_i()),print(another_square.what_am_i())でNoneが出力結果にでる理由がわかりません。
ShapeクラスとSquareクラスのwhat_am_iが処理されるだけではないのでしょうか?
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/22 07:57