python基本数据类型之int

 

 


数字:int

    在32位机器上,整数的位数为32位,取值范围为-2**31~2**31-1,即-2147483648~2147483647
    在64位系统上,整数的位数为64位,取值范围为-2**63~2**63-1,即-9223372036854775808~9223372036854775807

  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 
  4 """ 基本数据类型之int """
  5 
  6 
  7 class int(object):
  8     """
  9     int(x=0) -> integer
 10     int(x, base=10) -> integer
 11 
 12     Convert a number or string to an integer, or return 0 if no arguments
 13     are given.  If x is a number, return x.__int__().  For floating point
 14     numbers, this truncates towards zero.
 15 
 16     If x is not a number or if base is given, then x must be a string,
 17     bytes, or bytearray instance representing an integer literal in the
 18     given base.  The literal can be preceded by '+' or '-' and be surrounded
 19     by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
 20     Base 0 means to interpret the base from the string as an integer literal.
 21     >>> int('0b100', base=0)
 22     4
 23     """
 24 
 25     def bit_length(self):  # real signature unknown; restored from __doc__
 26         """ 返回用二进制表示该数字的最少位数 """
 27         """
 28         int.bit_length() -> int
 29 
 30         Number of bits necessary to represent self in binary.
 31         >>> bin(37)
 32         '0b100101'
 33         >>> (37).bit_length()
 34         6
 35         """
 36         return 0
 37 
 38     def conjugate(self, *args, **kwargs):  # real signature unknown
 39         """ 返回该数字的共轭复数 """
 40         """ Returns self, the complex conjugate of any int. """
 41         pass
 42 
 43     @classmethod  # known case
 44     def from_bytes(cls, bytes, byteorder, *args,**kwargs):  # real signature unknown; NOTE: unreliably restored from __doc__
 45         """ 将字节转换成相应的数字,其中byte是字节;byteorder是字节顺序,big是高字节在后低字节在前
 46             little是低字节在后,高字节在前;signed表示的是有符号和无符号
 47         """
 48         """
 49         int.from_bytes(bytes, byteorder, *, signed=False) -> int
 50 
 51         Return the integer represented by the given array of bytes.
 52 
 53         The bytes argument must be a bytes-like object (e.g. bytes or bytearray).
 54 
 55         The byteorder argument determines the byte order used to represent the
 56         integer.  If byteorder is 'big', the most significant byte is at the
 57         beginning of the byte array.  If byteorder is 'little', the most
 58         significant byte is at the end of the byte array.  To request the native
 59         byte order of the host system, use `sys.byteorder' as the byte order value.
 60 
 61         The signed keyword-only argument indicates whether two's complement is
 62         used to represent the integer.
 63         """
 64         pass
 65 
 66     def to_bytes(self, length, byteorder, *args,**kwargs):  # real signature unknown; NOTE: unreliably restored from __doc__
 67         """ 把数字转换成字节类型的格式,from_bytes的过程 """
 68         """
 69         int.to_bytes(length, byteorder, *, signed=False) -> bytes
 70 
 71         Return an array of bytes representing an integer.
 72 
 73         The integer is represented using length bytes.  An OverflowError is
 74         raised if the integer is not representable with the given number of
 75         bytes.
 76 
 77         The byteorder argument determines the byte order used to represent the
 78         integer.  If byteorder is 'big', the most significant byte is at the
 79         beginning of the byte array.  If byteorder is 'little', the most
 80         significant byte is at the end of the byte array.  To request the native
 81         byte order of the host system, use `sys.byteorder' as the byte order value.
 82 
 83         The signed keyword-only argument determines whether two's complement is
 84         used to represent the integer.  If signed is False and a negative integer
 85         is given, an OverflowError is raised.
 86         """
 87         pass
 88 
 89     def __abs__(self, *args, **kwargs):  # real signature unknown
 90         """ 取绝对值 """
 91         """ abs(self) """
 92         pass
 93 
 94     def __add__(self, *args, **kwargs):  # real signature unknown
 95         """ 求和运算 """
 96         """ Return self+value. """
 97         pass
 98 
 99     def __and__(self, *args, **kwargs):  # real signature unknown
