Computer Science, asked by faritha6543, 8 months ago

What will be the output of the following Python code snippet? d={"john":40,"peter":45} d["john"]

Answers

Answered by mad210203
4

Output:

40

Explanation:

  • In python we have a dictionary data type.
  • A dictionary is a collection which is unordered collection of data values.
  • Dictionary contains keys and their respective values.
  • With the help of keys, their values can be accessed.

Program:

d={"john":40,"peter":45}

print(d["john"])

Let us understand the program.

#Here, we are declaring and initializing a dictionary.

d={"john":40,"peter":45}

#This statement is used print the value associated with john.

#The value associated with john is 40.

#So, it will print 40.

print(d["john"])

Refer the attached image for the output.

Attachments:
Similar questions