(1) Python Code Standards
1. Quotes
Single and Double Quotes: In Python, both single quotes (‘) and double quotes (“) can be used to define strings. They can be used interchangeably without any difference in any context.
Triple Quotes: In Python, triple quotes (”’) are used for multi-line comments.
2. Parentheses
Round Brackets: Used for function calls, tuple definitions, and to increase precedence in mathematical operations.
Square Brackets: Used for defining lists and for indexing.
Curly Braces: Used for defining dictionaries, formatting sets, and for f-string formatting.
3. Spaces
Spaces should be added around operators (such as +, -, /, etc.), after commas, and around equal signs to enhance code readability and standardize the code.
4. Colons
In Python, colons are used to indicate the start of a code block, such as in if statements, for loops, while loops, function definitions, and class definitions. There should be a newline after the colon (the next line will be automatically indented).
5. Wavy Lines
Yellow Wavy Line: Indicates that the marked code is not standard but can run normally; it can be ignored.
Red Wavy Line: Indicates that the marked code has a syntax error, and the program cannot run; the error needs to be resolved.
Green Wavy Line: Indicates that the marked code generally has a spelling issue, such as writing ‘mane’ instead of ‘name’, which does not affect execution.
(2) Python Comments
The main purposes of comments include:
1. Improving Code Readability: By adding comments, you can help other programmers (or your future self) understand the functionality and logic of the code more quickly, similar to a memo that reminds you of key processes.
2. Preventing Code Execution and Documentation: In some cases, comments can be used to temporarily disable part of the code without deleting it, which is very convenient. At the same time, comments can also be used to document the purpose of the code and record learning points.
Usage of Comments
There are two main forms of comments: single-line comments and multi-line comments.
1. Single-line Comments:
Comment Shortcut: ctrl+/ 
Single-line comments start with a hash (#) and are written above or beside the line of code they are commenting on. The content after the # will not be executed by the Python interpreter and will be treated as a comment.
Single-line Comment Example
print("He11o, world!") # This is a single-line comment at the end of the code line (the gray part will not be executed by Python). 'print' is a function in Python that outputs text.
2. Multi-line Comments
Python does not have a dedicated syntax for multi-line comments, but it typically uses triple quotes (”’ or “””) to create multi-line strings.
'''This is a multi-line comment that uses triple quotes to enclose multiple lines of text but will not be executed by the Python interpreter.'''# The following code will run normally, while the above code will not be executed.print('This code will be executed.')
Every line of code written today is building confidence for the future ‘automation master’ – take it slow.