Find more articles in our new Python Knowledge Base

Indentation contains mixed spaces and tabs

Per the PEP 8 Style Guide, all Python code should be consistently indented with 4 spaces, never tabs.

Anti-pattern

The following code mixes spaces and tabs for indentation. The print("Hello, World!") statement is indented with a tab. The print("Goodybye, World!") statement is indented with 4 spaces.

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

Solutions

Consistently indent with spaces

All Python code should be consistently indented with 4 spaces.

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

Status