▶ Try It Yourself

Python Syntax

Python syntax is clean, readable, and easy to understand.

Execute Python Syntax

Python syntax can be executed by writing directly in the command line, or by creating a .py file. On this site, you can run it live with the ▶ Try it button.

Example
print("Hello, World!")

Indentation

Indentation refers to the spaces at the beginning of a code line. In Python, indentation is required — it indicates a block of code. Other languages often use curly-braces for this.

Example — Correct indentation
if 5 > 2: print("Five is greater than two!")
⚠️ Warning Python will raise an IndentationError if you skip the indentation. The number of spaces is up to you, but it must be consistent within the same block. 4 spaces is the standard.

Python Variables

Python has no command for declaring a variable. It is created the moment you first assign a value to it:

Example
x = 5 y = "Hello, World!" print(x) print(y)

Comments

Python has commenting capability for in-code documentation. Comments start with a #:

Example — Comment
# This is a comment print("Hello, World!")

Multi Line Statements

Python normally uses one line per statement. You can use a backslash \ to extend to the next line:

Example — Multi-line
total = 1 + \ 2 + \ 3 print(total)