Python_01 _ Variable _ comment _ input_if _ indent, python_01_input_if
Personal notes, only for learning records. please correct me if you have any mistakes
Variable naming rules:
1: The variable name must be a combination of letters, underscores, and numbers.
2: The variable name cannot start with a number.
3: variable names cannot be keywords in Python
4: The variable name cannot be Chinese
5. If the variable name in Python has multiple words, it is recommended to connect the variable names with underlines (Common camper in other languages)
6: constants cannot be defined in Python: all the variables in python are variable, so the variable names in full uppercase are used to represent constants.
Variable assignment:
1 name1 = "laowang"2 name2 = name13 name1 = "xiaozhang"
Does the name2 value change at this time?
A: No. The name2 value is still "laowang", and the name1 value is changed to "xiaozhang"
Deletion of variables:
1 age = 202 del age
Delete variable references, instead of releasing memory. GC processes memory reclaim.
Python encoding:
Python2.x: default encoding ASCII
Python3.x: Unicode by default
Annotations in Python:
Python single line comment: #
Python multi-line comment: the start and end of the three quotation marks are "" comment content "".
In fact, the three quotation marks for multi-line comments in python are not really comments, but strings that are not referenced!
Because it is not referenced, the strings caused by the three quotation marks are ignored by the python interpreter. Therefore, it can be used as a comment.
Input ():
1 name = input ("enter your name:") 2 age = int (input ("Enter your age :"))
The content received by input is of the str type (string) by default)
If... else... statement:
1 if name = "laowang": 2 print ("Old Wang") 3 else: 4 print ("James ")
Note: There is no else if syntax in python, but it is abbreviated as elif.
Python indent:
The tab key and space cannot be mixed, either tab indent or space indent (any space, as long as the indentation is consistent ), the recommended indentation is to use four spaces (the tab key in the text editor is converted to four spaces)