python - Python 中包含哪些数据 int 对象?
问题描述
当我在 python 中编写a = 1
时,a 是对 int 类对象的引用——如果我错了,请纠正我。那么,类 int 的对象是只包含值 1还是包含其他东西呢?我对此进行了搜索,但答案对我没有帮助。
解决方案
当我在 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__']
推荐阅读
- nuxt.js - 如何始终重定向到 nuxtjs 中的浏览器语言页面?
- php - android 和 php api 的响应是正确的,而通过 android 应用程序删除数据时没有删除数据?
- javascript - 如何在博客页面中获取搜索栏以搜索精选文章?
- php - 已解决:当 MySQL 数据包含重音符号时,PHP json_encode 返回 BLANK
- javascript - 使用 vue-virtual-scroler 和 Vuetify 2.0 滚动时出现视觉故障 - 不流畅的可视化
- javascript - 是否可以在 Tempus Dominus bootstrap 4 datetimepicker 中将 minDate 和 maxDate 设置为同一天?
- python-3.x - 如何修复 HTTPSConnectionPool - 连接到数据库服务器时出现读取超时错误
- c++ - 在多个头文件中使用枚举状态的问题
- javascript - 如何在wordpress cms中使用css从div中删除属性
- c++ - 在函数本身而不是在主函数中声明由参数限制的变量有什么问题?