Comments
- Single-line comment
#content - Multi-line comment
'''
This green section is a comment
This part is also
'''
This is no longer a comment
# Single-line comment
print("'''This is not a comment''' Will this be printed?")
a='''Hello'''1
Terminal: SyntaxError: invalid syntax
'''
Writing like this will cause an error. It seems inserting comments in the middle of code affects execution.
Multi-line strings can be defined using '''string'''. The comment is interpreted as an assignment operation, so the above error points to the trailing 1.
'''
Encoding Format
- In Python 2.x, the default source file encoding is ASCII. If the content contains Chinese characters, the file cannot be read and output correctly without specifying the encoding format. You can add the following code at the beginning of the source file to specify UTF-8 encoding:
# -*- coding: UTF-8 -*-
In Python 3.x, the default source file encoding is UTF-8. Therefore, when using Python 3.x, specifying the encoding format is usually unnecessary.
Identifiers
- Identifiers are a universal concept in programming, used to name ==variables, functions, interfaces, classes==, etc.
- Python identifiers are case-sensitive and consist of letters, numbers, and underscores. The first character must be a letter or underscore and cannot start with a number. In Python 3.x, Chinese characters can be used as identifiers.
- Identifiers starting with underscores have special meanings:
- A single underscore prefix (e.g.,
_name) indicates a class attribute that cannot be accessed directly and requires an interface provided by the class. - A double underscore prefix (e.g.,
__age) indicates a private class member. - Identifiers with double underscores at both ends (e.g.,
__init__(), the class constructor) represent built-in Python identifiers.
- A single underscore prefix (e.g.,

When will I have a drink and discuss the details again?