variables do not need to be declared
Python variables do not need to be declared, you can enter directly:
Copy the Code code as follows:
>>>a = 10
Then your memory has a variable a, its value is 10, its type is an integer (integer). You don't need to make any special statements before, and data types are automatically determined by Python.
Copy CodeThe code is as follows:
>>>print A
>>>print type (a)
Then there will be the following output:
Copy CodeThe code is as follows:
10
Here, we learned a built-in function type () to query the type of the variable.
Recycle variable name
If you want a to store different data, you don't need to delete the original variable to directly assign the value. The
copy Code code is as follows:
>>>a = 1.3
>>>print A,type (a)
will have the following output
copy code code as follows:
1.3
We see another use of print, which is print followed by multiple outputs, separated by commas.
basic data type
Copy Code code is as follows:
a=10 # int integer
a=1.3 # F Loat floating-point
A=true # Truth (true/false)
a= ' hello! ' # string
above is the most commonly used data type, and in the case of strings, double quotes are also possible.
(in addition to other data types, such as fractions, characters, complex numbers, etc.)
Summary
Variables do not need to be declared, do not need to be deleted, can be directly recycled to apply.
Type (): Query data type
Integer, floating-point number, truth value, string