[Python] Sweet Is it sweet? About suites and expressions in the official documentation

[Python] Sweet Is it sweet? About suites and expressions in the official documentation

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. **


For example, in the case of the if statement "If A, then B", it will be as follows. ・ Expression = A ・ Suite = B
** Meaning of suite ** By the way, katakana is sweet, but the spelling is different from sweets such as sweets and desserts.

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.


■suite It is described in the syntax of if statement, try statement, etc. on the official page.

image.png image.png

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.

Official page

To do

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.

image.png

** ▼ How to write the official page ** There are no line breaks when writing the official page. This works the same way.

if statement example


A = 90
if A == 100:print('A is 100.')

** ▼ About clause ** When conditional branching, multiple clauses can be created. A suite can also be created for each section.

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.')
image.png

■expression This is also described in the syntax of if statement, try statement, etc. on the official page like suite.

image.png image.png image.png image.png image.png

expression type

There are also some impressions in the above syntax.

①assignment_expression ②expression_list ③expression


①assignment_expression The official name is "substitution formula". It is used in if statements and while statements.

An inequality sign that connects some letters and numbers.

A == 100 B >= 80 Such.


②expression_list The official name is "List of Expressions". (Well I do not know,,)

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.


③expression The official name is "conditional expression".

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.


▼ Official page ・ [Compound sentence](https://docs.python.org/ja/3/reference/compound_stmts.html#grammar-token-suite) ・ [Expression](https://docs.python.org/ja/3/reference/expressions.html#grammar-token-or-test)
_stmt This is a supplement, "_Stmt" written at the beginning of each syntax is an abbreviation of "statement" and means "○○ sentence".

▼ Example image.png

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.


*** The official documentation has a lot of jargon and is unfamiliar to write, but if you can read it, your understanding of python will be more accurate and faster (should).

Recommended Posts

[Python] Sweet Is it sweet? About suites and expressions in the official documentation
About the difference between "==" and "is" in python
About Python and regular expressions
It is easy to execute SQL with Python and output the result in Excel
Difference between == and is in python
About dtypes in Python and Cython
[Python] What is @? (About the decorator)
Delete a particular character in Python if it is the last
Overlapping regular expressions in Python and Java
What is "mahjong" in the Python library? ??
Find it in the procession and edit it
How to use is and == in Python
I set the environment variable with Docker and displayed it in Python
How to input a character string in Python and output it as it is or in the opposite direction.
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
What is "functional programming" and "object-oriented" in Python?
I compared the speed of regular expressions in Ruby, Python, and Perl (2013 version)
The answer of "1/2" is different between python2 and 3
[Xonsh] The Python shell is sharp and god
What is wheezy in the Docker Python image?
In Python, change the behavior of the method depending on how it is called
Think about depth-priority and width-priority searches in Python
Note that I understand the least squares algorithm. And I wrote it in Python.
[Note] About the role of underscore "_" in Python
About the behavior of Model.get_or_create () of peewee in Python
An engineer who has noticed the emo of cryptography is trying to implement it in Python and defeat it
POST JSON in Python and receive it in PHP
About the * (asterisk) argument of python (and itertools.starmap)
The result of making a map album of Italy honeymoon in Python and sharing it
[Selenium] Open the link in a new tab and move it [Python / Chrome Driver]
I want to replace the variables in the python template file and mass-produce it in another file.
Check if the string is a number in python
The simplest Python memo in Japan (classes and objects)
Sort in Python. Next, let's think about the algorithm.
Receive the form in Python and do various things
Carefully understand the exponential distribution and draw in Python
Read the csv file and display it in the browser
Plot and understand the multivariate normal distribution in Python
Check if it is Unix in the scripting language
Find the part that is 575 from Wikipedia in Python
Carefully understand the Poisson distribution and draw in Python
Find the Hermitian matrix and its eigenvalues in Python
Check if it is Unix in the scripting language
A reminder about the implementation of recommendations in Python
About __all__ in python
[Python] Isn't it copied even though "copy ()" is done? Beliefs and failures about deep copying
It is blocked by Proxy, a connection error occurs in Python or pip, and it is retried.
Recursively get the Excel list in a specific folder with python and write it to Excel.
[Python beginner] Variables and scope inside the function (when the processing inside the function is reflected outside the function and when it is not reflected)
An easy way to view the time taken in Python and a smarter way to improve it
Put Ubuntu in Raspi, put Docker on it, and control GPIO with python from the container
Try to make it using GUI and PyQt in Python
Test.py is not reflected on the web server in Python3.
Temporarily save a Python object and reuse it in another Python
Get the MIME type in Python and determine the file format
Sort and output the elements in the list as elements and multiples in Python.
Manipulate the clipboard in Python and paste the table into Excel
[Python] I installed the game from pip and played it
I tried programming the chi-square test in Python and Java.
Automatically get the port where Arduino is stuck in Python
[Python] Display the elapsed time in hours, minutes, and seconds (00:00:00)