Running Python

Run real Python in this page, print something, and understand the one rule that makes Python look the way it does.

01of 24
≈ 10Min read
5Parts

This is not a simulation

The editor below runs CPython 3.14, the same interpreter you would install, compiled to WebAssembly and started inside a sandboxed frame. sys.version is real, the standard library is real, and when you make a mistake the traceback is the one you would get on your own machine.

It costs about 12 MB the first time it starts, then your browser keeps it. Every lesson in this course boots it as the page opens, so it is usually warm by the time you press Run.

Print

print is a function — parentheses are not optional, which is the single most visible difference from Python 2. It takes any number of arguments, joins them with sep (a space by default) and ends with end (a newline by default).

There is no semicolon at the end of a line. You may write one, and nobody does.

py
print("Hello.")
print("Two", "arguments", "are", "joined", "by", "spaces")
print("no newline", end="")
print(1 + 1, type(1 + 1))

Indentation is the syntax

Four spaces per level, never tabs — PEP 8 says so and every Python tool assumes it. Mixing tabs and spaces in one file is an error by design, because the interpreter cannot know what you meant.

a colon opens a block; the indent is the block
if temperature > 30:
    print("hot")
    print("still inside the if")
print("outside again")

Names, and no declarations

Assignment creates the name. There is no declaration keyword and no type annotation required — the name refers to an object, and the object carries the type.

Python has no const: TOTAL in capitals is a message to the next reader, and the interpreter will let anyone reassign it.

py
count = 3            # no let, no const, no type
count = "three"      # and nothing stops this
TOTAL = 100          # capitals mean "do not reassign" — a convention, not a rule
first_name = "Ada"   # snake_case for names, always

Comments and docstrings

Python has no block comment. Three quotes give you a string that spans lines, and people use one as a comment — but in the first position of a module, class or function it is a docstring, which is a real, readable attribute rather than text the parser throws away.

py
# a comment runs to the end of the line

def area(width, height):
    """Return the area of a rectangle.

    The first string in a function is its docstring — help() reads it,
    tools read it, and it is not a comment: it is an attribute of the function.
    """
    return width * height

print(area.__doc__.splitlines()[0])

Practice