前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[转载] python学习笔记2--操作符,数据类型和内置功能

[转载] python学习笔记2--操作符,数据类型和内置功能

作者头像
用户7886150
修改2020-11-27 10:55:52
2390
修改2020-11-27 10:55:52
举报
文章被收录于专栏:bit哲学院

参考链接: Python中的Inplace运算符| 1(iadd(),isub(),iconcat()…)

参考链接: Python中的Inplace运算符| 1(iadd(),isub(),iconcat()…) 

什么是操作符?  

 简单的回答可以使用表达式4 + 5等于9,在这里4和5被称为操作数,+被称为操符。 Python语言支持操作者有以下几种类型。  

  算术运算符  比较(即关系)运算符  赋值运算符  逻辑运算符  位运算符  会员操作符  标识操作符  

 让我们逐一看看所有的运算符。  

 Python算术运算符:  

 操作符描述符例子+加法 - 对操作符的两侧增加值a + b = 30-减法 - 减去从左侧操作数右侧操作数a - b = -10*乘法 - 相乘的运算符两侧的值a * b = 200/除 - 由右侧操作数除以左侧操作数b / a = 2%模 - 由右侧操作数和余返回除以左侧操作数b % a = 0**指数- 执行对操作指数(幂)的计算a**b = 10 的幂 20//地板除 - 操作数的除法,其中结果是将小数点后的位数被除去的商。9//2 =  4 而 9.0//2.0 = 4.0 

   #!/usr/bin/python 

a = 21 

b = 10 

c = 0 

c = a + b 

print "Line 1 - Value of c is ", c 

c = a - b 

print "Line 2 - Value of c is ", c  

c = a * b 

print "Line 3 - Value of c is ", c  

c = a / b 

print "Line 4 - Value of c is ", c  

c = a % b 

print "Line 5 - Value of c is ", c 

a = 2 

b = 3 

c = a**b  

print "Line 6 - Value of c is ", c 

a = 10 

b = 5 

c = a//b  

print "Line 7 - Value of c is ", c  

  算术运算符示例 

   Line 1 - Value of c is 31 

Line 2 - Value of c is 11 

Line 3 - Value of c is 210 

Line 4 - Value of c is 2 

Line 5 - Value of c is 1 

Line 6 - Value of c is 8 

Line 7 - Value of c is 2  

  算术运算结果 

  Python的比较操作符:  

 运算符描述示例==检查,两个操作数的值是否相等,如果是则条件变为真。(a == b) 不为 true.!=检查两个操作数的值是否相等,如果值不相等,则条件变为真。(a != b) 为 true.<>检查两个操作数的值是否相等,如果值不相等,则条件变为真。(a <> b) 为 true。这个类似于 != 运算符>检查左操作数的值是否大于右操作数的值,如果是,则条件成立。(a > b) 不为 true.<检查左操作数的值是否小于右操作数的值,如果是,则条件成立。(a < b) 为 true.>=检查左操作数的值是否大于或等于右操作数的值,如果是,则条件成立。(a >= b) 不为 true.<=检查左操作数的值是否小于或等于右操作数的值,如果是,则条件成立。(a <= b) 为 true. 

   #!/usr/bin/python 

a = 21 

b = 10 

c = 0 

if ( a == b ): 

   print "Line 1 - a is equal to b" 

else: 

   print "Line 1 - a is not equal to b" 

if ( a != b ): 

   print "Line 2 - a is not equal to b" 

else: 

   print "Line 2 - a is equal to b" 

if ( a <> b ): 

   print "Line 3 - a is not equal to b" 

else: 

   print "Line 3 - a is equal to b" 

if ( a < b ): 

   print "Line 4 - a is less than b"  

else: 

   print "Line 4 - a is not less than b" 

if ( a > b ): 

   print "Line 5 - a is greater than b" 

else: 

   print "Line 5 - a is not greater than b" 

a = 5; 

b = 20; 

if ( a <= b ): 

   print "Line 6 - a is either less than or equal to  b" 

else: 

   print "Line 6 - a is neither less than nor equal to  b" 

if ( b >= a ): 

   print "Line 7 - b is either greater than  or equal to b" 

else: 

   print "Line 7 - b is neither greater than  nor equal to b"  

  比较操作符运算示例 

   Line 1 - a is not equal to b 

