Python statements have some basic rules and special characters:
- # Indicates that the subsequent characters are Python comments.
- Line feed (\ n) is a standard line separator (usually one statement line)
- Backslash (\) to continue the previous line
- Semicolon (;) connects two statements in one row
- Colon (:) separates the header and body of the code block
- Statements (code blocks) are implemented using indentions.
- Separate unused code blocks with different indentions in Depth
- Python files are organized as modules
Variable assignment: A value is not directly assigned to a variable. in Python, objects are passed through reference. The value assignment statement of Python does not return values. The following statements are invalid:
>>> x=1>>> y=(x=x+1
No problem with chain assignment:
>>> x=1>>> y=x=x+1>>>2, 2)
Python does not support pre-and post-auto-increment/auto-increment operations like x ++ or -- x.
Repeated values:
>>> x=y=z=1>>>1>>>1>>>1
You can assign multiple values:
>>> x,y,z=1,2,>>>1>>>2>>>
Usually enclosed in parentheses to enhance code readability:
>>> (x,y,z)=(1,2,>>>1>>>2>>>
Using the multivariate value Assignment Method in Python, You can exchange values of two variables without intermediate variables:
>>> >>> x,y=1,2>>>1>>>2>>> x,y=>>>2>>>1