100         """ 按位与运算 """
101         """ Return self&value. """
102         pass
103 
104     def __bool__(self, *args, **kwargs):  # real signature unknown
105         """ 返回布尔值,非0数的布尔值是True,0的布尔值是False """
106         """  """
107         """ self != 0 """
108         pass
109 
110     def __ceil__(self, *args, **kwargs):  # real signature unknown
111         """ 返回这个整数本身 """
112         """ Ceiling of an Integral returns itself. """
113         pass
114 
115     def __divmod__(self, *args, **kwargs):  # real signature unknown
116         """ (num1).__divmod__(num2) 将num1除以num2,返回的是一个格式为(商,余数)的元组 """
117         """ Return divmod(self, value). """
118         pass
119 
120     def __eq__(self, *args, **kwargs):  # real signature unknown
121         """ (num1).__eq__(num2)  比较num1和num2的值,相等返回True,不等返回False """
122         """ Return self==value. """
123         pass
124 
125     def __float__(self, *args, **kwargs):  # real signature unknown
126         """ 将数字从整数类型转换成浮点类型 """
127         """ float(self) """
128         pass
129 
130     def __floordiv__(self, *args, **kwargs):  # real signature unknown
131         """ 地板除,相当于 // 运算 """
132         """ Return self//value. """
133         pass
134 
135     def __floor__(self, *args, **kwargs):  # real signature unknown
136         """ 返回这个数本身 """
137         """ Flooring an Integral returns itself. """
138         pass
139 
140     def __format__(self, *args, **kwargs):  # real signature unknown
141         pass
142 
143     def __getattribute__(self, *args, **kwargs):  # real signature unknown
144         """ x.__getattribute__('name') == x.name """
145         """ Return getattr(self, name). """
146         pass
147 
148     def __getnewargs__(self, *args, **kwargs):  # real signature unknown
149         """ 内部调用 __new__方法或创建对象时传入参数使用 """
150         pass
151 
152     def __ge__(self, *args, **kwargs):  # real signature unknown
153         """ (num1).__ge__(num2) 如果num1大于或等于num2,则返回True,否则返回False """
154         """ Return self>=value. """
155         pass
156 
157     def __gt__(self, *args, **kwargs):  # real signature unknown
158         """ (num1).__ge__(num2) 如果num1大于num2,则返回True,否则返回False """
159         """ Return self>value. """
160         pass
161 
162     def __hash__(self, *args, **kwargs):  # real signature unknown
163         """ 如果对象object为哈希表类型,返回对象object的哈希值。哈希值为整数。
164         在字典查找中,哈希值用于快速比较字典的键。两个数值如果相等,则哈希值也相等 """
165         """ Return hash(self). """
166         pass
167 
168     def __index__(self, *args, **kwargs):  # real signature unknown
169         """ 用于切片,数字无意义
170             x[y:z] <==> x[y.__index__():z.__index__()]
171         """
172         """ Return self converted to an integer, if self is suitable for use as an index into a list. """
173         pass
174 
175     def __init__(self, x, base=10):  # known special case of int.__init__
176         """ 构造方法,创建int对象时自动调用 """
177         """
178         int(x=0) -> integer
179         int(x, base=10) -> integer
180 
181         Convert a number or string to an integer, or return 0 if no arguments
182         are given.  If x is a number, return x.__int__().  For floating point
183         numbers, this truncates towards zero.
184 
185         If x is not a number or if base is given, then x must be a string,
186         bytes, or bytearray instance representing an integer literal in the
187         given base.  The literal can be preceded by '+' or '-' and be surrounded
188         by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
189         Base 0 means to interpret the base from the string as an integer literal.
190         >>> int('0b100', base=0)
191         4
192         # (copied from class doc)
193         """
194         pass
195 
196     def __int__(self, *args, **kwargs):  # real signature unknown
197         """ 转换成整数类型 """
198         """ int(self) """
199         pass
200 
201     def __invert__(self, *args, **kwargs):  # real signature unknown
202         """ 按位取反, (x).__invert__()类似于-x-1  """
203         """ ~self """
204         pass
205 
206     def __le__(self, *args, **kwargs):  # real signature unknown
207         """ (num1).__ge__(num2) 如果num1小于或等于num2,则返回True,否则返回False """
208         """ Return self<=value. """
209         pass
210 
211     def __lshift__(self, *args, **kwargs):  # real signature unknown
212         """ """
213         """ Return self<<value. """
214         pass
215 
216     def __lt__(self, *args, **kwargs):  # real signature unknown
217         """ (num1).__ge__(num2) 如果num1小于num2,则返回True,否则返回False """
218         """ Return self<value. """
219         pass
220 
221     def __mod__(self, *args, **kwargs):  # real signature unknown
222         """ 取模运算 """
223         """ Return self%value. """
224         pass
225 
226     def __mul__(self, *args, **kwargs):  # real signature unknown
227         """ 乘法运算 """
228         """ Return self*value. """
229         pass
230 
231     def __neg__(self, *args, **kwargs):  # real signature unknown
232         """ (x).__neg() <==> -(x) """
233         """ -self """
234         pass
235 
236     @staticmethod  # known case of __new__
237     def __new__(*args, **kwargs):  # real signature unknown
238         """ Create and return a new object.  See help(type) for accurate signature. """
239         pass
240 
241     def __ne__(self, *args, **kwargs):  # real signature unknown
242         """ x.__ne__(y) 如果x与y的值不相等,返回True,相等则返回False """
243         """ Return self!=value. """
244         """  """
245         pass
246 
247     def __or__(self, *args, **kwargs):  # real signature unknown
248         """ 按位或运算 """
249         """ Return self|value. """
250         pass
251 
252     def __pos__(self, *args, **kwargs):  # real signature unknown
253         """ (x).__pos__()  <==> +(x) """
254         """ +self """
255         pass
256 
257     def __pow__(self, *args, **kwargs):  # real signature unknown
258         """ (x).__pow__(y)  <==> x**y """
259         """ Return pow(self, value, mod). """
260         pass
261 
262     def __radd__(self, *args, **kwargs):  # real signature unknown
263         """ 后面的数加上前面的数 """
264         """ Return value+self. """
265         pass
266 
267     def __rand__(self, *args, **kwargs):  # real signature unknown
268         """ 后面的数对前面的数进行按位与运算 """
269         """ Return value&self. """
270         pass
271 
272     def __rdivmod__(self, *args, **kwargs):  # real signature unknown
273         """ (num1).__divmod__(num2) 将num2除以num1,返回的是一个格式为(商,余数)的元组 """
274         """ Return divmod(value, self). """
275         pass
276 
277     def __repr__(self, *args, **kwargs):  # real signature unknown
278         """ 转化为解释器可读取的形式 """
279         """ Return repr(self). """
280         pass
281 
282     def __rfloordiv__(self, *args, **kwargs):  # real signature unknown
283         """ 后面的数对前面的数进行取整除运算 """
284         """ Return value//self. """
285         pass
286 
287     def __rlshift__(self, *args, **kwargs):  # real signature unknown
288         """ 左移 (x).__lshift__(y) 相当与y*2^x """
289         """ Return value<<self. """
290         pass
291 
292     def __rmod__(self, *args, **kwargs):  # real signature unknown
293         """ 后面的数与前面的数进行取模运算 """
294         """ Return value%self. """
295         pass
296 
297     def __rmul__(self, *args, **kwargs):  # real signature unknown
298         """ 后面的数乘以前面的数 """
299         """ Return value*self. """
300         pass
301 
302     def __ror__(self, *args, **kwargs):  # real signature unknown
303         """ 后面的数和前面的数进行按位或运算 """
304         """ Return value|self. """
305         pass
306 
307     def __round__(self, *args, **kwargs):  # real signature unknown
308         """ 返回小数点四舍五入到N个数字,整型无意义 """
309         """
310         Rounding an Integral returns itself.
311         Rounding with an ndigits argument also returns an integer.
312         """
313         pass
314 
315     def __rpow__(self, *args, **kwargs):  # real signature unknown
316         """ (x).__rpow__(y) <==> y**x """
317         """ Return pow(value, self, mod). """
318         pass
319 
320     def __rrshift__(self, *args, **kwargs):  # real signature unknown
321         """ 右移 (x).__rrshift__(y) 相当于y//(2^x) """
322         """ Return value>>self. """
323         pass
324 
325     def __rshift__(self, *args, **kwargs):  # real signature unknown
326         """ 右移 (x).__rshift__(y) 相当于x//(2^y) """
327         """ Return self>>value. """
328         pass
329 
330     def __rsub__(self, *args, **kwargs):  # real signature unknown
331         """ 后面的数减去前面的数 """
332         """ Return value-self. """
333         pass
334 
335     def __rtruediv__(self, *args, **kwargs):  # real signature unknown
336         """ 将后面的数除以前面的数 """
337         """ Return value/self. """
338         pass
339 
340     def __rxor__(self, *args, **kwargs):  # real signature unknown
341         """ 将后面的数与前面的数按位异或 """
342         """ Return value^self. """
343         pass
344 
345     def __sizeof__(self, *args, **kwargs):  # real signature unknown
346         """ 返回占用的字节数 """
347         """ Returns size in memory, in bytes """
348         pass
349 
350     def __str__(self, *args, **kwargs):  # real signature unknown
351         """ 转换成可读取的形式 """
352         """ Return str(self). """
353         pass
354 
355     def __sub__(self, *args, **kwargs):  # real signature unknown
356         """ 将前面的数减去后面的数 """
357         """ Return self-value. """
358         pass
359 
360     def __truediv__(self, *args, **kwargs):  # real signature unknown
361         """ 将前面的数除以后面的数 """
362         """ Return self/value. """
363         pass
364 
365     def __trunc__(self, *args, **kwargs):  # real signature unknown
366         """ 返回数值被截取为整型的值,在整型中无意义 """
367         """ Truncating an Integral returns itself. """
368         pass
369 
370     def __xor__(self, *args, **kwargs):  # real signature unknown
371         """ 将前面的数与后面的数按位异或 """
372         """ Return self^value. """
373         pass

 

 

posted @ 2018-07-20 22:44  Sorcerer  阅读(487)  评论(0)    收藏  举报