← Technology quizzes

Free practice quiz

Python Gotchas and Rules

15 questions Technology Grades 9-12

The question sheet

Reveal any answer as you study
  1. When is an empty list default argument created?

    • On import
    • At definition
    • Never
    • Each call
    Reveal answer

    Answer: At definition

  2. Calling add_item(1) then add_item(2) returns [1, 2] on the second call.

    • True
    • False
    Reveal answer

    Answer: True

  3. To avoid the mutable default trap, use ____ as the default value.

    • {}
    • None
    • []
    • 0
    Reveal answer

    Answer: None

  4. The mutable default problem applies to strings and tuples too.

    • True
    • False
    Reveal answer

    Answer: False

  5. What does [10, 20, 30, 40][1:3] return?

    • [20, 30]
    • [30, 40]
    • [20, 30, 40]
    • [10, 20]
    Reveal answer

    Answer: [20, 30]

  6. What does [10, 20, 30, 40][-1] give?

    • 30
    • 10
    • -1
    • 40
    Reveal answer

    Answer: 40

  7. The slice ____ returns a list in reverse order.

    • [::2]
    • [::-1]
    • [1:3]
    • [:-1]
    Reveal answer

    Answer: [::-1]

  8. Slicing modifies the original list in place.

    • True
    • False
    Reveal answer

    Answer: False

  9. An out-of-range slice raises an error in Python.

    • True
    • False
    Reveal answer

    Answer: False

  10. Which value is NOT falsy in Python?

    • ""
    • 0
    • "hi"
    • []
    Reveal answer

    Answer: "hi"

  11. The operators and/or return one of their ____ rather than a strict boolean.

    • operands
    • errors
    • indices
    • types
    Reveal answer

    Answer: operands

  12. What does the LEGB rule stand for?

    • Local Extern Global Base
    • List Enum Global Byte
    • Level Enclosing Group Block
    • Local Enclosing Global Built-in
    Reveal answer

    Answer: Local Enclosing Global Built-in

  13. To assign to a global variable inside a function, use the ____ keyword.

    • extern
    • static
    • global
    • nonlocal
    Reveal answer

    Answer: global

  14. Which keyword modifies an enclosing function's variable?

    • local
    • enclose
    • global
    • nonlocal
    Reveal answer

    Answer: nonlocal

  15. Assigning inside a function without 'global' changes the outer variable.

    • True
    • False
    Reveal answer

    Answer: False

Play the whole quiz inside a game Answers stay hidden while you play

Make your own — free

Turn any notes into a game in under a minute. Free to start.

Make a quiz