お世話になります。
python入門(2&3)対応で学習しています。
p235部分で演算子のカスタマイズ:特殊メソッドを使うことでインスタンスの様々な挙動をカスタマイズできる。例として"imul"を用いて
”*=”の算術演算子をカスタマイズする
class Shape(object):
... def init(self, width):
... self.width = width
... def imul(self, factor):
... self.width *= factor
...
shape = Shape(3)
shape *= 2
shape.width
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'width'
object has no attribute 'width'となりますが(オブジェクトは属性『幅』を全然持っていない)
何か間違っているのでしょうか?記載通りにやりましたがなぜこのようなエラーになるのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/20 00:33