Python day1 variable, pythonday1
Python path, Day1-Python basic 1 variable
Variables are used to store reference and operation information in computer programs. They also provide a way to mark data with descriptive names so that our programs are more clearly understood by readers and ourselves. It is helpful to think of variables as containers for saving information. They only aim to mark and store data in memory. Then you can use the data throughout the program.
Declare Variables
123 |
#_*_coding:utf-8_*_ name = "Many Qian" |
The code above declares a variable named: name. The value of the variable name is: "Many Qian"
Rule for variable definition:
- Variable names can only be any combination of letters, numbers, or underscores
- The first character of the 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)
- [Abs,Dict,Help,Min,Setattr,All,Dir,Hex,Next,Slice,Any,Divmod,Id,Object,Sorted,Ascii,Enumerate,Input,Oct,Staticmethod,Bin,Eval,Int,Open,Str,Bool,Exec,Isinstance,Ord,Sum,Bytearray,Filter,Issubclass,Pow,Super,Bytes,Float,Iter,Print,Tuple,Callable,Format,Len,Property,Type,Chr,Frozenset,List,Range,Vars,Classmethod,Getattr,Locals,Repr,Zip,Compile,Globals,Map,Reversed,_ Import __,Complex,Hasattr,Max,Round, Delattr,Hash,Memoryview,Set,]
- Conventional rules: 1. Do not use Chinese characters (though supported by Python3) 2. Do not write pinyin 3. It is best to use English words (the combination of words and underlines is the best to connect, not the first letter of "hump)
- Constant (although Python does not support constants, we will define them as "PIE ")
- The following keywords cannot be declared as variable names
- ['And', 'as', 'assert ', 'Break', 'class', 'contine', 'def', 'del ', 'elif ', 'else', 'Got t', 'exec ', 'Finally', 'for ', 'from', 'global', 'if', 'import', 'in ', 'Is ', 'lambda', 'not ',' or ', 'pass', 'print', 'raise ', 'Return', 'try', 'while ', 'with', 'yield ',]
Variable assignment
12345678910111213 |
name = "Many Qian" name2 = name print (name,name2) name = "Tom" print ( "What is the value of name2 now?" ) The result is: What is the value of parameter Qian now? |
Garbage Collection Mechanism
First, we need to know what garbage is. Some values in the memory do not have any references. What is reference? For example, if a house number is referenced once, there is no house number on the body, and the reference value is garbage, Python will recycle the garbage regularly, so we don't have to consider this!