int类中的方法(二)
2018-06-17 22:45:29来源:未知 阅读 ()
25.__pos__(self,*args,**kwargs)
def __pos__(self, *args, **kwargs): # real signature unknown
""" +self """
pass
26.__pow__(self,*args,**kwargs)
def __pow__(self, *args, **kwargs): # real signature unknown
""" Return pow(self, value, mod). """
"""返回一个数的乘冪,并且这个函数有第三个参数,求冪之后还可以求余数"""
pass
>>> a = 3
>>> a.__pow__(3)
27
>>> a.__pow__(3,4)
3
27.__radd__(self,*args,**kwargs)
def __radd__(self, *args, **kwargs): # real signature unknown
""" Return value+self. """
"""由self+value变成value+self"""
pass
__radd__(self,value)是变换加数与被加数的位置,self+value变为value+self.如下所示:
>>> a = 13
>>> b = 14
>>> a.__radd__(b)
27
>>> a.__add__(b)
27
28.__rand__(self,value)
def __rand__(self, *args, **kwargs): # real signature unknown
""" Return value&self. """
pass
self&value改变给value&self,实例如下:
>>> a = 10
>>> b = 50
>>> a.__rand__(b)
2
>>> a.__and__(b)
2
29.__rdivmod__()
def __rdivmod__(self, *args, **kwargs): # real signature unknown
""" Return divmod(value, self). """
pass
__rdivmod__(slef,value)等价于__divmod__(value,self),其中div是单词除的缩写,返回除数,mod是余数的缩写,返回余数,所以结果为一个数组,用于存储商和余数部分。
>>> a = 55
>>> b = 15
>>> a.__divmod__(b)
(3, 10)
>>> a.__rdivmod__(b)
(0, 15)
30.__rper__(self,*args,**kwargs)
def __repr__(self, *args, **kwargs): # real signature unknown
""" Return repr(self). """
pass
31.__rfloordiv__(self,value)
def __rfloordiv__(self, *args, **kwargs): # real signature unknown
""" Return value//self. """
pass
__rfloordiv__(self,value)等价于__floordiv__(value,self),两个处相除之后进行舍入。
>>> a = 5
>>> b = 3
>>> a.__rfloordiv__(b)
0
>>> a.__floordiv__(b)
1
31.__round__(self,*args,**kwargs)
def __round__(self, *args, **kwargs): # real signature unknown
"""
四舍五入
Rounding an Integral returns itself.
Rounding with an ndigits argument also returns an integer.
"""
pass
32.__rpow__(self,*args,**kwargs)
def __rpow__(self, *args, **kwargs): # real signature unknown
""" Return pow(value, self, mod). """
pass
看一个例子如下:
>>> a = 4
>>> b = 3
>>> a.__pow__(b)
64
>>> a.__rpow__(b)
81
>>> a.__pow__(b,3)
1
>>> a.__rpow__(b,3)
0
33.__rrshift__(self,value)
def __rrshift__(self, *args, **kwargs): # real signature unknown
""" Return value>>self. """
pass
34.__rshift__(self,value)
def __rshift__(self, *args, **kwargs): # real signature unknown
""" Return self>>value. """
pass
35.__rsub__(self,*args,**kwargs)
def __rsub__(self, *args, **kwargs): # real signature unknown
""" Return value-self. """
pass
36.__rtruediv__(self,value)
def __rtruediv__(self, *args, **kwargs): # real signature unknown
""" Return value/self. """
"""把除数与被除数进行颠倒"""
pass
实例如下:
>>> a = 10
>>> b = 4
>>> a.__rtruediv__(b)
0.4
>>> a.__truediv__(b)
2.5
37.__rxor__(self,value)
def __rxor__(self, *args, **kwargs): # real signature unknown
""" Return value^self. """
pass
38.__sizeof__(self,*args,**kwargs)
def __sizeof__(self, *args, **kwargs): # real signature unknown
""" Returns size in memory, in bytes """
pass
39.__str__(self,*args,**kwargs)
def __str__(self, *args, **kwargs): # real signature unknown
""" Return str(self). """
"""将数字转换为字符串"""
pass
将数字转化为字符串,等价于str(a).实例如下:
>>> a = 15
>>> a.__str__()
'15'
>>> str(a)
'15'
40.__sub__(self,*args,**kwargs)
def __sub__(self, *args, **kwargs): # real signature unknown
""" Return self-value. """
pass
41.__truediv__()
def __truediv__(self, *args, **kwargs): # real signature unknown
""" Return self/value. """
"""返回两个数相除的积"""
pass
实例如下:
>>> a = 5
>>> b = 3
>>> a.__truediv__(b)
1.6666666666666667
>>> a.__truediv__(2)
2.5
42.__trunc__(self,*args,**kwargs)
def __trunc__(self, *args, **kwargs): # real signature unknown
""" Truncating an Integral returns itself. """
"""截尾取整,主要用于浮点型数字"""
pass
实例如下:
>>> a = 3.9
>>> b = 2.0001
>>> a.__trunc__()
3
>>> b.__trunc__()
2
43.__xor__(self,*args,**kwargs)
def __xor__(self, *args, **kwargs): # real signature unknown
""" Return self^value. """
"""二进制下,同为假,异为真"""
pass
实例如下:
1 0 1 a = 5
1 1 1 b = 7
0 1 0 a.__xor__(b)(a^b)
上面运算的十进制下的2,用程序结果如下:
>>> a = 5
>>> b = 7
>>> a.__xor__(b)
2
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:2801 LOL-盖伦的蹲草计划
下一篇:CPP笔记_函数返回局部变量
- 关于各种不同开发语言之间数据加密方法(DES,RSA等)的互通的 2020-06-07
- C++ 类 2020-06-02
- 模板大全 2020-04-30
- 从Point类继承的Circle类 代码参考 2020-04-21
- G++编译链接的那些事!G++的特殊使用方法[常用] 2020-04-19
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash