码迷,mamicode.com
首页 > 编程语言 > 详细

python基础系列(二)----各数据类型的详细方法描述

时间:2016-01-14 23:52:43      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

python基础

技术分享

一、整数

技术分享
  1 class int(object):
  2     """
  3     int(x=0) -> int or long
  4     int(x, base=10) -> int or long
  5     
  6     Convert a number or string to an integer, or return 0 if no arguments
  7     are given.  If x is floating point, the conversion truncates towards zero.
  8     If x is outside the integer range, the function returns a long instead.
  9     
 10     If x is not a number or if base is given, then x must be a string or
 11     Unicode object representing an integer literal in the given base.  The
 12     literal can be preceded by ‘+‘ or ‘-‘ and be surrounded by whitespace.
 13     The base defaults to 10.  Valid bases are 0 and 2-36.  Base 0 means to
 14     interpret the base from the string as an integer literal.
 15     >>> int(‘0b100‘, base=0)
 16     4
 17     """
 18     def bit_length(self): 
 19         """ 返回表示该数字的时占用的最少位数 """
 20         """
 21         int.bit_length() -> int
 22         
 23         Number of bits necessary to represent self in binary.
 24         >>> bin(37)
 25         ‘0b100101‘
 26         >>> (37).bit_length()
 27         6
 28         """
 29         return 0
 30 
 31     def conjugate(self, *args, **kwargs): # real signature unknown
 32         """ 返回该复数的共轭复数 """
 33         """ Returns self, the complex conjugate of any int. """
 34         pass
 35 
 36     def __abs__(self):
 37         """ 返回绝对值 """
 38         """ x.__abs__() <==> abs(x) """
 39         pass
 40 
 41     def __add__(self, y):
 42         """ x.__add__(y) <==> x+y """
 43         pass
 44 
 45     def __and__(self, y):
 46         """ x.__and__(y) <==> x&y """
 47         pass
 48 
 49     def __cmp__(self, y): 
 50         """ 比较两个数大小 """
 51         """ x.__cmp__(y) <==> cmp(x,y) """
 52         pass
 53 
 54     def __coerce__(self, y):
 55         """ 强制生成一个元组 """ 
 56         """ x.__coerce__(y) <==> coerce(x, y) """
 57         pass
 58 
 59     def __divmod__(self, y): 
 60         """ 相除,得到商和余数组成的元组 """ 
 61         """ x.__divmod__(y) <==> divmod(x, y) """
 62         pass
 63 
 64     def __div__(self, y): 
 65         """ x.__div__(y) <==> x/y """
 66         pass
 67 
 68     def __float__(self): 
 69         """ 转换为浮点类型 """ 
 70         """ x.__float__() <==> float(x) """
 71         pass
 72 
 73     def __floordiv__(self, y): 
 74         """ x.__floordiv__(y) <==> x//y """
 75         pass
 76 
 77     def __format__(self, *args, **kwargs): # real signature unknown
 78         pass
 79 
 80     def __getattribute__(self, name): 
 81         """ x.__getattribute__(‘name‘) <==> x.name """
 82         pass
 83 
 84     def __getnewargs__(self, *args, **kwargs): # real signature unknown
 85         """ 内部调用 __new__方法或创建对象时传入参数使用 """ 
 86         pass
 87 
 88     def __hash__(self): 
 89         """如果对象object为哈希表类型,返回对象object的哈希值。哈希值为整数。在字典查找中,哈希值用于快速比较字典的键。两个数值如果相等,则哈希值也相等。"""
 90         """ x.__hash__() <==> hash(x) """
 91         pass
 92 
 93     def __hex__(self): 
 94         """ 返回当前数的 十六进制 表示 """ 
 95         """ x.__hex__() <==> hex(x) """
 96         pass
 97 
 98     def __index__(self): 
 99         """ 用于切片,数字无意义 """
