首页 > 解决方案 > Python 中包含哪些数据 int 对象?

问题描述

当我在 python 中编写a = 1时,a 是对 int 类对象的引用——如果我错了,请纠正我。那么,类 int 的对象是只包含值 1还是包含其他东西呢?我对此进行了搜索,但答案对我没有帮助。

标签: pythonclassobject

解决方案


当我在 python 中编写a = 1时,a 是对 int 类对象的引用

这是对的。

那么,类 int 的对象是只包含值 1 还是包含其他东西呢?

它还包含许多其他内容,请参阅:

>>> a = 1
>>> isinstance(a, object)
True
>>> a
1
>>> a.real
1
>>> a.imag
0
>>> a.__dir__()
['__repr__', '__hash__', '__getattribute__', '__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', '__add__', '__radd__', '__sub__', '__rsub__', '__mul__', '__rmul__', '__mod__', '__rmod__', '__divmod__', '__rdivmod__', '__pow__', '__rpow__', '__neg__', '__pos__', '__abs__', '__bool__', '__invert__', '__lshift__', '__rlshift__', '__rshift__', '__rrshift__', '__and__', '__rand__', '__xor__', '__rxor__', '__or__', '__ror__', '__int__', '__float__', '__floordiv__', '__rfloordiv__', '__truediv__', '__rtruediv__', '__index__', '__new__', 'conjugate', 'bit_length', 'to_bytes', 'from_bytes', 'as_integer_ratio', '__trunc__', '__floor__', '__ceil__', '__round__', '__getnewargs__', '__format__', '__sizeof__', 'real', 'imag', 'numerator', 'denominator', '__doc__', '__str__', '__setattr__', '__delattr__', '__init__', '__reduce_ex__', '__reduce__', '__subclasshook__', '__init_subclass__', '__dir__', '__class__']

推荐阅读