Knowee
Questions
Features
Study Tools

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 mentioned options?

🧐 Not the exact question you are looking for?Go ask a question

Solution

All of the mentioned statements create a dictionary in Python.

  1. d = {} creates an empty dictionary.
  2. 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.
  3. 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.

This problem has been solved

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}

Which of the following types are allowed for Python dictionary keys?Question 8Select one:a.dictionaryb.listc.list of dictionariesd.tuplee.All of the above

What is the output of the following code?dict1 = {"key1":1, "key2":2}dict2 = {"key2":2, "key1":1}print(dict1 == dict2)ATrueBFalseC0Dkey1

What would be the output of the following Python statement?Dict = {1:2, 3:4, 4:21, 5:6, 7:8}Dict[Dict[3]]

1/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.