← 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 is the purpose of the `__init__` method in a Python class?

    Answer: Initialize a new object's attributes

    `__init__` is the constructor that runs automatically when a new instance is created, setting initial attribute values.

  2. What does `dict.get('key', 'default')` return if 'key' is not in the dictionary?

    Answer: 'default'

    `dict.get(key, default)` returns the default value instead of raising a KeyError when the key is missing.

  3. Which Python built-in function returns the length of an object?

    Answer: len()

    `len()` returns the number of items in a sequence, collection, or other container object.

  4. What does a `try/except/finally` block guarantee about the `finally` clause?

    Answer: It always runs regardless of exceptions

    The `finally` block always executes whether an exception was raised or not, making it ideal for cleanup.

  5. What is the result of `'hello'[::-1]` in Python?

    Answer: 'olleh'

    The slice `[::-1]` reverses the string by stepping backward through all characters.

  6. Which statement about Python's `set` type is correct?

    Answer: Sets are unordered and contain unique elements

    Python sets are unordered collections that automatically enforce uniqueness — duplicates are silently ignored.

  7. What does the `zip()` function do in Python?

    Answer: Combine two or more iterables element-by-element into tuples

    `zip()` pairs up elements from multiple iterables and returns an iterator of tuples.