>A Byte of Python

Single Statement Blocks

By now, you should have firmly understood that each block of statements is set apart from the rest by it's own indentation level. Well, this is true for the most part but it is not entirely true. If your block of statements contains only one single statement, then you can specify it on the same line of, say, a conditional statement or looping statement. The following example should make this clear.

>>> flag = True
>>> if flag: print 'Yes'
...
Yes
>>>
      

As we can see, the single statement is used in-place and not as a separate block. Although you can use this for making your program smaller, I strongly recommend that you do not use this short-cut method. One reason is that it will be much easier to add an extra statement if you are using proper indentation.