To create a tuple of one item, you need a comma after the value. Without the comma, Python just assumes you have an extra pair of parentheses, which is harmless, but it doesn't create a tuple.〔【出典】"Dive Into Python 3" by Mark Pilgrim ◆【和訳】Fukada & Fujimoto ◆【License】CC-BY-SA-3.0 〕
Pythonでは、if 文はコードブロックを伴う。もし if 文が真と評価されれば、インデントされたブロックが実行され、そうでなければelseブロックが(もしあれば)実行される。式の周りに括弧がないないことに注意しよう。
In Python, an if statement is followed by a code block. If the if expression evaluates to true, the indented block is executed, otherwise it falls to the else block (if any). Note the lack of parentheses around the expression.〔【出典】"Dive Into Python 3" by Mark Pilgrim ◆【和訳】Fukada & Fujimoto ◆【License】CC-BY-SA-3.0 〕
Python uses carriage returns to separate statements and a colon and indentation to separate code blocks. C++ and Java use semicolons to separate statements and curly braces to separate code blocks.〔【出典】"Dive Into Python 3" by Mark Pilgrim ◆【和訳】Fukada & Fujimoto ◆【License】CC-BY-SA-3.0 〕
Code blocks are defined by their indentation. By "code block," I mean functions, if statements, for loops, while loops, and so forth. Indenting starts a block and unindenting ends it. There are no explicit braces, brackets, or keywords. This means that whitespace is significant, and must be consistent. In this example, the function code is indented four spaces. It doesn't need to be four spaces, it just needs to be consistent. The first line that is not indented marks the end of the function.〔【出典】"Dive Into Python 3" by Mark Pilgrim ◆【和訳】Fukada & Fujimoto ◆【License】CC-BY-SA-3.0 〕