Skills101
← Python — Advanced

Python Advanced — Test 1

15 questions22 minPass: 60%+40 XP on first passFree sample test

15 questions · 22 minutes · advanced level, with an explanation for every answer.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    Which method makes len(obj) work on your own class?

  2. Question 2

    What is the output?

    funcs = [lambda: i for i in range(3)]
    print([f() for f in funcs])
    
  3. Question 3

    What is the output?

    print(sorted([("b", 2), ("a", 2), ("c", 1)], key=lambda t: (-t[1], t[0])))
    
  4. Question 4

    What is the output?

    def gen():
        for i in range(3):
            yield i * 10
    
    g = gen()
    print(next(g), next(g), list(g), list(g))
    
  5. Question 5

    What does a generator expression (x*x for x in range(10**9)) use compared to a list comprehension?

  6. Question 6

    What is the output?

    from functools import lru_cache
    calls = 0
    @lru_cache(maxsize=None)
    def fib(n):
        global calls
        calls += 1
        return n if n < 2 else fib(n - 1) + fib(n - 2)
    print(fib(30), calls)
    
  7. Question 7

    Which is the most Pythonic way to read a large file line by line?

  8. Question 8

    What is the output?

    a = [[0] * 3] * 2
    a[0][0] = 9
    b = [[0] * 3 for _ in range(2)]
    b[0][0] = 9
    print(a, b)
    
  9. Question 9

    What is the output?

    def deco(fn):
        def wrap(*a):
            return fn(*a) * 2
        return wrap
    
    @deco
    def add(x, y):
        return x + y
    
    print(add(3, 4), add.__name__)
    
  10. Question 10

    What is the output?

    x = [1, 2, 3]
    y = x
    x += [4]
    z = x
    x = x + [5]
    print(y, z is y, len(x))
    
  11. Question 11

    Why do CPU-heavy Python threads usually not run faster on many cores?

  12. Question 12

    What is the output?

    class A:
        def hello(self): return "A"
    class B(A):
        def hello(self): return "B" + super().hello()
    class C(A):
        def hello(self): return "C" + super().hello()
    class D(B, C):
        pass
    print(D().hello())
    
  13. Question 13

    What is the output?

    x = 10
    def outer():
        x = 20
        def inner():
            nonlocal x
            x += 1
            return x
        inner()
        return x
    print(outer(), x)
    
  14. Question 14

    What is the difference between copy.copy(x) and copy.deepcopy(x) for a list of lists?

  15. Question 15

    What is the output?

    class Counter:
        count = 0
        def __init__(self):
            Counter.count += 1
            self.count = Counter.count * 10
    
    a, b = Counter(), Counter()
    print(a.count, b.count, Counter.count)
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →