Format Python with consistent four-space indentation and readable line breaks.
The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.
Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.
Python tokens are indented from colon-delimited suites while strings, comments, brackets, and continuation lines are preserved. Formatting changes layout without executing code.
def greet(name):
if name:
print(f'Hello {name}')
else:
print('Hello World')
def greet(name):
if name:
print(f'Hello {name}')
else:
print('Hello World')
Pre-commit hooks, notebook exports, and code reviews format Python.