int内部功能介绍

 

对象具有的功能都是在类里面找的

 

整数 int

如:22 、33、44

age = 22
print(type(age))
结果
<class 'int'>

>>> dir(int)
['__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']

 

bit_length  返回当前数字占用的最少位数,2进制表示10进制位

>>> age = 18

>>> age.bit_length()
5             #最少要用5位

>>> bin(18)
'0b10010'

 

__abs__ 绝对值

>>> age = -19
>>> age.__abs__()
19

>>> abs(-19)
19

绝对值属于常用功能,系统将它设置为内置函数,直接用abs也可以调用,在直接使用abs时,内部abs拿到这个数字,先创建一个数字对象,执行这个对象的.__abs__方法。

__add__

>>> age
-19
>>> age.__add__(100)
81

>>> 1+1
2

在语法堂里面,当直接使用加号时,也是先创建一个1的对象,然后在执行对象方法.__add__将另外一个1传进来,得到结果2。

 __and__  于运算(它且它)

__bool__  布尔值

 

 __divmod__

test = 95
pager = 10
result = test.__divmod__(10)
print(result)

结果(9,5)

 

__eq__   

age = 18
result = age.__eq__(19)
print(result)

结果(False)

 

__float__

age = 18
print(type(age))
result = age.__float__()
print(type(result))

结果

<class 'int'>
<class 'float'>

 

__floordiv__  地板除

age = 5
result = age.__floordiv__(6)
print(result)

#快捷方式5//6

结果  0

__ge__   大于等于

 

__or__  相当于  a|b

 

__rdivmod__ 反过来除

 

长整型、浮点型类似于int

 

转载于:https://www.cnblogs.com/hongweipython/p/8657933.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值