Python road, Day1-python base 1 variables
Variables are used to store information that is referenced and manipulated in a computer program. They also provide a way to tag data with descriptive names so that our programs can be more clearly understood by the reader and ourselves. It is helpful to consider variables as containers for storing information. Their sole purpose is to mark and store data in memory. This data can then be used throughout the program.
declaring variables
123 |
#_*_coding:utf-8_*_ name = "Many Qian" |
The code above declares a variable named: Name, and the value of the variable name is: "Many Qian"
Rules for variable definitions:
- Variable names can only be any combination of letters, numbers, or underscores
- The first character of a variable name cannot be a number
- (The function name defined in program programming cannot be used as a variable name, otherwise it will dig a hole for itself)
- Conventional rules: 1. Do not use Chinese (although Python3 support) 2. Do not write Pinyin 3. English words are the best (the word combination is best to use underline, do not "hump" the first letter capital)
- Constants (Python does not support constants, we define it as "PIE")
- The following keywords cannot be declared as variable names
- [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ',]
Assigning values to variables
1234567891011121314 |
name = "Many Qian" name2 = name print (name,name2) name = "Tom" print ( "What is the value of name2 now?" ) The result would be: What's the value of Tom now? |
Little white python path day1 variable