Module 02 - Core Python Syntax
Reading time: ~8 minutes | Level: Foundation Gateway
Here is a question most Python developers cannot answer correctly:
a = 256
b = 256
print(a is b) # True or False?
c = 257
d = 257
print(c is d) # True or False?
The first prints True. The second prints False.
Same code structure. Different behavior. One silent CPython optimization separates them.
If you cannot explain why - this module is exactly where you need to be.
What This Module Covers
This is the foundation module. Not foundation in the sense of "easy." Foundation in the sense of load-bearing.
Every advanced Python concept - decorators, generators, async, metaclasses, memory management - rests on what you learn here.
By the end of this module, you will have the mental models that let you predict Python's behavior, not just observe it.
Module Topics
01 - Installing Python Properly
Not a beginner tutorial. A systems engineering guide.
You will learn why pyenv exists, what PATH actually controls, why system Python must never be modified, how virtual environments work at the filesystem level, and how to make your environment fully reproducible.
Key concepts: pyenv, venv, PATH, pip, requirements.txt, interpreter discovery
02 - Understanding the REPL
The REPL is not a toy. It is Python's interactive execution engine - the purest interface to the interpreter.
You will understand Read-Eval-Print-Loop as a cycle, how bytecode is compiled even in interactive mode, how state persists, and why professional engineers use the REPL daily for debugging and exploration.
Key concepts: REPL cycle, expression vs statement, _ variable, IPython, stateful sessions
03 - Execution Model in Practice
What happens between python script.py and your first line of code running?
This lesson breaks the abstraction: tokenization, AST construction, bytecode compilation, the Python Virtual Machine, stack frames, heap allocation, and the __main__ guard.
Key concepts: dis module, bytecode, PVM, stack frames, __name__, import system, .pyc files
04 - Variables and Assignment Deep Dive (Already Complete)
Python variables are not storage boxes. They are names bound to objects on the heap.
This lesson (already written to full engineering depth) covers name binding, reassignment vs mutation, identity vs equality, copy semantics, and the default mutable argument trap.
05 - Primitive Data Types
int, float, bool, NoneType - not primitives in the C sense. They are full objects with overhead, methods, and CPython-specific behavior.
You will understand arbitrary-precision integers, IEEE-754 float limitations, bool as a subclass of int, and why None is a singleton.
Key concepts: sys.getsizeof, integer overflow, float precision, Decimal, math.isclose
06 - Strings: Internals and Immutability
Strings power APIs, logs, NLP, networking, and parsing. Engineers do not just use strings - they understand them.
This lesson covers Unicode vs bytes, UTF-8 encoding, immutability guarantees, string interning, f-strings, performance of concatenation vs join(), and common bugs.
Key concepts: str vs bytes, encode()/decode(), f-strings, casefold(), repr(), join()
07 - Type Casting and Coercion
int(), float(), str(), bool() - these look simple. The behavior is not.
You will understand explicit vs implicit conversion, numeric type promotion rules, why "0" is truthy but 0 is falsy, and how coercion causes real production bugs in environment variable parsing and API responses.
Key concepts: type promotion, truthiness coercion, __int__, __bool__, __str__, ValueError
08 - Operators: Arithmetic, Comparison, Logical
Operators are not symbols. They are method calls, evaluation rules, and execution controllers.
This lesson covers all Python operators at depth: floor division behavior with negatives, chained comparisons, short-circuit evaluation, augmented assignment, and operator overloading via dunder methods.
Key concepts: // vs /, and/or return values, chained comparisons, __add__, __eq__, augmented assignment
09 - Bitwise Operators Deep Dive
Binary operations are not academic. They appear in permission systems, ML frameworks, network protocols, embedded systems, and performance-critical code.
You will understand &, |, ^, ~, <<, >> with two's complement semantics, bit masking, flag systems, and where NumPy and PyTorch use them internally.
Key concepts: bit masking, flags, two's complement, bin(), format(), shift multiplication tricks
10 - Input and Output
print() is a wrapper around sys.stdout. input() is a blocking read from sys.stdin.
This lesson covers stream internals, buffering, encoding mismatches, flush, sep/end parameters, stderr vs stdout, and why print() should never appear in production systems.
Key concepts: sys.stdout, sys.stderr, buffering, flush=True, encoding, logging module
11 - Comments vs Docstrings
Comments disappear at compile time. Docstrings become part of the object - accessible at runtime via __doc__.
You will understand PEP 257 conventions, Google/NumPy/reST docstring styles, help() integration, doctest, and when to write which.
Key concepts: __doc__, help(), PEP 257, Google style, doctest, python -O
12 - Everything is an Object
This is Python's most important architectural truth.
Integers, functions, classes, modules - all objects. All have identity, type, and behavior. This enables decorators, higher-order functions, dynamic dispatch, and the entire framework ecosystem.
Key concepts: id(), type(), dir(), __class__, callable(), first-class functions
13 - Type System and Dynamic Typing
"Dynamically typed" means more than "no type declarations." It means types live on objects, not variables, and all type checking happens at runtime.
This lesson covers duck typing, structural vs nominal typing, isinstance vs type(), type hints (PEP 484), and the EAFP vs LBYL philosophical divide.
Key concepts: duck typing, isinstance, typing module, mypy, runtime dispatch, gradual typing
14 - Truthiness and Falsiness
Every Python object has a boolean value. Not just True and False. Every object.
You will understand the boolean protocol (__bool__ → __len__ → True), all falsy values, how logical operators return objects (not booleans), and the traps that cause silent bugs.
Key concepts: __bool__, __len__, falsy values, short-circuit, None vs empty vs 0
15 - Identity vs Equality
is vs == is not a style choice. They answer different questions about reality.
This lesson connects memory model to comparison semantics: id(), __eq__, singleton objects, and why using is for numeric comparison passes tests and breaks production.
Key concepts: is, ==, id(), __eq__, singletons, None check
16 - Interning and Object Caching
CPython caches integers from -5 to 256. It may intern string literals. It reuses the empty tuple singleton.
This lesson explains why, proves it with code, and explains exactly when you can and cannot rely on this behavior.
Key concepts: integer cache, sys.intern(), string interning, empty tuple singleton, implementation vs language spec
Module Projects
Four projects that force you to apply this knowledge under real constraints:
| Project | Core Skill |
|---|---|
| Interactive Calculator CLI | Operators, type casting, input parsing, error handling |
| CLI Unit Converter | Structured data modeling, conversion logic, float precision |
| Binary Logic Playground | Bitwise operations, two's complement, visual output |
| Type Inspector Tool | Runtime introspection, object model, identity/equality |
Projects are not exercises. They are environments designed to surface the behaviors you have studied.
Prerequisites for This Module
- You can run Python from a terminal
- You know what a variable is (conceptually)
- You have written at least one Python program
No prior engineering depth required. That is what this module builds.
How to Use This Module
Read each lesson in order. The mental models build on each other.
Variables (lesson 04) depends on understanding execution (lesson 03). Truthiness (lesson 14) depends on understanding the object model (lesson 12). Interning (lesson 16) depends on identity (lesson 15).
After every lesson: open the REPL and verify the concepts yourself. Reading is not learning. Verifying is learning.
The Engineering Standard
This module is written for engineers, not beginners.
Every topic goes beneath the surface. Every code example reveals behavior that surprises most developers. Every section connects to real production systems, AI/ML libraries, or engineering practice.
By the end, you will not just know Python syntax.
You will understand why Python behaves the way it does - and that understanding will make you a better engineer regardless of what language you work in next.
