Execution of two ways python
Interactive
Pros: an implementation of a run, easy to modify
Disadvantages: Close disappear, can not be saved
Command line
Advantages: could have been saved
Disadvantages: all the code before they can finish debugging bug
And later try to use pycharm jupyter
variable
What is variable
All things described changes state
Compositional variables
Variable name (accepts variable value) = (sign copy) a variable variable value (numerical value) / Definitions
Naming the variable name
1. the variable name must number / letter / underscore (underline used when connecting)
2. Variable names should have read significance, storage is not an end, is the purpose of taking
3. You can not use keywords (some of which have been defined strings)
Variables defined in two ways
Underline style: python
nick_name="nick"
Camel: c / java
NickName="nick"
constant
The same amount, variable names all uppercase, but can not be changed can be changed, convention
Memory Management
If not within the print function variables declared in advance, it will create a variable, after printing, rapid release memory
When defining a variable, it opens up memory space to store a memory variable, while the reference count +1
When the value of a variable reference count of 0, it will trigger a garbage collection mechanism to release the memory of this variable
Small integer pool
Defined in python is an interval [-5,256] pool of small integers, it will open up a memory space to store each time you start the python small integer pool, whenever used in the definition of variables, which can be directly the value of the variable address assigned to a variable name, no need to re-open the memory space is optimized in pycharm, the time interval is short regardless of how much memory addresses are the same
3 wherein
print () print variable values
print (id ()) Print memory address
print (type ()) print variable type
Cross assignment
Decompressed form:
a,b,c=1,2,3
In the form of a plurality of variable value plus a plurality of variable name assignment symbol plus
Modify a and b in the case to ensure that the same memory address:
Application to the idea of intermediate variables
a=100
b=200
c=a
a=b
b=c
You can also directly assign cross
a=100
b=200
a,b=b,a
Chain assignment (to use the same value)
a=b=c=10
Single-line comments
Code (Code # plus)
Let it not be interpreted to explain the code running in python, invalidated
Codes can also be used to add comments
Multi-line comments
'' 'Code' '' (writing code within three quotes)