โ† 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 is the output of `print(not not True)`?

    Answer: True

    Applying `not` twice negates the value twice, returning the original `True`.

  2. Which of the following creates an empty dictionary in Python?

    Answer: {}

    An empty pair of curly braces `{}` creates an empty dictionary; `set()` must be used for an empty set.

  3. What does `'hello'[1:4]` evaluate to?

    Answer: 'ell'

    Slice `[1:4]` extracts characters at indices 1, 2, and 3 (stop index is exclusive), yielding `'ell'`.

  4. In Python, what does the `global` keyword do inside a function?

    Answer: Allows modification of a variable defined in the global scope

    The `global` keyword tells Python that a name refers to the global scope, allowing assignment to that global variable inside a function.

  5. What is the result of `list(range(2, 10, 3))`?

    Answer: [2, 5, 8]

    `range(2, 10, 3)` starts at 2 and steps by 3, producing 2, 5, 8 (stops before 10).

  6. Which of the following correctly checks if a key exists in a dictionary `d`?

    Answer: 'k' in d

    The `in` operator checks for key membership in a dictionary; `has_key()` was removed in Python 3.

  7. What is the difference between `is` and `==` in Python?

    Answer: `is` checks identity (same object); `==` checks equality (same value)

    `is` tests whether two variables point to the exact same object in memory, while `==` tests whether their values are equal.