Line 2 - a is not equal to b 

Line 3 - a is not equal to b 

Line 4 - a is not less than b 

Line 5 - a is greater than b 

Line 6 - a is either less than or equal to b 

Line 7 - b is either greater than or equal to b  

  比较操作符结果 

 Python赋值运算符:  

 运算符描述示例=简单的赋值运算符,赋值从右侧操作数左侧操作数c = a + b将指定的值 a + b 到  c+=加法AND赋值操作符,它增加了右操作数左操作数和结果赋给左操作数c += a 相当于 c = c + a-=减AND赋值操作符,它减去右边的操作数从左边操作数,并将结果赋给左操作数c -= a 相当于 c = c - a*=乘法AND赋值操作符,它乘以右边的操作数与左操作数,并将结果赋给左操作数c *= a 相当于 c = c * a/=除法AND赋值操作符,它把左操作数与正确的操作数,并将结果赋给左操作数c /= a 相当于= c / a%=模量AND赋值操作符,它需要使用两个操作数的模量和分配结果左操作数c %= a is equivalent to c = c % a**=指数AND赋值运算符,执行指数(功率)计算操作符和赋值给左操作数c **= a 相当于 c = c ** a//=地板除,并分配一个值,执行地板除对操作和赋值给左操作数c //= a 相当于 c = c // a 

   #!/usr/bin/python 

a = 21 

b = 10 

c = 0 

c = a + b 

print "Line 1 - Value of c is ", c 

c += a 

print "Line 2 - Value of c is ", c  

c *= a 

print "Line 3 - Value of c is ", c  

c /= a  

print "Line 4 - Value of c is ", c  

c  = 2 

c %= a 

print "Line 5 - Value of c is ", c 

c **= a 

print "Line 6 - Value of c is ", c 

c //= a 

print "Line 7 - Value of c is ", c 

#----------------------结果----------------------- 

Line 1 - Value of c is 31 

Line 2 - Value of c is 52 

Line 3 - Value of c is 1092 

Line 4 - Value of c is 52 

Line 5 - Value of c is 2 

Line 6 - Value of c is 2097152 

Line 7 - Value of c is 99864  

  赋值运算示例 

 Python位运算符:  

  位运算符作用于位和位操作执行位。假设,如果a =60;且b =13;现在以二进制格式它们将如下:  

 a = 0011 1100  

 b = 0000 1101  

 -----------------  

 a&b = 0000 1100  

 a|b = 0011 1101  

 a^b = 0011 0001  

 ~a  = 1100 0011  

 Python语言支持下位运算符  

 操作符描述示例&二进制和复制操作了一下,结果,如果它存在于两个操作数。(a & b) = 12 即 0000 1100|二进制或复制操作了一个比特,如果它存在一个操作数中。(a | b) = 61 即 0011 1101^二进制异或运算符的副本,如果它被设置在一个操作数而不是两个比特。(a ^ b) =  49 即  0011 0001~二进制的补运算符是一元的,并有“翻转”位的效果。(~a ) =  -61 即 1100 0011以2的补码形式由于带符号二进制数。<<二进位向左移位运算符。左操作数的值左移由右操作数指定的位数。a << 2 = 240 即 1111 0000>>二进位向右移位运算符。左操作数的值是由右操作数指定的位数向右移动。a >> 2 = 15 即 0000 1111 

   #!/usr/bin/python 

a = 60            # 60 = 0011 1100  

b = 13            # 13 = 0000 1101  

c = 0 

c = a & b;        # 12 = 0000 1100 

print "Line 1 - Value of c is ", c 

c = a | b;        # 61 = 0011 1101  

print "Line 2 - Value of c is ", c 

c = a ^ b;        # 49 = 0011 0001 

print "Line 3 - Value of c is ", c 

c = ~a;           # -61 = 1100 0011 

print "Line 4 - Value of c is ", c 

c = a << 2;       # 240 = 1111 0000 

print "Line 5 - Value of c is ", c 

c = a >> 2;       # 15 = 0000 1111 

print "Line 6 - Value of c is ", c 

#--------------------------------结果------------------------- 

Line 1 - Value of c is 12 

Line 2 - Value of c is 61 

Line 3 - Value of c is 49 

Line 4 - Value of c is -61 

Line 5 - Value of c is 240 

