Appearance
Quick Revision: Programming from First Principles
Use this page for a fast sweep through all 14 modules. For deeper reading, open Web Resources.
Module 1: Data Types and Collections
- Python values have types such as
int,float,bool,str,list,tuple,set, anddict. - Use
intfor whole numbers,floatfor decimal values, andboolfor yes/no logic. - Lists are ordered and changeable.
- Tuples are ordered and fixed.
- Sets remove duplicates.
- Dictionaries map keys to values.
Module 2: Higher-Order Functions
- Functions are values in Python.
map,filter,sorted(key=...), andfunctools.reduceare common higher-order patterns.lambdacreates a small anonymous function.- Main benefit: reuse and compact code.
Module 3: Standard Constructs
- Indentation defines blocks.
if/elif/elsechooses between paths.forandwhilerepeat work.- Comprehensions build new collections clearly.
matchcan inspect shape in modern Python.
Module 4: Iteration and Lazy Evaluation
- Python evaluates most expressions eagerly.
- Generators and iterators let you produce values on demand.
yieldcreates lazy sequences.- Lazy evaluation helps when data is large or infinite-like.
Module 5: Anonymous Functions and Lambda Calculus
lambdacreates a short anonymous function.- Function application means calling a function with arguments.
- Beta reduction means substituting inputs into a function body.
- Lambda calculus is the formal foundation behind function thinking.
Module 6: First-Class Functions
- Functions can be stored, passed, and returned like data.
- Closures remember values from the surrounding scope.
- This makes callbacks and factories easy to write.
Module 7: Type Discipline
- Python is dynamically typed, but type hints can improve checking.
- Runtime errors happen when the wrong kind of value is used.
isinstanceand type checkers help reduce mistakes.- Type safety means fewer invalid operations.
Module 8: Type Hints and Inference
- Type hints describe expected types.
- Editors and type checkers can infer local types from code.
mypyand Pyright help spot mismatches early.- Inference reduces repeated annotation work.
Module 9: User-Defined Types
classdefines a custom type.@dataclassis useful for simple data containers.Enumis good for fixed named choices.- Custom types model domain concepts clearly.
Module 10: Concrete Types
- Concrete types are specific, fully known types.
- Examples:
int,float,bool,str, and a specific class such asStudent. AnyandTypeVarare not concrete.- Concrete types are useful when the value shape is fixed.
Module 11: Recursion
- A recursive function calls itself on a smaller input.
- Every recursive function needs a base case.
- Structural recursion follows the shape of the data.
- Python has a recursion limit, so deep recursion needs care.
Module 12: Operational Semantics
- Operational semantics explains step-by-step execution.
- Expressions are evaluated in a fixed order.
- Function calls create new stack frames.
- Side effects and exceptions matter in Python execution.
Module 13: Protocols and Shared Behavior
- Python uses duck typing: if it behaves correctly, it fits.
abc.ABCandtyping.Protocoldescribe shared behavior.- Special methods like
__len__and__eq__provide common operations. - Interfaces help code work across many types.
Module 14: Polymorphism
- One function can work with many types.
- Type variables support parametric polymorphism.
- Operator overloading and protocols support shared behavior.
- Generic containers such as
list[T]are polymorphic.
One-Line Memory Map
text
Types -> Functions -> Constructs -> Iteration -> Types again -> Recursion -> Behavior -> PolymorphismWeb Revision Path
- Read the module note.
- Open the matching section in Web Resources.
- Compare one formal definition and one example.
- Return to this page for final recall.