Pythonic code values readability, small reusable functions, sensible naming, and style consistency guided by PEP 8.
- Readability counts
- Names should reveal intent
- Idiomatic code is clear before it is clever
CPython compiles source to bytecode, may cache it in `.pyc` files, and then runs that bytecode on the Python virtual machine.
- Compilation step creates bytecode
- Import can cache `.pyc`
- Virtual machine executes bytecode instructions
Python includes arithmetic, comparison, logical, membership, identity, bitwise, and assignment operators.
- Operator families solve different problems
- `is` is identity, `==` is equality
- Bitwise operators are lower-level but still interview-relevant
Python is a high-level, readable, batteries-included language that supports procedural, object-oriented, and functional styles.
- Readable syntax
- Large standard library
- Works well for scripting, backend, data, and automation
Python ships with iteration helpers that make common loops shorter and clearer when used carefully.
- enumerate pairs index with value
- zip walks iterables together
- any and all summarize boolean checks
Python regular expressions help when patterns are simpler to express declaratively than with manual loops.
- `search` scans anywhere, `match` starts at the front
- Groups capture subpatterns
- `sub` performs replacements
The REPL is great for quick experiments, while scripts are how you save repeatable program logic.
- REPL is interactive
- Scripts are file-based
- Both still run through the interpreter
Python functions can return any object, often pack multiple results into a tuple, and may document intent through annotations and docstrings.
- Multiple returns are tuple packing
- Annotations describe intent, not runtime enforcement by default
- Docstrings explain usage and behavior
Sets support fast membership checks and mathematical operations like union, intersection, difference, and symmetric difference.
- Sets remove duplicates
- frozenset is immutable and hashable
- Set algebra is useful in filtering and comparison problems
A shallow copy copies the outer container; a deep copy recursively copies nested objects too.
- Shallow shares nested refs
- Deep duplicates nested refs
- copy and deepcopy from copy module
A single underscore is a convention for internal use, double underscore triggers name mangling in classes, and dunder names are reserved for language-defined behavior.
- Single underscore is social, not enforced
- Double underscore rewrites names to reduce accidental clashes
- Dunder names should not be invented casually
Python's standard library covers operating-system access, math, dates, iteration helpers, subprocesses, logging, regular expressions, and typing support.
- Know the purpose of common modules
- Reach for stdlib before extra dependencies
- Interviews reward practical module selection