Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Condition Style Notes

Now that we have introduced compound statements, you may need to make an adjustment to your editor. Set your editor to use spaces instead of tabs. Most Python is typed using four spaces instead of the ASCII tab character (^I). Most editors can be set so that when you hit the Tab key on your keyboard, the editor inserts four spaces. IDLE is set up this way by default. A good editor will follow the indents so that once you indent, the next line is automatically indented.

We'll show the spaces explicitly as ␣'s in the following fragment.


This is has typical spacing for a piece of Python programming.

Note that the colon (:) immediately follows the condition. This is the usual format, and is consistent with the way natural languages (like English) are formatted.

These if statements can be collapsed to one-liners, in which case they would look like this:


It helps to limit your lines to 80 positions or less. You may need to break long statements with a \at the end of a line. Also, parenthesized expressions can be continued onto the next line without a \. Some programmers will put in extra ()'s just to make line breaks neat.

While spaces are used sparingly, they are always used to set off comparison operators and boolean operators. Other mathmatical operators may or may not be set off with spaces. This makes the comparisons stand out in an if statement or while statement.


This shows the space around the comparison, but not the other arithmetic operators.

  Published under the terms of the Open Publication License Design by Interspire