Formatting and Syntax

Python Indentation

Python uses indentation to define a block of code. Indentation means that there is a space at the beginning of the line - similar to the space at the beginning of a paragraph in English. In python, you can make a single level indent by either using four spaces or the tab key once. An example is show below:

if 1==1: 
#### 4 spaces or 1 tab spot
    print("This is indent level 1")
    if 2==2:
######## 8 spaces or 2 tab spots
        print("This is indent level 2")

Comments

#This is a comment. 

You might have seen statements starting with '#' such as the one above in our code. These statements are called comments. To write a comment in Python, just make sure to start your statement with a hashtag like in the example above.

Comments can be used whenever you feel there is a need to explain your code or certain steps you take to approach a problem in your program. We recommend using comments to keep track of your code, because in some instances you might come back to it after a month and not remember what your code does. Comments can be especially useful when other people look at your code so that they do not have to decipher an entire code block to know what it does.

Last updated