Python Lists, Tuples, Sets u0026 Dictionaries: Core Concepts Quiz Quiz

  1. List mutability

    Which Python collection is mutable and allows you to change its items after creation?

    1. Arrangement
    2. Dictionary
    3. List
    4. Tuple
    5. Set
  2. Tuples and parentheses

    Which of these code snippets correctly creates a tuple containing the values 4 and 7?

    1. [4, 7]
    2. (4, 7)
    3. u003C4, 7u003E
    4. (4; 7)
    5. {4, 7}
  3. Set uniqueness property

    If you create a set with the values {1, 2, 2, 3}, how many unique items will it contain?

    1. 1
    2. 4
    3. 3
    4. 5
    5. 2
  4. Dictionary key types

    Which of the following cannot be used as a key in a Python dictionary?

    1. A boolean
    2. An integer
    3. A tuple
    4. A string
    5. A list
  5. Accessing list elements

    How do you access the first element of a list named my_list?

    1. my_list.0
    2. my_list(0)
    3. my_list[0]
    4. my_list{0}
    5. my_list|0|
  6. Tuple immutability

    What happens if you try to change an item in a tuple after it is created?

    1. The tuple becomes a list
    2. A TypeError is raised
    3. The item is changed
    4. A ValueError is raised
    5. The item is ignored
  7. Adding items to a set

    Which method is used to add a single element to a Python set?

    1. append()
    2. ad()
    3. add()
    4. extend()
    5. insert()
  8. Dictionary retrieval method

    Which dictionary method is best for retrieving a value by key with a fallback if the key is missing?

    1. extract()
    2. fetch()
    3. get()
    4. find()
    5. pull()
  9. Removing from a list

    Which method removes the first occurrence of a value from a Python list?

    1. pop()
    2. erase()
    3. remove()
    4. discard()
    5. delete()
  10. Empty set creation

    Which of the following creates an empty set in Python?

    1. emptyset()
    2. {}
    3. ()
    4. set()
    5. []
  11. Dictionary item iteration

    What method can you use to iterate over both the keys and values of a dictionary?

    1. keys()
    2. elements()
    3. pairs()
    4. values()
    5. items()
  12. List comprehension basics

    What does [x for x in range(3)] create?

    1. A dictionary {0:0, 1:1, 2:2}
    2. A list [0, 1, 2]
    3. A set {0, 1, 2}
    4. A string '012'
    5. A tuple (0, 1, 2)
  13. Set method for combination

    Which set method returns a new set containing all items from both sets without duplicates?

    1. merge()
    2. combine()
    3. update()
    4. union()
    5. join()
  14. Dictionary mutability

    Are Python dictionaries mutable, and what does that mean?

    1. Yes, but only the lengths can change
    2. No, you cannot modify a dictionary after it is made
    3. Yes, but you can only change the keys
    4. No, but values can be changed
    5. Yes, you can add, remove, or change items after creation
  15. Performance: membership test

    Which collection offers the fastest average-time membership test (e.g., x in collection) for large collections?

    1. Array
    2. Set
    3. Sequence
    4. Tuple
    5. List