Line 6 - Value of c is 15  

  位运算符 

 Python逻辑运算符:  

  Python语言支持以下逻辑运算符。  

 运算符描述示例and所谓逻辑与运算符。如果两个操作数都是真的,那么则条件成立。(a and b) 为 true.or所谓逻辑OR运算符。如果有两个操作数都是非零然后再条件变为真。(a or b) 为 true.not所谓逻辑非运算符。用于反转操作数的逻辑状态。如果一个条件为真,则逻辑非运算符将返回false。not(a and b) 为 false. 

   #!/usr/bin/python 

a = 10 

b = 20 

c = 0 

if ( a and b ): 

   print "Line 1 - a and b are true" 

else: 

   print "Line 1 - Either a is not true or b is not true" 

if ( a or b ): 

   print "Line 2 - Either a is true or b is true or both are true" 

else: 

   print "Line 2 - Neither a is true nor b is true" 

a = 0 

if ( a and b ): 

   print "Line 3 - a and b are true" 

else: 

   print "Line 3 - Either a is not true or b is not true" 

if ( a or b ): 

   print "Line 4 - Either a is true or b is true or both are true" 

else: 

   print "Line 4 - Neither a is true nor b is true" 

if not( a and b ): 

   print "Line 5 - Either a is not true or b is not true" 

else: 

   print "Line 5 - a and b are true" 

#---------------------------结果-------------------------------------- 

Line 1 - a and b are true 

Line 2 - Either a is true or b is true or both are true 

Line 3 - Either a is not true or b is not true 

Line 4 - Either a is true or b is true or both are true 

Line 5 - Either a is not true or b is not true  

  逻辑运算示例 

 Python成员运算符:  

 Python成员运算符,在一个序列中成员资格的测试,如字符串,列表或元组。有两个成员运算符解释如下:  

 操作符描述示例in计算结果为true,如果它在指定找到变量的顺序,否则false。x在y中,在这里产生一个1,如果x是序列y的成员。not in计算结果为true,如果它不找到在指定的变量顺序,否则为false。x不在y中,这里产生结果不为1,如果x不是序列y的成员。 

   #!/usr/bin/python 

a = 10 

b = 20 

list = [1, 2, 3, 4, 5 ]; 

if ( a in list ): 

   print "Line 1 - a is available in the given list" 

else: 

   print "Line 1 - a is not available in the given list" 

if ( b not in list ): 

   print "Line 2 - b is not available in the given list" 

else: 

   print "Line 2 - b is available in the given list" 

a = 2 

if ( a in list ): 

   print "Line 3 - a is available in the given list" 

else: 

   print "Line 3 - a is not available in the given list" 

#------------结果-------------------------------------- 

Line 1 - a is not available in the given list 

Line 2 - b is not available in the given list 

Line 3 - a is available in the given list  

  成员运算示例 

 Python标识运算符:  

 运算符描述例子is计算结果为true,如果操作符两侧的变量指向相同的对象,否则为false。x是y,这里结果是1,如果id(x)的值为id(y)。is not计算结果为false,如果两侧的变量操作符指向相同的对象,否则为true。x不为y,这里结果不是1,当id(x)不等于id(y)。 

   #!/usr/bin/python 

a = 20 

b = 20 

if ( a is b ): 

   print "Line 1 - a and b have same identity" 

else: 

   print "Line 1 - a and b do not have same identity" 

if ( id(a) == id(b) ): 

   print "Line 2 - a and b have same identity" 

else: 

   print "Line 2 - a and b do not have same identity" 

b = 30 

if ( a is b ): 

   print "Line 3 - a and b have same identity" 

else: 

   print "Line 3 - a and b do not have same identity" 

if ( a is not b ): 

   print "Line 4 - a and b do not have same identity" 

else: 

   print "Line 4 - a and b have same identity" 

#--------------------结果------------------------------------------- 

Line 1 - a and b have same identity 

Line 2 - a and b have same identity 

Line 3 - a and b do not have same identity 

Line 4 - a and b do not have same identity  

  标识运算符示例 

 Python运算符优先级  

 下表列出了所有运算符从最高优先级到最低。  

 运算符描述**幂(提高到指数)~ + -补码,一元加号和减号(方法名的最后两个+@和 - @)* / % //乘,除,取模和地板除+ -加法和减法>> <<左,右按位转移&位'AND'^ |按位异'或`'和定期`或'<= < > >=比较运算符<> == !=等式运算符= %= /= //= -= += *= **=赋值运算符is is not标识运算符in not in成员运算符not or and逻辑运算符 

 优先级  

   #!/usr/bin/python 

