Anonymous user
Boston Python workshop 2/Friday tutorial: Difference between revisions
Boston Python workshop 2/Friday tutorial (view source)
Revision as of 00:12, 27 May 2011
, 13 years ago→Flow Control
Line 428:
</pre>
So what is going on here? When Python encounters the <code>if</code> keyword, it <i>evaluates</i> the <i>expression</i> following the keyword and before the colon. If that expression is <b>True</b>, Python executes the code in the indented code block under the <code>if</code> line. If that expression is <b>False</b>, Python skips over the code block
In this case, because <code>1</code> is truthy, Python executes the code block under the if statement, and we see "1 is truthy" printed to the screen.
What about a 0? Is it truthy?
<pre>
|