擅长:python、mysql、java
<p>在<a href="https://docs.python.org/3/reference/grammar.html" rel="nofollow noreferrer">grammar</a>中,您正在寻找</p>
<pre><code>if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
</code></pre>
<p>(我重新排列了这些)。所以一个<code>if</code>语句有一个<code>suite</code>,如果<code>test</code>是真的,它就是执行的部分。<code>suite</code>要么是单个简单语句,要么是简单语句的缩进块。你知道吗</p>
<p>简单语句是一个带有可选分号的小语句或多个由分号分隔的小语句。<em>所有的</em>简单语句都以换行结束。你知道吗</p>
<p>如果你是在寻找设计意义上的原因,我只能猜测。这可能会使编写语法变得更简单,而且设计者可能会认为在您的示例中这样限制代码是一种好处。你知道吗</p>