QUESTION IMAGE
Question
what is the output of the following code?
my_dict = {\apple\: 1, \banana\: 2, \cherry\: 3}
print(my_dict\banana\)
\apple\
1
2
error
question 5
which method is used to add an item to the end of a list?
append()
insert()
extend()
add()
Step1: Dictionary key - value access
In Python, my_dict["banana"] accesses the value corresponding to the key "banana" in the dictionary my_dict.
Since the dictionary is defined as my_dict = {"apple": 1, "banana": 2, "cherry": 3}, when we access my_dict["banana"], we get the value 2.
Step2: List method functionality
append(): Adds a single element to the end of a list.insert(): Inserts an element at a specified position in the list.extend(): Adds all elements of an iterable (like another list) to the end of the list.add(): Not a standard list method in Python.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
For the first question: 2
For the second question: append()