If there is more than one Python version in the environment, specify the appropriate version in the header:
#!/usr/bin/python
The default encoding format in Python is the ASCII format, which fails to print correctly when the encoding format is not modified, so the error occurs when reading Chinese.
Workaround as long as the file is added at the beginning
Python identifiers
In Python, identifiers are made up of letters, numbers, and underscores.
In Python, all identifiers can contain English, numbers, and underscores (_), but cannot begin with a number.
Identifiers in Python are case-sensitive.
Identifiers that begin with an underscore are of special significance. The _foo of a single underline is not directly accessing the properties of the class, but is accessed through the interface of the class. Cannot import using from XXX import *.
A _foo that begins with a double underscore represents a private member of a class, and a _foo that begins with a double underscore represents a special identifier for a particular method in Python, and _init_ () represents the constructor of a class.
Python can chevalier multiple statements on the same line by separating them with semicolons (;), such as:
>>> print ' Hello ';p rint ' world ' HelloWorld
Python reserved characters:
Reserved words cannot be used as constants or variables.
Line and indent
The amount of white space to indent is variable, but all code block statements must contain the same amount of indentation whitespace, which must be observed.
If true: print "True" Else: print "False"
Multi-line statements
A general new line in a Python statement is used as a terminator to the statement.
We can use () to divide a line of statements into multiple displays, for example:
Total = Item_one + item_two + Item_three
A statement that contains [],{} or () parentheses does not need to use a multiline connector. Example:
days = [' Monday ', ' Tuesday ', ' Wednesday ', ' Thursday ', ' Friday ']
Python boot
Python can use quotation marks ('), double quotation marks ("), three quotation marks (" "), or (" "") to represent a string, and the beginning of the quotation mark must be of the same type.
Where three quotation marks can be composed of more than one line, the shortcut syntax for writing multiple lines of text, often used in a document string, at a specific location of the file, as a comment.
Word = ' word ' sentence = ' This is a sentence. "paragraph =" "" This is a paragraph. Contains multiple statements "" "
Python comments
A single line comment in Python starts with #
#!/usr/bin/python#-*-coding:utf-8-*-# file name: test.py# First Comment
Annotations can be added to the end of a statement or an expression.
Print "Hello, python!"; # A second comment
Use three single quotation marks ("') or three double quotation marks (" ") for the du note in Python
#!/usr/bin/python#-*-coding:utf-8-*-# file name: test.py "This is a multiline comment, using single quotation marks. This is a multiline comment, using single quotation marks. This is a multiline comment, using single quotation marks. "" "This is a multiline comment, using double quotes. This is a multiline comment, using double quotation marks. This is a multiline comment, using double quotation marks. """
Python Empty Line
A blank line separates between functions or methods of a class, indicating the beginning of a new piece of code. The class and function entries are also separated by a line of spaces to highlight the beginning of the function entry.
Blank lines are different from code indentation, and empty lines are not part of the Python syntax. Do not insert blank lines when writing, the interpreter will not error. The purpose of a blank line is to separate the code of different functions or meanings at each end to facilitate maintenance or refactoring of future code.
A blank line is also part of the program
————————————————————————————————————————————————————————————
Python Learning notes (i)