1.2python基础_数字类型_数字(Number)类型,python的数字类型


一、整型(int型、整数)

整型 等价于C中的有符号长整型(long)

与系统的最大整型一致(如32位机器上的整型是32位,64位机器上的整型是64位),

可以表示的整数范围在[-sys.maxint-1, sys.maxint]之间。整型字面值的表示方法有3种:

十进制(常用)、八进制(以数字“0”开头)和十六进制(以“0x”或“0X”开头)。

整型的标准库操作有如下

 

1 class int(object): 2 """ 3 int([x]) -> integer 4 int(x, base=10) -> integer 5 6 Convert a number or string to an integer, or return 0 if no arguments 7 are given. If x is a number, return x.__int__(). For floating point 8 numbers, this truncates towards zero. 9 10 If x is not a number or if base is given, then x must be a string, 11 bytes, or bytearray instance representing an integer literal in the 12 given base. The literal can be preceded by '+' or '-' and be surrounded 13 by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. 14 Base 0 means to interpret the base from the string as an integer literal. 15 >>> int('0b100', base=0) 16 4 17 """ 18 def bit_length(self): # real signature unknown; restored from __doc__ 19 """ 20 Number of bits necessary to represent self in binary. 21 22 >>> bin(37) 23 '0b100101' 24 >>> (37).bit_length() 25 6 26 """ 27 pass 28 29 def conjugate(self, *args, **kwargs): # real signature unknown 30 """ Returns self, the complex conjugate of any int. """ 31 pass 32 33 @classmethod # known case 34 def from_bytes(cls, *args, **kwargs): # real signature unknown 35 """ 36 Return the integer represented by the given array of bytes. 37 38 bytes 39 Holds the array of bytes to convert. The argument must either 40 support the buffer protocol or be an iterable object producing bytes. 41 Bytes and bytearray are examples of built-in objects that support the 42 buffer protocol. 43 byteorder 44 The byte order used to represent the integer. If byteorder is 'big', 45 the most significant byte is at the beginning of the byte array. If 46 byteorder is 'little', the most significant byte is at the end of the 47 byte array. To request the native byte order of the host system, use 48 `sys.byteorder' as the byte order value. 49 signed 50 Indicates whether two's complement is used to represent the integer. 51 """ 52 pass 53 54 def to_bytes(self, *args, **kwargs): # real signature unknown 55 """ 56 Return an array of bytes representing an integer. 57 58 length 59 Length of bytes object to use. An OverflowError is raised if the 60 integer is not representable with the given number of bytes. 61 byteorder 62 The byte order used to represent the integer. If byteorder is 'big', 63 the most significant byte is at the beginning of the byte array. If 64 byteorder is 'little', the most significant byte is at the end of the 65 byte array. To request the native byte order of the host system, use 66 `sys.byteorder' as the byte order value. 67 signed 68 Determines whether two's complement is used to represent the integer. 69 If signed is False and a negative integer is given, an OverflowError 70 is raised. 71 """ 72 pass 73 74 def __abs__(self, *args, **kwargs): # real signature unknown 75 """ abs(self) """ 76 pass 77 78 def __add__(self, *args, **kwargs): # real signature unknown 79 """ Return self+value. """ 80 pass 81 82 def __and__(self, *args, **kwargs): # real signature unknown 83 """ Return self&value. """ 84 pass 85 86 def __bool__(self, *args, **kwargs): # real signature unknown 87 """ self != 0 """ 88 pass 89 90 def __ceil__(self, *args, **kwargs): # real signature unknown 91 """ Ceiling of an Integral returns itself. """ 92 pass 93 94 def __divmod__(self, *args, **kwargs): # real signature unknown 95 """ Return divmod(self, value). """ 96 pass 97 98 def __eq__(self, *args, **kwargs): # real signature unknown 99 """ Return self==value. """ 100 pass 101 102 def __float__(self, *args, **kwargs): # real signature unknown 103 """ float(self) """ 104 pass 105 106 def __floordiv__(self, *args, **kwargs): # real signature unknown 107 """ Return self//value. """ 108 pass 109 110 def __floor__(self, *args, **kwargs): # real signature unknown 111 """ Flooring an Integral returns itself. """ 112 pass 113 114 def __format__(self, *args, **kwargs): # real signature unknown 115 pass 116 117 def __getattribute__(self, *args, **kwargs): # real signature unknown 118 """ Return getattr(self, name). """ 119 pass 120 121 def __getnewargs__(self, *args, **kwargs): # real signature unknown 122 pass 123 124 def __ge__(self, *args, **kwargs): # real signature unknown 125 """ Return self>=value. """ 126 pass 127 128 def __gt__(self, *args, **kwargs): # real signature unknown 129 """ Return self>value. """ 130 pass 131 132 def __hash__(self, *args, **kwargs): # real signature unknown 133 """ Return hash(self). """ 134 pass 135 136 def __index__(self, *args, **kwargs): # real signature unknown 137 """ Return self converted to an integer, if self is suitable for use as an index into a list. """ 138 pass 139 140 def __init__(self, x, base=10): # known special case of int.__init__ 141 """ 142 int([x]) -> integer 143 int(x, base=10) -> integer 144 145 Convert a number or string to an integer, or return 0 if no arguments 146 are given. If x is a number, return x.__int__(). For floating point 147 numbers, this truncates towards zero. 148 149 If x is not a number or if base is given, then x must be a string, 150 bytes, or bytearray instance representing an integer literal in the 151 given base. The literal can be preceded by '+' or '-' and be surrounded 152 by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. 153 Base 0 means to interpret the base from the string as an integer literal. 154 >>> int('0b100', base=0) 155 4 156 # (copied from class doc) 157 """ 158 pass 159 160 def __int__(self, *args, **kwargs): # real signature unknown 161 """ int(self) """ 162 pass 163 164 def __invert__(self, *args, **kwargs): # real signature unknown 165 """ ~self """ 166 pass 167 168 def __le__(self, *args, **kwargs): # real signature unknown 169 """ Return self<=value. """ 170 pass 171 172 def __lshift__(self, *args, **kwargs): # real signature unknown 173 """ Return self<<value. """ 174 pass 175 176 def __lt__(self, *args, **kwargs): # real signature unknown 177 """ Return self<value. """ 178 pass 179 180 def __mod__(self, *args, **kwargs): # real signature unknown 181 """ Return self%value. """ 182 pass 183 184 def __mul__(self, *args, **kwargs): # real signature unknown 185 """ Return self*value. """ 186 pass 187 188 def __neg__(self, *args, **kwargs): # real signature unknown 189 """ -self """ 190 pass 191 192 @staticmethod # known case of __new__ 193 def __new__(*args, **kwargs): # real signature unknown 194 """ Create and return a new object. See help(type) for accurate signature. """ 195 pass 196 197 def __ne__(self, *args, **kwargs): # real signature unknown 198 """ Return self!=value. """ 199 pass 200 201 def __or__(self, *args, **kwargs): # real signature unknown 202 """ Return self|value. """ 203 pass 204 205 def __pos__(self, *args, **kwargs): # real signature unknown 206 """ +self """ 207 pass 208 209 def __pow__(self, *args, **kwargs): # real signature unknown 210 """ Return pow(self, value, mod). """ 211 pass 212 213 def __radd__(self, *args, **kwargs): # real signature unknown 214 """ Return value+self. """ 215 pass 216 217 def __rand__(self, *args, **kwargs): # real signature unknown 218 """ Return value&self. """ 219 pass 220 221 def __rdivmod__(self, *args, **kwargs): # real signature unknown 222 """ Return divmod(value, self). """ 223 pass 224 225 def __repr__(self, *args, **kwargs): # real signature unknown 226 """ Return repr(self). """ 227 pass 228 229 def __rfloordiv__(self, *args, **kwargs): # real signature unknown 230 """ Return value//self. """ 231 pass 232 233 def __rlshift__(self, *args, **kwargs): # real signature unknown 234 """ Return value<<self. """ 235 pass 236 237 def __rmod__(self, *args, **kwargs): # real signature unknown 238 """ Return value%self. """ 239 pass 240 241 def __rmul__(self, *args, **kwargs): # real signature unknown 242 """ Return value*self. """ 243 pass 244 245 def __ror__(self, *args, **kwargs): # real signature unknown 246 """ Return value|self. """ 247 pass 248 249 def __round__(self, *args, **kwargs): # real signature unknown 250 """ 251 Rounding an Integral returns itself. 252 Rounding with an ndigits argument also returns an integer. 253 """ 254 pass 255 256 def __rpow__(self, *args, **kwargs): # real signature unknown 257 """ Return pow(value, self, mod). """ 258 pass 259 260 def __rrshift__(self, *args, **kwargs): # real signature unknown 261 """ Return value>>self. """ 262 pass 263 264 def __rshift__(self, *args, **kwargs): # real signature unknown 265 """ Return self>>value. """ 266 pass 267 268 def __rsub__(self, *args, **kwargs): # real signature unknown 269 """ Return value-self. """ 270 pass 271 272 def __rtruediv__(self, *args, **kwargs): # real signature unknown 273 """ Return value/self. """ 274 pass 275 276 def __rxor__(self, *args, **kwargs): # real signature unknown 277 """ Return value^self. """ 278 pass 279 280 def __sizeof__(self, *args, **kwargs): # real signature unknown 281 """ Returns size in memory, in bytes. """ 282 pass 283 284 def __str__(self, *args, **kwargs): # real signature unknown 285 """ Return str(self). """ 286 pass 287 288 def __sub__(self, *args, **kwargs): # real signature unknown 289 """ Return self-value. """ 290 pass 291 292 def __truediv__(self, *args, **kwargs): # real signature unknown 293 """ Return self/value. """ 294 pass 295 296 def __trunc__(self, *args, **kwargs): # real signature unknown 297 """ Truncating an Integral returns itself. """ 298 pass 299 300 def __xor__(self, *args, **kwargs): # real signature unknown 301 """ Return self^value. """ 302 pass 303 304 denominator = property(lambda self: object(), lambda self, v: None, lambda self: None) # default 305 """the denominator of a rational number in lowest terms""" 306 307 imag = property(lambda self: object(), lambda self, v: None, lambda self: None) # default 308 """the imaginary part of a complex number""" 309 310 numerator = property(lambda self: object(), lambda self, v: None, lambda self: None) # default 311 """the numerator of a rational number in lowest terms""" 312 313 real = property(lambda self: object(), lambda self, v: None, lambda self: None) # default 314 """the real part of a complex number""" int

 

相关内容

    暂无相关文章

评论关闭