Which of the following statements create a dictionary?d = {}d = {“john”:40, “peter”:45}d = {40:”john”, 45:”peter”}All of the mentione
Question
Which of the following statements create a dictionary?d = {}d = {“john”:40, “peter”:45}d = {40:”john”, 45:”peter”}All of the mentione
Solution
All of the mentioned statements create a dictionary in Python.
d = {}creates an empty dictionary.d = {"john":40, "peter":45}creates a dictionary with two key-value pairs, where "john" and "peter" are the keys and 40 and 45 are their respective values.d = {40:"john", 45:"peter"}also creates a dictionary with two key-value pairs, but here 40 and 45 are the keys and "john" and "peter" are their respective values.
In Python, dictionaries are created by placing a comma-separated list of key:value pairs within braces {}, where key and value express an association between the two.
Similar Questions
Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?d.size()len(d)size(d)d.len()
Which of the following is correct with respect to the above Python code?d={"a":3,"b":7}a dictionary d is created.a and b are the keys of dictionary d.3 and 7 are the values of dictionary dAll of the above.
How do you initialize a dictionary?
How are dictionaries different from Lists?
1.Question 1What are the keys of the following dictionary: {"a":1,"b":2}1 point1,2"a","b"2.Question 2Consider the following Python Dictionary:Dict={"A":1,"B":"2","C":[3,3,3],"D":(4,4,4),'E':5,'F':6}What is the result of the following operation: Dict["D"]1 point(4, 4, 4)[3,3,3]1
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.