Python 基本数据类型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 基本数据类型相关的知识,希望对你有一定的参考价值。

一运算符

1算数运算符

技术分享

2.比较运算符

技术分享

3.赋值运算符

技术分享

4.逻辑运算符

技术分享

 

二.基本数据类型

1.数字

数字 age = 123

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

indetationError 缩进错误

一个等号是赋值,两个等号是比较。

 

2.字符串

a1=‘abs‘

a2="sdf"

a3="""nsdfis"""

 

 

3.布尔值
True/False

 


以上是关于Python 基本数据类型的主要内容,如果未能解决你的问题,请参考以下文章

python 用于数据探索的Python代码片段(例如,在数据科学项目中)

13 个非常有用的 Python 代码片段

02 python基本语法和数据类型

Python从零开始:变量与基本数据类型

python基本数据类型

python基本数据类型都有哪些