Variable does not need to be declared
Python variables do not need to be declared, you can enter directly:
Copy Code code as follows:
Then you have a variable in the memory of a, its value is 10, its type is integer (whole number). You don't have to make any special statements before, and the data types are automatically determined by Python.
Copy Code code as follows:
>>>print A
>>>print type (a)
Then there will be the following output:
Copy Code code as follows:
Here, we learned a built-in function type () to query the type of the variable.
Reclaim Variable Name
If you want a to store different data, you don't have to delete the original variable to assign the value directly.
Copy Code code as follows:
>>>a = 1.3
>>>print A,type (a)
will have the following output
Copy Code code as follows:
We see another use of print, which is that print is followed by multiple outputs, separated by commas.
Basic data types
Copy Code code as follows:
a=10 # int Integer
a=1.3 # Float floating-point number
A=true # Truth (true/false)
A= ' hello! ' # string
These are the most commonly used data types, and you can use double quotes for strings.
(in addition, there are scores, characters, complex numbers and other data types, interested can learn)
Summarize
Variables do not need to be declared, do not need to be deleted, can be directly recycled apply.
Type (): Query data type
Integers, floating-point numbers, truth values, strings