Skip to content

Python foundations: check what you know

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
  1. Install Python and run your first file
  2. Variables, print() and input()
  3. Decisions and loops: if, for and while
  4. Numbers, strings, slicing and f-strings
  5. Your first functions: def and return
  6. list, tuple, dict and set, and what each operation costs
  7. How Python runs your code
  8. Names, objects and references
  9. Mutable and immutable objects
  10. Functions, *args, **kwargs and the mutable-default trap
  11. Scope and the LEGB rule
  12. Comprehensions
  13. Exceptions
  14. Files and pathlib
  15. Modules, packages and virtual environments
  16. Git for everyday work: commit, branch, merge, rebase, pull requests
  1. Question 1 of 15 · Predict the outputYou run python app.py. Line 2 has a typo in a name. What happens?
    print("start")
    pritn("end")
    
  2. Question 2 of 15 · Predict the outputThe user types 30. What happens?
    age = input("Age? ")
    print(age + 1)
    
  3. Question 3 of 15 · Predict the outputWhat does this print?
    word = "python"
    print(f"{word[1:4]}-{len(word)}")
    
  4. Question 4 of 15 · Predict the outputWhat does this print?
    total = 0
    for n in range(1, 5):
        if n % 2 == 0:
            continue
        total += n
    print(total)
    
  5. Question 5 of 15 · Predict the outputWhat does this print?
    def area(w, h):
        w * h
    
    print(area(3, 4))
    
  6. Question 6 of 15 · Multiple choiceYou will check thousands of times whether a user id is in a group of a million ids. Which container makes each check fastest?
  7. Question 7 of 15 · Multiple choiceEach container holds a million items. Which of these takes about a million steps, not one?
  8. Question 8 of 15 · Predict the outputWhat does this print?
    a = [1, 2]
    b = a
    b.append(3)
    print(a)
    
  9. Question 9 of 15 · Predict the outputWhat does this print?
    def add(item, bag=[]):
        bag.append(item)
        return bag
    
    add("a")
    print(add("b"))
    
  10. Question 10 of 15 · Predict the outputWhat does this print?
    def show(first, *args, **kwargs):
        print(first, args, kwargs)
    
    show(1, 2, 3, color="red")
    
  11. Question 11 of 15 · Predict the outputWhat happens when bump() runs?
    count = 0
    
    def bump():
        count += 1
    
    bump()
    
  12. Question 12 of 15 · Predict the outputWhat does this print?
    print([x * x for x in range(6) if x % 2])
    
  13. Question 13 of 15 · Predict the outputnotes.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))
    
  14. Question 14 of 15 · Multiple choiceYou made a virtual environment in .venv, installed requests, and now make your first git commit. What should the commit hold?
  15. Question 15 of 15 · Multiple choiceYour 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?

Answered 0 of 15.