Interactive Reference Guide

Python 3 Syntax Cheat Sheet

Quick syntax reference for Python 3. Every snippet can be executed and tested directly in the ZenCompiler sandbox with one click.

List Comprehensions & Slicing

Concise expressions for creating and slicing lists.

Run in Python Sandbox
# List comprehension with condition
evens = [x for x in range(10) if x % 2 == 0]

# List slicing [start:stop:step]
nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
reversed_nums = nums[::-1]
sub_list = nums[2:7:2]  # [2, 4, 6]

print("Evens:", evens)
print("Reversed:", reversed_nums)

Dictionary Operations

Key-value mapping manipulation and comprehensions.

Run in Python Sandbox
user = {"name": "Alice", "role": "engineer", "level": 3}

# Safe get with default value
team = user.get("team", "Core Platform")

# Dictionary comprehension
squares = {x: x**2 for x in range(5)}

# Iterating keys and values
for key, val in user.items():
    print(f"{key}: {val}")

Lambda, Map & Filter

Anonymous inline functions and functional helpers.

Run in Python Sandbox
# Lambda function (x, y) -> x * y
multiply = lambda x, y: x * y

numbers = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x**2, numbers))
greater_than_2 = list(filter(lambda x: x > 2, numbers))

print("Squared:", squared)
print("Filtered:", greater_than_2)