Skip to content

Python core: check what you know

Already know some Python? Answer these 13 questions, about 7 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 13 topics it checks
  1. Classes: inheritance, MRO, super() and dunder methods
  2. @property, class methods and static methods
  3. Dataclasses
  4. Iterators and generators
  5. Closures
  6. Decorators, with arguments and functools.wraps
  7. Context managers
  8. collections, itertools and functools
  9. Type hints
  10. is vs ==, shallow vs deep copy
  11. Logging
  12. pytest basics
  13. pandas basics: DataFrames, filtering, groupby and merge
  1. Question 1 of 13 · Predict the outputWhat does this print?
    class A:
        def hi(self):
            return "A"
    class B(A):
        def hi(self):
            return "B" + super().hi()
    class C(A):
        def hi(self):
            return "C" + super().hi()
    class D(B, C):
        pass
    print(D().hi())
    
  2. Question 2 of 13 · Multiple choiceCode all over the app writes item.price = x. You need to reject negative prices. What keeps every caller unchanged?
  3. Question 3 of 13 · Spot the bugWhy does Python refuse to create this class?
    from dataclasses import dataclass
    
    @dataclass
    class Cart:
        owner: str
        items: list = []
    
  4. Question 4 of 13 · Predict the outputWhat does this print?
    nums = (n * n for n in range(4))
    print(sum(nums), sum(nums))
    
  5. Question 5 of 13 · Predict the outputWhat does this print?
    fns = []
    for i in range(3):
        fns.append(lambda: i)
    print([f() for f in fns])
    
  6. Question 6 of 13 · Spot the bugAfter adding @timed, every decorated function returns None. Why?
    def timed(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            start = time.perf_counter()
            func(*args, **kwargs)
            print(time.perf_counter() - start)
        return wrapper
    
  7. Question 7 of 13 · Multiple choiceIn a @contextmanager function, where must the clean-up code go so it runs even when the with block raises?
  8. Question 8 of 13 · Multiple choiceYou need the 3 most common words in a list of a million words. What is shortest and fast?
  9. Question 9 of 13 · Predict the outputWhat happens when this runs?
    def double(x: int) -> int:
        return x * 2
    
    print(double("ab"))
    
  10. Question 10 of 13 · Predict the outputWhat does this print?
    a = [[0], [0]]
    b = a.copy()
    b[0].append(1)
    print(a, a == b, a is b)
    
  11. Question 11 of 13 · Multiple choiceWhich line belongs in a library module?
  12. Question 12 of 13 · Spot the bugThis test passes even when parse("") raises nothing. Why?
    def test_empty():
        try:
            parse("")
            assert False, "should raise"
        except Exception:
            pass
    
  13. Question 13 of 13 · Multiple choiceA pandas report loops with iterrows over 3 million rows and takes 20 minutes. What is the fix for total amount per region?

Answered 0 of 13.