Skip to main content
← Python Study Guide

Unit 1 · Foundational

Python Foundations

Variables, types, operators, and control flow. Python hides type declarations, which makes the language friendly to start and makes type errors appear later than they would elsewhere.

What a strong answer looks like

A strong Unit 1 answer names the type of each value before reasoning about the result, because dynamic typing means the type is not written down anywhere.

Topics in this unit

1

Variables and Dynamic Typing

Know

A Python variable is a name bound to an object, and the type belongs to the object rather than to the name. Rebinding a name to a different type is legal.

Apply

Track what each name currently refers to, especially after reassignment inside a branch.

Watch out

Assuming a name keeps its original type. Nothing prevents it changing, and the error surfaces far from the cause.

Study move

Rebind one name to three different types and print the type after each.

2

Numeric Types and Division

Know

The two division operators differ: one always produces a float, the other floors toward negative infinity. Mixing int and float promotes to float.

Apply

Choose floor division when counting whole groups and true division when a fraction is meant.

Watch out

Floor division of a negative number rounds toward negative infinity, not toward zero.

Study move

Evaluate both division operators on a negative operand and explain the difference.

3

Strings and Formatting

Know

Strings are immutable sequences. Formatted string literals interpolate expressions directly and are the clearest way to build output.

Apply

Build messages with formatted literals rather than repeated concatenation.

Watch out

Expecting a string method to modify in place. Every one returns a new string.

Study move

Rewrite a concatenated message as a formatted literal and compare readability.

4

Conditionals and Loops

Know

Indentation defines blocks, so structure is enforced by layout. A for loop iterates over a sequence directly rather than over indices.

Apply

Iterate over items when the index is not needed, and enumerate when it is.

Watch out

Looping over a range of indices out of habit, which is longer and easier to get wrong than iterating directly.

Study move

Rewrite an index-based loop as a direct iteration and then as an enumeration.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • Tracking the current type of every name
  • Choosing the right division operator deliberately
  • Iterating over items rather than indices

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • Input handling. Interactive input is emphasised in beginner sections and skipped where work is file-driven.
  • Type hints. Introduced early in some courses as documentation.

Mastery checklist

  • State the type of a value after reassignment.
  • Predict the result of both division operators, including on negatives.
  • Build output with a formatted string literal.
  • Write a loop that iterates directly over a sequence.

Check yourself

  • Why does a Python name have no type of its own?
  • How does floor division behave on a negative operand?
  • Why does calling a string method never change the original?

Modeling drill

Write a program that converts a total number of minutes into hours and minutes and prints a formatted sentence, then test it on 0, 59, and 60.

Dynamic typingBindingFloor divisionImmutabilityf-stringIndentation block