Small talk of Python data types
-
Python has data types
The difference between '520' and 520, string and integer
-
Integer
There is no difference between Python integer type and long integer type, and the integer length is not limited
-
Floating point
e counting method
>>> a=0.0000001 >>> a 1e-07 >>> 15e10 150000000000.0
-
Boolean type
Boolean type is integer 0, 1; but it is best not to perform operations
>>> True + True 2
-
Data type conversion
## 转换成整型 >>> a = '520' >>> b = int (a) #字符串转整型 >>> b 520 >>> a = 5.99 >>> b = int(a) #浮点转整型 >>> b 5 ## 转换成浮点型 float(a) ## 转换成字符串 str(a)
-
What is special about python
str is a built-in function and a keyword. Once used as a variable name, the function name is replaced;
>>> str = 'i love you' >>> c = str(5e19) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object is not callable
-
Determine the type of data
## 利用type >>> a= '520' >>> type(a) <class 'str'> ## 利用isinstance >>> a= '520' >>> isinstance(a,str) True