Python Quick Reference
Essential syntax and built-in functions at a glance
Data Types
• int, float, complex – numeric types
• str – immutable text: "hello", 'world'
• list – mutable sequence: [1, 2, 3]
• tuple – immutable sequence: (1, 2, 3)
• dict – key-value pairs: {"a": 1}
• set – unique values: {1, 2, 3}
• bool – True / False
Control Flow
• if x > 0: / elif x == 0: / else:
• for item in iterable:
• while condition:
• break – exit loop early
• continue – skip to next iteration
• pass – do nothing placeholder
Useful Built-ins
• len(x) – length of a sequence
• range(start, stop, step) – integer range
• enumerate(iterable) – index + value pairs
• zip(a, b) – pair two iterables
• sorted(iterable, reverse=False)
• map(func, iterable) / filter(func, iterable)
• any(iterable) / all(iterable)
String Methods
• .strip() .lstrip() .rstrip() – trim whitespace
• .split(sep) / [Link](list)
• .upper() / .lower() / .title()
• .replace(old, new)
• .startswith(s) / .endswith(s)
• f"Hello {name}" – f-string formatting
List Comprehensions
• [x*2 for x in range(10)]
• [x for x in nums if x > 0]
• {k: v for k, v in [Link]()} – dict comp
• {x for x in lst} – set comp