a = 20 

b = 10 

c = 15 

d = 5 

e = 0 

e = (a + b) * c / d       #( 30 * 15 ) / 5 

print "Value of (a + b) * c / d is ",  e 

e = ((a + b) * c) / d     # (30 * 15 ) / 5 

print "Value of ((a + b) * c) / d is ",  e 

e = (a + b) * (c / d);    # (30) * (15/5) 

print "Value of (a + b) * (c / d) is ",  e 

e = a + (b * c) / d;      #  20 + (150/5) 

print "Value of a + (b * c) / d is ",  e 

#-------------结果------------------------ 

Value of (a + b) * c / d is 90 

Value of ((a + b) * c) / d is 90 

Value of (a + b) * (c / d) is 90 

Value of a + (b * c) / d is 50  

  运算符优先级示例 

 数据类型和内置的功能  

 常用类功能查看方法  

 在pycharm里面 输入class的名称,  

 按住ctrl 单击会自己跳转到对应的class源码里面。  

  一、整数int的命令汇总  

    '''''' 

class int(object): 

    """ 

    int(x=0) -> integer 

    int(x, base=10) -> integer 

    Convert a number or string to an integer, or return 0 if no arguments 

    are given.  If x is a number, return x.__int__().  For floating point 

    numbers, this truncates towards zero. 

    If x is not a number or if base is given, then x must be a string, 

    bytes, or bytearray instance representing an integer literal in the 

    given base.  The literal can be preceded by '+' or '-' and be surrounded 

    by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36. 

    Base 0 means to interpret the base from the string as an integer literal. 

    >>> int('0b100', base=0) 

    """ 

    def bit_length(self):  # real signature unknown; restored from __doc__ 

        """ 

        int.bit_length() -> int 

        Number of bits necessary to represent self in binary. 

        案例: 

        >>> bin(37) 

        '0b100101' 

        >>> (37).bit_length() 

        """ 

        return 0 

    def conjugate(self, *args, **kwargs):  # real signature unknown 

        """ Returns self, the complex conjugate of any int.  

        返回共轭复数 

        >>> a=37 

        >>> result=a.conjugate() 

        >>> print (result) 

        >>> a=-37 

        >>> print(a.conjugate()) 

        -37         

        """ 

        pass 

    @classmethod  # known case 

    def from_bytes(cls, bytes, byteorder, *args, 

                   **kwargs):  # real signature unknown; NOTE: unreliably restored from __doc__ 

        """ 

        不知道什么作用 

        >>> a.from_bytes 

        <built-in method from_bytes of type object at 0x000000001E283A30> 

        >>> b=a.from_bytes 

        >>> print(b) 

        <built-in method from_bytes of type object at 0x000000001E283A30> 

        >>> a=37 

        >>> b=a.from_bytes() 

        Traceback (most recent call last): 

          File "<pyshell#18>", line 1, in <module> 

            b=a.from_bytes() 

        TypeError: Required argument 'bytes' (pos 1) not found 

        加()后会报错。 

        int.from_bytes(bytes, byteorder, *, signed=False) -> int 

        Return the integer represented by the given array of bytes. 

        The bytes argument must be a bytes-like object (e.g. bytes or bytearray). 

        The byteorder argument determines the byte order used to represent the 

        integer.  If byteorder is 'big', the most significant byte is at the 

        beginning of the byte array.  If byteorder is 'little', the most 

        significant byte is at the end of the byte array.  To request the native 

        byte order of the host system, use `sys.byteorder' as the byte order value. 

        The signed keyword-only argument indicates whether two's complement is 

        used to represent the integer. 

        """ 

        pass 

    def to_bytes(self, length, byteorder, *args, 

                 **kwargs):  # real signature unknown; NOTE: unreliably restored from __doc__ 

        """ 

        int.to_bytes(length, byteorder, *, signed=False) -> bytes 

        Return an array of bytes representing an integer. 

        The integer is represented using length bytes.  An OverflowError is 

        raised if the integer is not representable with the given number of 

        bytes. 

        The byteorder argument determines the byte order used to represent the 

        integer.  If byteorder is 'big', the most significant byte is at the 

        beginning of the byte array.  If byteorder is 'little', the most 

        significant byte is at the end of the byte array.  To request the native 

        byte order of the host system, use `sys.byteorder' as the byte order value. 

        The signed keyword-only argument determines whether two's complement is 

        used to represent the integer.  If signed is False and a negative integer 

        is given, an OverflowError is raised. 

        """ 

        pass 

    def __abs__(self, *args, **kwargs):  # real signature unknown 

        """ abs(self)  

        取绝对值 

        >>> a=-50 

        >>> print(a.__abs__()) 

        """ 

        pass 

    def __add__(self, *args, **kwargs):  # real signature unknown 

        """ Return self+value.  

        相加 

        >>> a=-50 

        >>> print(a.__add__(100)) 

        >>>  

        """ 

        pass 

    def __and__(self, *args, **kwargs):  # real signature unknown 

        """ Return self&value. 

         >>> a=255 

        >>> print(bin(a)) 

        0b11111111 

        >>> b=128 

        >>> print(bin(b)) 

        0b10000000 

        >>> print(a.__and__(b)) 

        进行二进制的与运算 

        """ 

        pass 

    def __bool__(self, *args, **kwargs):  # real signature unknown 

        """ self != 0 

        计算布尔值,只要不为0,结果就是True 

        >>> a=35 

        >>> print(a.__bool__()) 

        True 

        >>> a=0 

        >>> print(a.__bool__()) 

        False 

        >>> a=-100 

        >>> print(a.__bool__()) 

        True 

         """ 

        pass 

    def __ceil__(self, *args, **kwargs):  # real signature unknown 

        """ Ceiling of an Integral returns itself. 

         """ 

        pass 

    def __divmod__(self, *args, **kwargs):  # real signature unknown 

        """ Return divmod(self, value).  

        >>> a=91 

        >>> print(a.__divmod__(9)) 

        (10, 1) 

        """ 

        pass 

    def __eq__(self, *args, **kwargs):  # real signature unknown 

        """ Return self==value.  

        >>> a=91 

        >>> print(a.__eq__(90)) 

        False 

        判断是否相等,返回bool值 

        """ 

        pass 

    def __float__(self, *args, **kwargs):  # real signature unknown 

        """ float(self)  

        转换为浮点数 

        """ 

        pass 

    def __floordiv__(self, *args, **kwargs):  # real signature unknown 

        """ Return self//value. 

        返回等于或小于代数商的最大整数值 

        >>> a=91 

        >>> print(a.__floordiv__(9)) 

        """ 

        pass 

    def __floor__(self, *args, **kwargs):  # real signature unknown 

        """ Flooring an Integral returns itself. """ 

        pass 

    def __format__(self, *args, **kwargs):  # real signature unknown 

        pass 

    def __getattribute__(self, *args, **kwargs):  # real signature unknown 

        """ Return getattr(self, name). """ 

        pass 

    def __getnewargs__(self, *args, **kwargs):  # real signature unknown 

        pass 

    def __ge__(self, *args, **kwargs):  # real signature unknown 

        """ Return self>=value.  

        判断大于等于某值的真假 

        """ 

        pass 

    def __gt__(self, *args, **kwargs):  # real signature unknown 

        """ Return self>value. 

        判断大于某值的真假 

        """ 

        pass 

    def __hash__(self, *args, **kwargs):  # real signature unknown 

        """ Return hash(self).  

        >>> a=91029393 

        >>> print(a.__hash__()) 

        >>>  

        不知道什么原因输入的结果均为自己 

        """ 

        pass 

    def __index__(self, *args, **kwargs):  # real signature unknown 

        """ Return self converted to an integer, if self is suitable for use as an index into a list. 

        """ 

        pass 

    def __init__(self, x, base=10):  # known special case of int.__init__ 

        """ 

        int(x=0) -> integer 

        int(x, base=10) -> integer 

        Convert a number or string to an integer, or return 0 if no arguments 

        are given.  If x is a number, return x.__int__().  For floating point 

        numbers, this truncates towards zero. 

        If x is not a number or if base is given, then x must be a string, 

        bytes, or bytearray instance representing an integer literal in the 

        given base.  The literal can be preceded by '+' or '-' and be surrounded 

        by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36. 

        Base 0 means to interpret the base from the string as an integer literal. 

        >>> int('0b100', base=0) 

        # (copied from class doc) 

        """ 

        pass 

    def __int__(self, *args, **kwargs):  # real signature unknown 

        """ int(self) """ 

        pass 

    def __invert__(self, *args, **kwargs):  # real signature unknown 

        """ ~self 

        >>> a=91 

        >>> print(a.__invert__()) 

        -92 

        >>> a=-90 

        >>> print(a.__invert__()) 

        >>> a=90 

        >>> print(a.__neg__()) 

        -90 

        >>> a=-90 

        >>> print(a.__neg__()) 

        """ 

        pass 

    def __le__(self, *args, **kwargs):  # real signature unknown 

        """ Return self<=value. """ 

        pass 

    def __lshift__(self, *args, **kwargs):  # real signature unknown 

        """ Return self<<value.  

        对二进制数值进行位移 

        >>> a=2 

        >>> print(bin(a)) 

        0b10 

        >>> b=a.__lshift__(2) 

        >>> print(b) 

        >>> print(bin(b)) 

        0b1000 

        >>> c=a.__rshift__(1) 

        >>> print(bin(c)) 

        0b1 

        >>> b 

        >>> c 

        """ 

        pass 

    def __lt__(self, *args, **kwargs):  # real signature unknown 

        """ Return self<value. """ 

        pass 

    def __mod__(self, *args, **kwargs):  # real signature unknown 

        """ Return self%value.  

        >>> a=91 

        >>> print(a.__mod__(9)) 

        """ 

        pass 

    def __mul__(self, *args, **kwargs):  # real signature unknown 

        """ Return self*value.  

        乘法的意思 

        >>> a=91 

        >>> print(a.__mul__(9)) 

        >>> print(a.__mul__(2)) 

        """ 

        pass 

    def __neg__(self, *args, **kwargs):  # real signature unknown 

        """ -self  

        负数 

        >>> a=91 

        >>> print(a.__invert__()) 

        -92 

        >>> a=-90 

        >>> print(a.__invert__()) 

        >>> a=90 

        >>> print(a.__neg__()) 

        -90 

        >>> a=-90 

        >>> print(a.__neg__()) 

        """ 

        pass 

    @staticmethod  # known case of __new__ 

    def __new__(*args, **kwargs):  # real signature unknown 

        """ Create and return a new object.  See help(type) for accurate signature. """ 

        pass 

    def __ne__(self, *args, **kwargs):  # real signature unknown 

        """ Return self!=value. 

        判断不等于  

        """ 

        pass 

    def __or__(self, *args, **kwargs):  # real signature unknown 

        """ Return self|value.  

        >>> a=255 

        >>> bin(a) 

        '0b11111111' 

        >>> b=128 

        >>> bin(b) 

        '0b10000000' 

        >>> c=a.__or__(b) 

        >>> print(c) 

        >>> bin(c) 

        '0b11111111' 

        >>>  

        """ 

        pass 

    def __pos__(self, *args, **kwargs):  # real signature unknown 

        """ +self """ 

        pass 

    def __pow__(self, *args, **kwargs):  # real signature unknown 

        """ Return pow(self, value, mod). """ 

        pass 

    def __radd__(self, *args, **kwargs):  # real signature unknown 

        """ Return value+self. """ 

        pass 

    def __rand__(self, *args, **kwargs):  # real signature unknown 

        """ Return value&self. """ 

        pass 

    def __rdivmod__(self, *args, **kwargs):  # real signature unknown 

        """ Return divmod(value, self). """ 

        pass 

    def __repr__(self, *args, **kwargs):  # real signature unknown 

        """ Return repr(self). """ 

        pass 

    def __rfloordiv__(self, *args, **kwargs):  # real signature unknown 

        """ Return value//self. """ 

        pass 

    def __rlshift__(self, *args, **kwargs):  # real signature unknown 

        """ Return value<<self. """ 

        pass 

    def __rmod__(self, *args, **kwargs):  # real signature unknown 

        """ Return value%self. """ 

        pass 

    def __rmul__(self, *args, **kwargs):  # real signature unknown 

        """ Return value*self. """ 

        pass 

    def __ror__(self, *args, **kwargs):  # real signature unknown 

        """ Return value|self. """ 

        pass 

    def __round__(self, *args, **kwargs):  # real signature unknown 

        """ 

        Rounding an Integral returns itself. 

        Rounding with an ndigits argument also returns an integer. 

        """ 

        pass 

    def __rpow__(self, *args, **kwargs):  # real signature unknown 

        """ Return pow(value, self, mod). """ 

        pass 

    def __rrshift__(self, *args, **kwargs):  # real signature unknown 

        """ Return value>>self. """ 

        pass 

    def __rshift__(self, *args, **kwargs):  # real signature unknown 

        """ Return self>>value. """ 

        pass 

    def __rsub__(self, *args, **kwargs):  # real signature unknown 

        """ Return value-self. """ 

        pass 

    def __rtruediv__(self, *args, **kwargs):  # real signature unknown 

        """ Return value/self.  

        >>> a=90 

        >>> print(a.__truediv__(8)) 

        11.25 

        >>> print(a.__div__(8))       

        """ 

        pass 

    def __rxor__(self, *args, **kwargs):  # real signature unknown 

        """ Return value^self. """ 

        pass 

    def __sizeof__(self, *args, **kwargs):  # real signature unknown 

        """ Returns size in memory, in bytes """ 

        pass 

    def __str__(self, *args, **kwargs):  # real signature unknown 

        """ Return str(self). """ 

        pass 

    def __sub__(self, *args, **kwargs):  # real signature unknown 

        """ Return self-value. """ 

        pass 

    def __truediv__(self, *args, **kwargs):  # real signature unknown 

        """ Return self/value. """ 

        pass 

    def __trunc__(self, *args, **kwargs):  # real signature unknown 

        """ Truncating an Integral returns itself. """ 

        pass 

    def __xor__(self, *args, **kwargs):  # real signature unknown 

        """ Return self^value.  

        二进制异或 

        """ 

        pass 

    denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default 

    """the denominator of a rational number in lowest terms""" 

    imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default 

    """the imaginary part of a complex number""" 

    numerator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default 

    """the numerator of a rational number in lowest terms""" 

    real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default 

    """the real part of a complex number""" 

