- No prior programming experience is required
- Ability to create, save, and edit plain-text files is helpful
Learn with diagrams, code, systems and practical examples.
Python Programming Foundations
Learn Python through practical examples covering syntax, data structures, functions, files, and problem solving.
Know where you are going before you begin
A useful course should make the starting point, destination, and learning method clear—not make you guess from a list of links.
Python Dictionaries & Hash Maps
Deepen the course material with today’s complete tutorial package: first-principles teaching, speaking-first interview practice, and a timed 25-question Online Test.
Inside this course
Move through the material in order unless a prerequisite or practice link gives you a better reason to branch.
Continue with purpose
These are curated relationships from the SubjectVision learning graph. Each recommendation should answer why it is useful next rather than merely adding another link.
Course interview practice
Use these as short execution and debugging drills after the course. Predict the program state before answering, name the data-model or control-flow choice that matters, and explain the smallest change that fixes the behavior rather than reciting Python syntax.
01 · IntermediateA program reads age = input("Age: ") and then fails on age + 1. What happened, and where should the fix live?Answer out loud before opening the expected response.
Practice
Answer out loud before opening the expected response.
Expected answer
input() returns text, so age is a string and cannot be added directly to an integer. Convert and validate the value at the input boundary, for example with int(age), while handling invalid user input explicitly.
Why this answer works
The interview signal is whether you trace types through execution instead of guessing at the error. External input begins as untrusted text. Converting close to the boundary makes the program’s internal assumptions clearer, but conversion can fail, so robust code decides what to do with blank, malformed, or out-of-range values rather than scattering casts throughout later calculations.
02 · IntermediateTwo variables point to the same list, one variable appends an item, and both variables now appear changed. Why, and how would you make an independent list?Answer out loud before opening the expected response.
Practice
Answer out loud before opening the expected response.
Expected answer
Assignment binds another name to the same mutable list object; it does not clone the list. Create a separate shallow copy with list(existing) or existing.copy() when independent top-level mutation is required.
Why this answer works
This tests the difference between names and objects. The useful trace is to ask whether the operation creates a new object or mutates an existing one. A shallow copy is enough for a flat list, but nested mutable objects can still be shared, so a strong answer distinguishes shallow copying from the rarer need for a deliberate deep copy.
03 · IntermediateYou repeatedly need to ask whether a user ID has already been seen, but the current code scans a growing list every time. What would you change and why?Answer out loud before opening the expected response.
Practice
Answer out loud before opening the expected response.
Expected answer
Use a set when the requirement is unique membership rather than positional order. Set membership is typically constant expected time, while scanning a list grows linearly with the number of stored IDs.
Why this answer works
The important skill is matching the data structure to the operation. Lists are valuable when order, duplicates, or indexing matter; sets express uniqueness and fast membership directly. A strong answer also notes that changing structures can change ordering semantics and that performance claims should be understood as expected behavior rather than a universal guarantee.
04 · IntermediateAn if/elif chain checks score >= 60 before score >= 90, so a score of 95 is labeled “pass” instead of “excellent.” Why does this happen?Answer out loud before opening the expected response.
Practice
Answer out loud before opening the expected response.
Expected answer
Python evaluates the chain from top to bottom and stops at the first true branch. The broad >= 60 condition captures 95 before the more specific >= 90 condition is reached, so the conditions should be ordered or rewritten to reflect the intended ranges.
Why this answer works
This is an execution-tracing question. Do not read every branch as if it were independently evaluated. For mutually exclusive ranges, trace the first condition that becomes true and ask whether earlier conditions accidentally contain later cases. Reordering from most specific/highest threshold downward is one clear fix when that matches the domain rules.
05 · SeniorThree parts of a program repeat the same price-after-discount calculation with slightly different variable names. What refactoring would you propose?Answer out loud before opening the expected response.
Practice
Answer out loud before opening the expected response.
Expected answer
Extract the business rule into a function with explicit inputs and a returned result, then have each caller supply its values. Keep input/output or unrelated state outside the function unless those effects are part of its responsibility.
Why this answer works
Interviewers are looking for more than “use a function.” A good boundary names one responsibility, makes dependencies visible as parameters, returns a useful value, and can be tested independently. Copy-pasted formulas drift over time; centralizing the rule reduces inconsistent fixes while avoiding a giant function that mixes calculation, user interaction, and unrelated side effects.
Test what you can apply
Five course-specific questions covering the most important ideas in Python Programming Foundations. Commit to an answer before reading the explanation.
A program runs age = input("Age: ") and the user types 12. What happens if the next line is print(age + 1) without any conversion?
input() returns a string such as "12". Adding that string to the integer 1 mixes incompatible types, so the program raises a TypeError. Converting first with int(age) makes numeric addition explicit and also makes invalid numeric input something the program can handle deliberately.
Review this topic →You need to record product IDs seen in a data feed and quickly answer “have we already seen this ID?” while storing each ID only once. Which built-in structure best matches that requirement?
A set models unique membership directly and provides efficient membership testing for this use case. A list can contain duplicates and generally requires scanning for membership, while tuples and strings do not match the requirement as naturally.
Review this topic →A checkout program needs to look up the price for a product by SKU, such as prices["A17"]. Which structure most directly represents that relationship?
A dictionary represents a key-to-value relationship, so the SKU can be used directly to retrieve its price. A set does not associate one value with another, and tuples or ranges would force the program to invent positional meaning instead of using the SKU itself as the lookup key.
Review this topic →Consider: temperature = 31; if temperature > 35: print("hot"); elif temperature > 25: print("warm"); else: print("cool"). What is printed?
31 is not greater than 35, so the first branch is skipped. It is greater than 25, so the elif branch prints "warm" and the remaining branches are not evaluated. An if/elif/else chain selects one matching branch, not every true-looking label.
Review this topic →A program repeats the same tax calculation in five places, and a rule change requires editing all five copies. Which refactor most directly reduces that maintenance risk?
A function gives the calculation one implementation point with explicit inputs and reusable behavior, so a rule change can be made once and tested in one place. Global state increases coupling, and changing data structures or wrapping duplicated code in conditions does not remove the duplication.
Review this topic →Review any missed answers, then continue while the concepts are fresh enough to connect.