โ† All Python Flashcard Decks

Core Syntax 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 Core Syntax flashcards as text
  1. What will `x = [1, 2, 3]; print(x[-1])` output?

    Answer: 3

    Negative indexing in Python counts from the end; `-1` refers to the last element, which is `3`.

  2. Which of the following correctly unpacks a tuple `t = (10, 20, 30)` into three variables?

    Answer: a, b, c = t

    Tuple unpacking with `a, b, c = t` assigns each element to a corresponding variable in order.

  3. What is the purpose of the `pass` statement in Python?

    Answer: Acts as a placeholder where syntax requires a statement

    `pass` is a null operation used as a syntactic placeholder when a block is required but no action is needed.

  4. What does `print(10 % 3)` output?

    Answer: 1

    The `%` modulus operator returns the remainder of divison; `10 % 3` is `1` because `10 = 3*3 + 1`.

  5. Which of the following is the correct way to write a single-line conditional expression (ternary) in Python?

    Answer: x = 1 if cond else 2

    Python's ternary expression uses the syntax `value_if_true if condition else value_if_false`.

  6. What is the output of `print(2 ** 3 ** 2)`?

    Answer: 512

    The `**` exponentiation operator is right-associative, so `2 ** 3 ** 2` = `2 ** 9` = `512`.

  7. Which built-in function returns the number of items in a sequence?

    Answer: len()

    `len()` is the built-in function that returns the number of items in a sequence or collection.