Expressions and statements for Python:
Expression: A sequence of one or more operands and 0 or more operators.
Statement: The operation to be implemented.
Declare variables, assignment statements, control statements, conditional statements .... The order in which statements are executed in a program is called a control flow. is a single line of code ending with a semicolon, or a series of single-line statements in a statement block.
Expression operators commonly used in Python:
x + y, xy
× * y, x/y, x//y, x%y
x or y, x and Y, not X
X in Y, x not in Y
X is y, x isn't is Y
x < Y, x > Y, x<=y, x>=y,x = = y, x! = y
Bit operations:
x | Y, X & y, x ^y (XOR), x << y, x >> y
Unary operations:
-X, +x, ~x
Power Operation:
X * * y
Indexes and Shards:
Call Operation:
X (..... )
Attribute operations:
X. Attribute
Tuples: (... )
Sequence: [... ]
Dictionary: {... }
Ternary selection expression:
X if y else Z
Anonymous functions:
Lambda Args:expression generating an anonymous function expression
Generator function Send protocol:
Yield x
Operation Priority:
(),[],{}
S[I],S[I:J]
S.attribute
S (...)
+x,-X, ~x
X * * y
*,/,//,%
+, -
<<, >>
&
^
|
<=,< >,>= ==,!=
IS, isn't
In, not in
Not
and
Or
Lambda
The statements in Python:
Assignment statement;
Call
Print: Printing objects
If, elif, else,
For/else sequence iterations
While/else Normal Cycle
Pass: Placeholder
Break
Continue
Def:
Return
Yield
Global: namespaces
Raise: Triggering an exception
Import
From: Module Property access
Class: Classes
Try/except/finally: Catching exceptions
Del: Delete Reference
Assert: Debug Check
With/as: Environment Manager
Assignment statement: Variable names must be assigned in advance. Stealth assignment scenarios, import,from,def,class,for, function parameters
Tuples and lists: Supports decomposition assignment worth = left is a tuple or list, Python will match the right object and the left target according to the location, and the number will be different when it starts the exception, which can be done by slicing.
Multiple target assignment: NUM1 = num2 = num3 = 44
Enhanced Assignment: + =,-=,*=,/=,%=,//=
Python expressions and operators and operation Precedence