โ† All Python Flashcard Decks

Python Flashcards

7 cards from real Python practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Python flashcards as text
  1. What does the `global` keyword do inside a Python function?

    Answer: Declares that a variable name refers to the module-level global variable

    `global x` inside a function tells Python to use and potentially modify the `x` defined at the module level rather than creating a local one.

  2. Which built-in function applies a function to every item in an iterable and returns a map object?

    Answer: map()

    `map(func, iterable)` applies `func` to each element and returns an iterator of the results.

  3. What is the output of `type(3.0)` in Python?

    Answer:

    `3.0` is a floating-point literal, so `type(3.0)` returns ``.

  4. What does `'%s has %d items' % ('cart', 5)` produce?

    Answer: 'cart has 5 items'

    The `%` formatting operator substitutes `%s` with the string and `%d` with the integer from the tuple.

  5. Which Python data structure guarantees FIFO (first-in, first-out) ordering?

    Answer: collections.deque used as a queue

    `collections.deque` with `append()` and `popleft()` provides O(1) FIFO queue operations.

  6. What is the purpose of `if __name__ == '__main__':` in a Python script?

    Answer: Both B and C

    This guard ensures the indented block runs only when the script is executed directly, not when imported, effectively marking the entry point.

  7. What does `sorted()` return compared to `list.sort()`?

    Answer: `sorted()` returns a new list; `list.sort()` sorts in place and returns None

    `sorted()` always returns a new sorted list, while `list.sort()` modifies the list in place and returns `None`.

Written and edited by , founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy