題名の通りです。__call__メソッドがないのにも関わらず呼び出しが出来てしまいます。
また、その挙動がよく分かりません。実行してみた感じだとそのオブジェクトの初期値?的なものが出力されているように感じます。
引数を与えるとその値がそのまま出力されます。ここら辺の仕様が確認できるところはありますでしょうか?
Python
1import pprint 2 3n = 1 4n_type = type(n) # <class 'int'> 5n_type() # 0 6n_type.__call__() # 0 7 8pprint.pprint(dir(n), compact=True) 9""" 10['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', 11 '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', 12 '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', 13 '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', 14 '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', 15 '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', 16 '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', 17 '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', 18 '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', 19 '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', 20 '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 21 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 22 'real', 'to_bytes'] 23""" 24pprint.pprint(dir(type(n)), compact=True) 25""" 26['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', 27 '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', 28 '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', 29 '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', 30 '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', 31 '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', 32 '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', 33 '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', 34 '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', 35 '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', 36 '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 37 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 38 'real', 'to_bytes'] 39"""
回答2件
あなたの回答
tips
プレビュー