100         """ x[y:z] <==> x[y.__index__():z.__index__()] """
101         pass
102 
103     def __init__(self, x, base=10): # known special case of int.__init__
104         """ 构造方法,执行 x = 123 或 x = int(10) 时,自动调用,暂时忽略 """ 
105         """
106         int(x=0) -> int or long
107         int(x, base=10) -> int or long
108         
109         Convert a number or string to an integer, or return 0 if no arguments
110         are given.  If x is floating point, the conversion truncates towards zero.
111         If x is outside the integer range, the function returns a long instead.
112         
113         If x is not a number or if base is given, then x must be a string or
114         Unicode object representing an integer literal in the given base.  The
115         literal can be preceded by ‘+‘ or ‘-‘ and be surrounded by whitespace.
116         The base defaults to 10.  Valid bases are 0 and 2-36.  Base 0 means to
117         interpret the base from the string as an integer literal.
118         >>> int(‘0b100‘, base=0)
119         4
120         # (copied from class doc)
121         """
122         pass
123 
124     def __int__(self): 
125         """ 转换为整数 """ 
126         """ x.__int__() <==> int(x) """
127         pass
128 
129     def __invert__(self): 
130         """ x.__invert__() <==> ~x """
131         pass
132 
133     def __long__(self): 
134         """ 转换为长整数 """ 
135         """ x.__long__() <==> long(x) """
136         pass
137 
138     def __lshift__(self, y): 
139         """ x.__lshift__(y) <==> x<<y """
140         pass
141 
142     def __mod__(self, y): 
143         """ x.__mod__(y) <==> x%y """
144         pass
145 
146     def __mul__(self, y): 
147         """ x.__mul__(y) <==> x*y """
148         pass
149 
150     def __neg__(self): 
151         """ x.__neg__() <==> -x """
152         pass
153 
154     @staticmethod # known case of __new__
155     def __new__(S, *more): 
156         """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
157         pass
158 
159     def __nonzero__(self): 
160         """ x.__nonzero__() <==> x != 0 """
161         pass
162 
163     def __oct__(self): 
164         """ 返回改值的 八进制 表示 """ 
165         """ x.__oct__() <==> oct(x) """
166         pass
167 
168     def __or__(self, y): 
169         """ x.__or__(y) <==> x|y """
170         pass
171 
172     def __pos__(self): 
173         """ x.__pos__() <==> +x """
174         pass
175 
176     def __pow__(self, y, z=None): 
177         """ 幂,次方 """ 
178         """ x.__pow__(y[, z]) <==> pow(x, y[, z]) """
179         pass
180 
181     def __radd__(self, y): 
182         """ x.__radd__(y) <==> y+x """
183         pass
184 
185     def __rand__(self, y): 
186         """ x.__rand__(y) <==> y&x """
187         pass
188 
189     def __rdivmod__(self, y): 
190         """ x.__rdivmod__(y) <==> divmod(y, x) """
191         pass
192 
193     def __rdiv__(self, y): 
194         """ x.__rdiv__(y) <==> y/x """
195         pass
196 
197     def __repr__(self): 
198         """转化为解释器可读取的形式 """
199         """ x.__repr__() <==> repr(x) """
200         pass
201 
202     def __str__(self): 
203         """转换为人阅读的形式,如果没有适于人阅读的解释形式的话,则返回解释器课阅读的形式"""
204         """ x.__str__() <==> str(x) """
205         pass
206 
207     def __rfloordiv__(self, y): 
208         """ x.__rfloordiv__(y) <==> y//x """
209         pass
210 
211     def __rlshift__(self, y): 
212         """ x.__rlshift__(y) <==> y<<x """
213         pass
214 
215     def __rmod__(self, y): 
216         """ x.__rmod__(y) <==> y%x """
217         pass
218 
219     def __rmul__(self, y): 
220         """ x.__rmul__(y) <==> y*x """
221         pass
222 
223     def __ror__(self, y): 
224         """ x.__ror__(y) <==> y|x """
225         pass
226 
227     def __rpow__(self, x, z=None): 
228         """ y.__rpow__(x[, z]) <==> pow(x, y[, z]) """
229         pass
230 
231     def __rrshift__(self, y): 
232         """ x.__rrshift__(y) <==> y>>x """
233         pass
234 
235     def __rshift__(self, y): 
236         """ x.__rshift__(y) <==> x>>y """
237         pass
238 
239     def __rsub__(self, y): 
240         """ x.__rsub__(y) <==> y-x """
241         pass
242 
243     def __rtruediv__(self, y): 
244         """ x.__rtruediv__(y) <==> y/x """
245         pass
246 
247     def __rxor__(self, y): 
248         """ x.__rxor__(y) <==> y^x """
249         pass
250 
251     def __sub__(self, y): 
252         """ x.__sub__(y) <==> x-y """
253         pass
254 
255     def __truediv__(self, y): 
256         """ x.__truediv__(y) <==> x/y """
257         pass
258 
259     def __trunc__(self, *args, **kwargs): 
260         """ 返回数值被截取为整形的值,在整形中无意义 """
261         pass
262 
263     def __xor__(self, y): 
264         """ x.__xor__(y) <==> x^y """
265         pass
266 
267     denominator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
268     """ 分母 = 1 """
269     """the denominator of a rational number in lowest terms"""
270 
271     imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
272     """ 虚数,无意义 """
273     """the imaginary part of a complex number"""
274 
275     numerator = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
276     """ 分子 = 数字大小 """
277     """the numerator of a rational number in lowest terms"""
278 
279     real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
280     """ 实属,无意义 """
281     """the real part of a complex number"""
View Code

 二、长整型,基本同整数

三、浮点数

四、字符串

五、列表

六、元组

七、字典

 

python基础系列(二)----各数据类型的详细方法描述

标签:

原文地址:http://www.cnblogs.com/weiqiangwang/p/5132008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!