Dictionaries and Sets Interview Questions

    Question 1: Python Dictionaries - Creation

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

    Question 2: Python Dictionaries - Accessing Values

    What will be the output?

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

    Question 3: Python Dictionaries - get() Method

    What is the output?

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

    Question 4: Python Dictionaries - Keys

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

    Question 5: Python Sets - Creation

    Which of the following correctly creates a set?

    Question 6: Python Sets - Uniqueness

    What will this code output?

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

    Question 7: Python Dictionaries - Updating Values

    What will be the output?

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

    Question 8: Python Sets - Union Operation

    What is the output?

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

    Question 9: Python Sets - Membership

    What will this code print?

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

    Question 10: Python Dictionaries - Iterating Keys

    What will this code output?

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