1. Variable definition:
Naming the data, the name of the data is called a variable
2. Variable format:
[variable name] = [value]
(Note: The name in a Python variable cannot use the following characters because it has been referenced within Python
And,as,assert,break,class,continue,def,del,elif,else,except,exec,false,finally,
For,from,global,if,import,in,is,lambda,not,none,or,pass,print,raise,return,try,
True,while,with,yield)
Print variables:
>>print (variable)
Reference variable:
Use variable names directly
Cases:
Define a variable named "Test" with a value of string "Python test">>> test='python test' Print test python test
Variables refer to the variables themselves:
>>> test=test+str (1) print test python test1 + = str (1) Example: >>> test='python test' >>> Test + = str (1) >>> test 'python test1'
Third, the memory point of the variable
If I define a variable data = ' Alan ' and then assign data to string (string = data) then will the value of data change when I modify the string?
Let's look at the following diagram:
Comments:
1. When you create data = ' Alan ', the variable creates a space in memory to hold the value and the corresponding relationship, such as this memory space address is 010101
2. When string = data, the string variable points itself to the memory ' Alan ' memory address of 010101
3. However, when string = ' Lisa ', string will re-open a memory space to store ' Lisa ' memory address 010102 without modifying data
Instance:
>>> data ='Alan'>>> string =Data>>>string'Alan'>>> ID (data)//view the address in data memory45990656 >>> ID (string)//to view the address in a string memory45990656 >>> string ='Lisa'//re-assigning a value to a string>>> Data//See if the value of data changes, but it does not change'Alan'>>> ID (data)//View the memory address of data45990656 >>> ID (string)//View the memory address of a string45913152
Python Basics "Eighth" variable