I was curious about the suite that appears in the official Python documentation, so make a note.
To summarize quickly, ・ ** suite is the processing after ":" ** ・ ** expression is an assignment expression, array, etc. **
suite is a noun such as a set or a set. It means a process (one set) used in a specific statement such as if statement or for statement.
There is a description about suite on the official page, but it is long ...
A compound sentence consists of one or more'clauses'. The clause consists of a header and a'suite'. The headers of each clause that make up a compound statement are all placed at the same indentation level. The header of each section begins with a uniquely identifying keyword and ends with a colon. A suite is a collection of sentences controlled by clauses. A suite is a collection of one or more simple statements placed after a colon on a line with a header, separated by a semicolon, or one more indented statement on the line following the header. Only suites of the latter form can further nest compound statements.
suite = processing under specific conditions
A process described after ":" in an if statement or for statement.
Although it is described immediately after ":" on the official page, it is generally the part that is displayed as an indent with a line break.
For example, in the case of the following if statement, which is super simple,
if statement example
A = 90
if A == 100:
print('A is 100.')
The relationship between clauses, headers, and suites is as follows.
if statement example
A = 90
if A == 100:print('A is 100.')
If statement example ②
A = 50
if A == 100:
print('A is 100.')
elif A >= 80:
print('A is over 80.')
elif A >= 70:
print('A is over 70.')
else:
print('A is 70 or less.')
■expression This is also described in the syntax of if statement, try statement, etc. on the official page like suite.
There are also some impressions in the above syntax.
①assignment_expression ②expression_list ③expression
An inequality sign that connects some letters and numbers.
A == 100 B >= 80 Such.
An expression that expresses a group of elements such as list and range.
Used in the for statement.
range(10) [1,2,3,4,5,6,7,8,9] [1:100] Such.
Expressions that perform Boolean operations (returning two choices of True or False) and lambda expressions (anonymous functions).
Used in except in try statements and in with statements. Things that become objects, such as functions and errors.
with open('sample.txt', 'a') as f: except ZeroDivisionError as e: except TypeError as e: Such.
▼ Example
try_stmt: try statement try1_stmt: try1 statement for_stmt: for statement if_stmt: if statement Such.
":: =" indicates that the formula of XX sentences is this.
Recommended Posts