''''''  

   class int 

  二、浮点型float的命令汇总  

    class float(object): 

    """ 

    float(x) -> floating point number 

    Convert a string or number to a floating point number, if possible. 

    """ 

    def as_integer_ratio(self):  # real signature unknown; restored from __doc__ 

        """ 

        float.as_integer_ratio() -> (int, int) 

        输出一对,除于等于浮点数的整数 

        Return a pair of integers, whose ratio is exactly equal to the original 

        float and with a positive denominator. 

        Raise OverflowError on infinities and a ValueError on NaNs. 

        >>> (10.0).as_integer_ratio() 

        (10, 1) 

        >>> (0.0).as_integer_ratio() 

        (0, 1) 

        >>> (-.25).as_integer_ratio() 

        (-1, 4) 

        """ 

        pass 

    def conjugate(self, *args, **kwargs):  # real signature unknown 

        """ Return self, the complex conjugate of any float. 

         >>> a=0.000000001 

        >>> a.conjugate() 

        1e-09 

         """ 

        pass 

    @staticmethod  # known case 

    def fromhex(string):  # real signature unknown; restored from __doc__ 

        """ 

        float.fromhex(string) -> float 

        十六进制文档转为10十进制浮点数 

        Create a floating-point number from a hexadecimal string. 

        >>> float.fromhex('0x1.ffffp10') 

        2047.984375 

        >>> float.fromhex('-0x1p-1074') 

        -5e-324 

        """ 

        return 0.0 

    def hex(self):  # real signature unknown; restored from __doc__ 

        """ 

        float.hex() -> string 

        转为十六进制 

        Return a hexadecimal representation of a floating-point number. 

        >>> (-0.1).hex() 

        '-0x1.999999999999ap-4' 

        >>> 3.14159.hex() 

        '0x1.921f9f01b866ep+1' 

        """ 

        return "" 

    def is_integer(self, *args, **kwargs):  # real signature unknown 

        """ Return True if the float is an integer.  

        判断是否整数 

        >>> a=10.0000 

        >>> a.is_integer() 

        True 

        >>> a=10.0001 

        >>> a.is_integer() 

        False 

        """

转载于:https://www.cnblogs.com/wintershen/p/6755976.html

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档