This language's greatest selling feature for me is its formatting. It takes very little work to put a script together, and because of its simplistic formatting requirements, you reduce chances of errors. For experienced programmers, the loathsome ;
and {}
signs will no longer impact your development time due to syntax errors.
The most important thing to remember in Python is indentation. Python uses indents to show where logic blocks are changed. So, if you are writing a simple print
script as mentioned earlier, you are not necessarily going to see this, but if you are writing an if
statement, you will. See the following example, which prints the statement previously mentioned here:
#!/usr/bin/env python execute=True if execute != False: print("Do you want to play a game? ")
More details on how this script operates and executes can be found in the Compound statements section of this chapter. The following example prints the statement to the screen if execute is not False
. This indentation signifies that the function separates it from the rest of the global code.
There are two ways of creating an indent: either through spaces or through tabs. Four spaces are equivalent to one tab; the indentation in the preceding code signifies the separation of the codes logic from the rest of the global code. The reason for this is that spaces translate better when moved from one system type to another, which again makes your code more portable.