โ† All Python Flashcard Decks

Data Types and Variables 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 Data Types and Variables flashcards as text
  1. What is the result of `type(lambda: None)`?

    Answer:

    Lambda expressions create anonymous functions; their type is `function`.

  2. How do you check if variable `x` is of type `str` using the recommended approach?

    Answer: isinstance(x, str)

    `isinstance(x, str)` is preferred because it also handles subclasses of `str`.

  3. What does Python's dynamic typing mean?

    Answer: Variable types are determined and can change at runtime

    In Python, type is associated with the object, not the variable, and the same name can point to objects of different types at runtime.

  4. What is the value of `int(3.9)`?

    Answer: 3

    `int()` truncates toward zero, so `int(3.9)` is `3`, not 4.

  5. Which Python keyword is used to annotate a variable's type without assigning it?

    Answer: :

    PEP 526 syntax `x: int` annotates the variable type using a colon without assignment.

  6. What is the output of `str(True)`?

    Answer: 'True'

    `str(True)` returns the string `'True'` with a capital T.

  7. Which of the following correctly unpacks values into multiple variables?

    Answer: a, b = (1, 2)

    Tuple unpacking `a, b = (1, 2)` assigns 1 to `a` and 2 to `b` simultaneously.