int方法

代码

#int内部功能
name='Kamil.Liu'
age=18
num=-11
print(dir(age))
print(age.bit_length())#返回表示当前数字占用的最少位数
print(num.__abs__())#__abs__:返回绝对值(或abs(-11))
print(age.__add__(num)) 
'''
__add__:相加(+)   
__bool__:转换为布尔值     
__divmod__:相除,得到商和余数组成的元祖 
__and__:与运算
'''
print(age.__eq__(18)) #__eq__:  等于(==)
print(type(age.__float__())) #__float__:根据原有数据,创建新的浮点型数据
'''
__floordiv__:地板除(//)
__ge__:大于等于
__gt__:大于
__init__:构造方法
__pow__:幂运算
__init__:构造方法
'''

 结果

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

 

公众号请关注:侠之大者
原文地址:https://www.cnblogs.com/kamil/p/5160866.html