Simple data types and assignments
Variables do not need to be declared
Python variables do not need to be declared, you can directly enter:
>>>a = 10
Then you will have a variable a in your memory, and its value is 10, its type is integer (integer). You don't need to make any special declarations before this, and the data type is automatically determined by Python.
>>>print a >>>print type(a)
Then there will be the following output:
10
Here, we learned a built-in function type() to query the type of a variable.
Recycle variable names
If you want a to store different data, you can assign the value directly without deleting the original variable.
>>>a = 1.3 >>>print a,type(a)
There will be the following output
1.3
We see another usage of print, that is, print is followed by multiple outputs, separated by commas.
Basic data types
a=10 # int 整数 a=1.3 # float 浮点数 a=True # 真值 (True/False) a='Hello!' # 字符串
The above are the most commonly used data types. For strings, double quotes can also be used.
(In addition, there are other data types such as fractions, characters, plurals, etc. If you are interested, you can learn about it)
Summary
Variables do not need to be declared or deleted, and can be directly recycled and applied.
type(): Query data type
integer, floating point number, true value, string