zoukankan      html  css  js  c++  java
  • python help(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.

    | 将一个数字或字符串转换成整数,没有参数的时候为默认值0。如果参数时数字,调用__init__(),参数为浮点数,会发生截取。

    |当x参数时不是数字时,或者有参数base,那么x参数一定是字面值是整数的字符串,字节流,或者是字节数组。这个字面值可以有正负号,前后可以有空格。

    |base参数默认是10,base允许是0,2到36。如果base是0的时候,会根据字符串的字面值判断base的值。

    1 a = int('100', 2)
    2 print(a)
    3 a = int('0b100', 0)
    4 print(a)
    1 4
    2 4

    | >>> int('0b100', base=0)
    | 4
    |
    | Methods defined here:
    |
    | __abs__(self, /)
    | abs(self)

    1 print(abs(-10))
    2 print(abs(10))
    1 10
    2 10

    |
    | __add__(self, value, /)
    | Return self+value.

    1 print(10 + 10 + 10)
    1 30

    |
    | __and__(self, value, /)
    | Return self&value.

    1 print(1 & 3)
    1 1

    |
    | __bool__(self, /)
    | self != 0

    1 if 1:
    2     print("True")
    3 if 0:
    4     pass
    5 else:
    6     print("False")
    1 True
    2 False

    |
    | __ceil__(...)
    | Ceiling of an Integral returns itself.

    返回一个大于或者等于x的最小整数。

    1 import math
    2 print(math.ceil(10))
    3 print(math.ceil(9.2))
    4 print(math.ceil(-8.2))
    1 10
    2 10
    3 -8

    |
    | __divmod__(self, value, /)
    | Return divmod(self, value).

    返回一个元组,一个值是x//y,第二个值是x%y。

    1 print(divmod(10, 3))
    1 (3, 1)

    |
    | __eq__(self, value, /)
    | Return self==value.

    1 print(5 == 5)
    1 True

    |
    | __float__(self, /)
    | float(self)

    1 print(float(5))
    1 5.0

    |
    | __floor__(...)
    | Flooring an Integral returns itself.

    返回数字的下舍整数。

    1 >>> import math
    2 >>> math.floor(5)
    3 5
    4 >>> math.floor(5.1)
    5 5
    6 >>> math.floor(-5.1)
    7 -6

    |
    | __floordiv__(self, value, /)
    | Return self//value.

    地板除。

    1 >>> 5//2
    2 2

    |
    | __format__(...)
    | default object formatter


    |
    | __ge__(self, value, /)
    | Return self>=value.

    1 >>> 10 >= 5
    2 True

    |
    | __getattribute__(self, name, /)
    | Return getattr(self, name).


    |
    | __getnewargs__(...)

    |
    | __gt__(self, value, /)
    | Return self>value.

    1 >>> 10 > 5
    2 True

    |
    | __hash__(self, /)
    | Return hash(self).

    获取一个对象(字符串或者数值等)的哈希值。

    1 >>> hash(15)
    2 15
    3 >>> hash(15.5)
    4 1152921504606846991
    5 >>> hash('wang')
    6 -1275867606344747311

    |
    | __index__(self, /)
    | Return self converted to an integer, if self is suitable for use as an index into a list.

    |
    | __int__(self, /)
    | int(self)

    1 >>> int(10)
    2 10
    3 >>> int(10.10)
    4 10

    |
    | __invert__(self, /)
    | ~self

    1 >>> ~0
    2 -1
    3 >>> ~1
    4 -2
    5 >>> ~-1
    6 0
    7 >>> ~-2
    8 1

    |
    | __le__(self, value, /)
    | Return self<=value.

    1 >>> 10 <= 5
    2 False

    |
    | __lshift__(self, value, /)
    | Return self<<value.

    1 >>> 1 << 1
    2 2

    |
    | __lt__(self, value, /)
    | Return self<value.

    1 >>> 1 < 1
    2 False

    |
    | __mod__(self, value, /)
    | Return self%value.

    1 >>> 5 % 2
    2 1

    |
    | __mul__(self, value, /)
    | Return self*value.

    1 >>> 5 * 2
    2 10

    |
    | __ne__(self, value, /)
    | Return self!=value.

    1 >>> 5 != 2
    2 True

    |
    | __neg__(self, /)
    | -self

    1 >>> -10
    2 -10
    3 >>> --10
    4 10

    |
    | __new__(*args, **kwargs) from builtins.type
    | Create and return a new object. See help(type) for accurate signature.


    |
    | __or__(self, value, /)
    | Return self|value.

    1 >>> 1 | 0
    2 1

    |
    | __pos__(self, /)
    | +self

    1 >>> +5
    2 5
    3 >>> +-5
    4 -5

    |
    | __pow__(self, value, mod=None, /)
    | Return pow(self, value, mod).

    1 >>> pow(2, 2)
    2 4
    3 >>> pow(3, 3)
    4 27

    |
    | __radd__(self, value, /)
    | Return value+self.

    |
    | __rand__(self, value, /)
    | Return value&self.
    |
    | __rdivmod__(self, value, /)
    | Return divmod(value, self).

    |
    | __repr__(self, /)
    | Return repr(self).

    1 >>> repr(10)
    2 '10'

    |
    | __rfloordiv__(self, value, /)
    | Return value//self.
    |
    | __rlshift__(self, value, /)
    | Return value<<self.
    |
    | __rmod__(self, value, /)
    | Return value%self.
    |
    | __rmul__(self, value, /)
    | Return value*self.
    |
    | __ror__(self, value, /)
    | Return value|self.
    |
    | __round__(...)
    | Rounding an Integral returns itself.
    | Rounding with an ndigits argument also returns an integer.

    |
    | __rpow__(self, value, mod=None, /)
    | Return pow(value, self, mod).
    |
    | __rrshift__(self, value, /)
    | Return value>>self.
    |
    | __rshift__(self, value, /)
    | Return self>>value.
    |
    | __rsub__(self, value, /)
    | Return value-self.
    |
    | __rtruediv__(self, value, /)
    | Return value/self.
    |
    | __rxor__(self, value, /)
    | Return value^self.
    |
    | __sizeof__(...)
    | Returns size in memory, in bytes

    |
    | __str__(self, /)
    | Return str(self).
    |
    | __sub__(self, value, /)
    | Return self-value.
    |
    | __truediv__(self, value, /)
    | Return self/value.
    |
    | __trunc__(...)
    | Truncating an Integral returns itself.
    |
    | __xor__(self, value, /)
    | Return self^value.
    |
    | bit_length(...)
    | int.bit_length() -> int
    |
    | Number of bits necessary to represent self in binary.
    | >>> bin(37)
    | '0b100101'
    | >>> (37).bit_length()
    | 6
    |
    | conjugate(...)
    | Returns self, the complex conjugate of any int.
    |
    | from_bytes(...) from builtins.type
    | 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.
    |
    | to_bytes(...)
    | 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.
    |
    | ----------------------------------------------------------------------
    | Data descriptors defined here:
    |
    | denominator
    | the denominator of a rational number in lowest terms
    |
    | imag
    | the imaginary part of a complex number
    |
    | numerator
    | the numerator of a rational number in lowest terms
    |
    | real
    | the real part of a complex number

  • 相关阅读:
    CSP_2019
    luogu_P1026 统计单词个数
    [SCOI2007]降雨量
    [HEOI2016/TJOI2016]排序
    LuoguP2698 【[USACO12MAR]花盆Flowerpot】
    LuoguP3069 【[USACO13JAN]牛的阵容Cow Lineup
    CF723D 【Lakes in Berland】
    CF799B T-shirt buying
    迪杰斯特拉算法(Dijkstra) (基础dij+堆优化) BY:优少
    Tarjan求有向图强连通分量 BY:优少
  • 原文地址:https://www.cnblogs.com/gundan/p/8137207.html
Copyright © 2011-2022 走看看