Already know some Python? Answer these 15 questions, about 8 minutes. Each topic you get fully right is marked Known on the Python roadmap , so you can skip it. Each one you miss is listed for you to study.
Don’t guess. Pick “I don’t know yet” when you’re not sure: a lucky guess would mark a topic Known that you still need to learn.
The 16 topics it checks Install Python and run your first file Variables, print() and input() Decisions and loops: if, for and while Numbers, strings, slicing and f-strings Your first functions: def and return list, tuple, dict and set, and what each operation costs How Python runs your code Names, objects and references Mutable and immutable objects Functions, *args, **kwargs and the mutable-default trap Scope and the LEGB rule Comprehensions Exceptions Files and pathlib Modules, packages and virtual environments Git for everyday work: commit, branch, merge, rebase, pull requests Question 1 of 15 · Predict the output You run python app.py. Line 2 has a typo in a name. What happens? print("start")
pritn("end")
Nothing prints. Python finds the typo before it runs anything. "start" prints, then Python stops with a NameError on line 2. Both lines print. Python skips line 2 and continues. I don’t know yet
Question 2 of 15 · Predict the output The user types 30. What happens? age = input("Age? ")
print(age + 1)
It prints 31. It prints 301. It stops with a TypeError. It prints age1. I don’t know yet
Question 3 of 15 · Predict the output What does this print? word = "python"
print(f"{word[1:4]}-{len(word)}")
yth-6 pyt-6 ytho-6 yth-5 I don’t know yet
Question 4 of 15 · Predict the output What does this print? total = 0
for n in range(1, 5):
if n % 2 == 0:
continue
total += n
print(total)
10 9 6 4 I don’t know yet
Question 5 of 15 · Predict the output What does this print? def area(w, h):
w * h
print(area(3, 4))
None 12 0 Nothing; it stops with an error. I don’t know yet
Question 6 of 15 · Multiple choice You will check thousands of times whether a user id is in a group of a million ids. Which container makes each check fastest? A list A tuple A string with the ids joined by commas A set I don’t know yet
Question 7 of 15 · Multiple choice Each container holds a million items. Which of these takes about a million steps, not one? prices[key] on a dict items.append(x) on a list items.insert(0, x) on a list seen.add(x) on a set I don’t know yet
Question 8 of 15 · Predict the output What does this print? a = [1, 2]
b = a
b.append(3)
print(a)
[1, 2] [1, 2, 3] [1, 2, [3]] Nothing; it stops with an error. I don’t know yet
Question 9 of 15 · Predict the output What does this print? def add(item, bag=[]):
bag.append(item)
return bag
add("a")
print(add("b"))
['b'] ['a'] [] ['a', 'b'] I don’t know yet
Question 10 of 15 · Predict the output What does this print? def show(first, *args, **kwargs):
print(first, args, kwargs)
show(1, 2, 3, color="red")
1 [2, 3] {'color': 'red'} 1 (2, 3) {'color': 'red'} 1 2 3 color=red (1, 2, 3) {'color': 'red'} I don’t know yet
Question 11 of 15 · Predict the output What happens when bump() runs? count = 0
def bump():
count += 1
bump()
count becomes 1. count stays 0 and nothing goes wrong. It stops with an UnboundLocalError. It makes a new global count of 1. I don’t know yet
Question 12 of 15 · Predict the output What does this print? print([x * x for x in range(6) if x % 2])
[1, 9, 25] [0, 4, 16] [1, 4, 9, 16, 25] [0, 1, 4, 9, 16, 25] I don’t know yet
Question 13 of 15 · Predict the output notes.txt does not exist. What happens? try:
with open("notes.txt") as f:
text = f.read()
except FileNotFoundError:
text = ""
finally:
print("done")
print(len(text))
It stops with a FileNotFoundError. It prints 0 only. It prints done, then 0. It prints done, then stops because text was never set. I don’t know yet
Question 14 of 15 · Multiple choice You made a virtual environment in .venv, installed requests, and now make your first git commit. What should the commit hold? requirements.txt (or pyproject.toml) with requests listed, and .venv in .gitignore. The .venv folder, so others get the same packages. Nothing about packages; git records what you installed. Both the .venv folder and requirements.txt. I don’t know yet
Question 15 of 15 · Multiple choice Your branch has 3 commits. Meanwhile a teammate added 2 commits to main. What is the difference between git merge main and git rebase main on your branch? merge deletes your 3 commits; rebase keeps them. They do the same thing; rebase is only faster. rebase sends your branch to GitHub; merge does not. merge adds a new commit that joins the two histories; rebase replays your 3 commits on top of main, as new commits. I don’t know yet
See my results Answered 0 of 15.