clause in python meaning

654 Views Asked by At

I was reading the python documentation and noticed the word clause being used in parts of sentences like: the try clause (the statement(s) between the try and except keywords) is executed, or Loop statements may have an else clause. What does clause mean?

1

There are 1 best solutions below

3
Allan Wind On

Clause, or more precisely a definite clause grammar, is a part of the the grammar used to define a programming language. Here is how it's defined for compound statements:

A compound statement consists of one or more ‘clauses.’ A clause consists of a header and a ‘suite.’ The clause headers of a particular compound statement are all at the same indentation level. Each clause header begins with a uniquely identifying keyword and ends with a colon. A suite is a group of statements controlled by a clause. A suite can be one or more semicolon-separated simple statements on the same line as the header, following the header’s colon, or it can be one or more indented statements on subsequent lines. compound statements

compound_stmt ::= ...
| while_stmt
...\

while_stmt ::= "while" assignment_expression ":" suite
...\

So the while_stmt or the equivalent right side "while" assignment_expression ":" suite is an example of a clause.