Dictionaries and Sets Interview Questions

    Question 1Python Dictionaries - Creation

    Which of the following is a valid way to create a dictionary?

    Question 2Python Dictionaries - Accessing Values

    What will be the output?

    d = {"x": 10, "y": 20} print(d["x"])

    Question 3Python Dictionaries - get() Method

    What is the output?

    d = {"x": 5} print(d.get("y", 0))

    Question 4Python Dictionaries - Keys

    Which of the following can be used as a dictionary key?

    Question 5Python Sets - Creation

    Which of the following correctly creates a set?

    Question 6Python Sets - Uniqueness

    What will this code output?

    s = {1, 2, 2, 3} print(s)

    Question 7Python Dictionaries - Updating Values

    What will be the output?

    d = {"a": 1} d["a"] = 5 print(d)

    Question 8Python Sets - Union Operation

    What is the output?

    s1 = {1, 2} s2 = {2, 3} print(s1 | s2)

    Question 9Python Sets - Membership

    What will this code print?

    s = {1, 2, 3} print(4 in s)

    Question 10Python Dictionaries - Iterating Keys

    What will this code output?

    d = {"a": 1, "b": 2} for key in d: print(key, end=" ")