Python Learning Tour - Variables

Rules for naming variables:

1. It must be descriptive;
2. The variable name can only be composed of _, numbers and letters, not spaces or special characters;
3. The variable name cannot be Chinese;
4. The variable name cannot start with a number;
5. Reserved characters cannot be used (eg print cannot be used as a variable name).

 

 

Constants: invariable quantities such as pie=3.1415926...
All variables in python are variable (constants can also be changed, such as pie can be reassigned),
so you can use the variable name in all uppercase to represent this variable named constant .

 

Reassignment of variables:

 

name2=name means name2 finds "Jack" in memory through name and points to it, at this time name and name2 point to "Jack" at the same time

 

name="Bob" Create a new "Bob" in memory and let name point to "Bob" At this time, name2 still points to "Jack"

 

 

Delete the value in memory:

Method 1: del variable name      

Method 2: Don't let the variable point to it (the python memory recycling mechanism will recycle the content in the memory that is not pointed to by the variable every once in a while)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324973362&siteId=291194637