Find more articles in our new Python Knowledge Base

Indentation contains tabs

Per the PEP 8 Style Guide, all Python code should be consistently indented with 4 spaces for each level of indentation, not tabs.

Anti-pattern

The following code uses tabs for indentation. Python code should be indented with four spaces for each level of indentation.

def print_hello_world():
    # indented with tab
    print("Hello, World!")
def print_goodbye_world():
    # indented with tab
    print("Goodbye, World!")

Best practice

Consistently indent with spaces

All Python code should be consistently indented with 4 spaces.

def print_hello_world():
    # indented with 4 spaces
    print("Hello, World!")
def print_goodbye_world():
    # indented with 4 spaces
    print("Goodbye, World!")

Status