Introduction to basic data types and variable declarations in basic python tutorials
Variable does not need to be declared
Python variables do not need to be declared. You can enter them directly:
Copy codeThe Code is as follows:
>>> A = 10
Then there is a variable a in your memory. Its value is 10 and its type is integer ). Before that, you do not need to make any special declaration, but the data type is automatically determined by Python.
Copy codeThe Code is as follows:
>>> Print
>>> Print type ()
The following output is displayed:
Copy codeThe Code is as follows:
10
<Type 'int'>
Here, we learned a built-in function type () to query the type of a variable.
Reclaim variable name
If you want a to store different data, you can directly assign values without deleting the original variables.
Copy codeThe Code is as follows:
>>> A = 1.3
>>> Print a, type ()
The following output is displayed:
Copy codeThe Code is as follows:
1.3 <type 'float'>
We can see another usage of print, that is, print is followed by multiple outputs, separated by commas.
Basic Data Type
Copy codeThe Code is as follows:
A = 10 # int integer
A = 1.3 # float floating point number
A = True # True Value (True/False)
A = 'Hello! '# String
The above is the most common data type. Double quotation marks can also be used for strings.
(In addition, there are scores, characters, plural numbers, and other data types. If you are interested, you can learn)
Summary
Variables do not need to be declared or deleted. They can be recycled directly.
Type (): query data type
Integer, floating point, true value, string
How does one define the data type in python, that is, declare the variable type?
This is not a declaration type problem, because a and B are already int when you call, so the number to be divided is only an integer. If you declare C in time, the result is only 0.0.
Suggestion:
Def test (a, B ):
A1 = float ()
B1 = float (B)
C = a1/b1
Return c
Python Data Type
CS is a reference.
The difference between reference and pointer should be clear: the former is the memory alias, and the latter is the storage variable of the memory address.
CS is a reference. To return the C language, you must use pointer variables instead of pointer variables.
The pointer should accept id (CS ).
* The pointer accepts cs.
Appendix: actual operation of the ID function
>>> Cd
'Abcdef'
>>> Id (cd)
35255712