Python Fundamentals: Values, Expressions & Control Flow
GATE 2027 DA core
“Read and reason about small Python programs, including types, branches, loops, and common expression traps.”
1.Start here: a small, traceable language
§ 1.1.Prerequisites: basic arithmetic, comparison, and the idea that a variable names a value. No C experience is required. Before proceeding, check that you can evaluate 3 * (4 + 1), distinguish assignment from equality, and follow a three-step sequence of updates.
Python executes statements in order. Names refer to objects; assignment binds a name, while an operation such as items.append(x) mutates the list object. Values have types: int, float, bool, str, and None are common built-ins. Python integers have arbitrary precision, while floating-point values use finite precision.
A branch chooses a block; a for loop iterates over an iterable, and a while loop repeats while a condition is true. Blocks are marked by indentation. range(n) produces 0 through n−1, which makes it convenient for zero-based indexing.
Worked trace: floor division and range
sum(i // 2 for i in range(-2, 3)).range(-2, 3) yields −2, −1, 0, 1, 2; the upper endpoint 3 is excluded.
The terms are −1, −1, 0, 0, 1. In particular, −1 // 2 is −1, not 0.
Add the five terms: −1 − 1 + 0 + 0 + 1 = −1.
Check your understanding
What values are produced by `list(range(2, 8, 2))`?
What is `-7 // 3` in Python?
One-minute revision
“Trace values in order; preserve types, mutation, branch conditions, and exclusive range endpoints.”
- •range(stop): 0, …, stop−1
- •a // b = floor(a / b)
- •a % b is the remainder paired with Python floor division
- •Negative floor division
- •Mutable list aliasing
- •
isversus== - •
breakaffects loopelse
Primary Academic References & Exam Sources
Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.
Curated for clarity, rigorous numerical solving, and semester excellence:
Visual thinkers who want to see each algorithm step animated clearly.
GATE-targeted coverage with step-by-step GATE PYQ walkthroughs.