Turn Messy Text into Structured Insights With AI. Join Greg Live:Β Dec 4th, 2024
Leverage
Glossary

Indent

Indentation in Python code

In python, the main way of formatting your code will be through indents. Indentation is tabs of white pass that β€˜group’ code together with each other.

For example, if you are using a for loop, every thing under the loop that is indented will be run with the loop. Once you go back to 0 indents, then python will know that you’re done with the loop code.

for i in range (5):
    print (i) # This line is indented once
    print ("This is my loop") # This line is also indented once
    print () # Finally, this line is also indented
print ("Ended Loop") # This line is back to 0 indents

Python Indents Code Sample

Let’s look at a quick code sample.

Link to code

On this page