Python Syntax References

Python syntax quick reference for common tasks, from the official Python documentation. Every item below is clearly marked as a shortcut, command, or syntax reference.

Most Useful Python Syntax References

PythonSyntax

Print to Console

Code example
print("Hello")

Prints a value to standard output.

Learn More
PythonSyntax

Define a Function

Code example
def greet(name): return f"Hi {name}"

Defines a reusable function.

Learn More
PythonSyntax

If / Elif / Else

Code example
if x > 0: ... elif x == 0: ... else: ...

Runs code depending on a condition.

Learn More
PythonSyntax

For Loop

Code example
for item in items: print(item)

Loops over each item in a sequence.

Learn More
PythonSyntax

Create a List

Code example
nums = [1, 2, 3]

Creates an ordered, changeable list.

Learn More
PythonSyntax

Append to List

Code example
nums.append(4)

Adds an item to the end of a list.

Learn More
PythonSyntax

Length of a Sequence

Code example
len(items)

Returns the number of items.

Learn More
PythonSyntax

Create a Dictionary

Code example
d = {"a": 1, "b": 2}

Creates key-value pairs.

Learn More

More Python Syntax References

Frequently Asked Questions

What does this Python syntax reference cover?

It covers 32 common Python patterns and examples, including Print to Console, Define a Function, If / Elif / Else, For Loop, Create a List.

Can I copy the Python examples?

Yes. Each reference page includes a copyable code example.

What affects these Python examples?

Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.