Join Regular Classroom : Visit ClassroomTech

values() method in Python Dictionary

It is a method in python that returns a view object which contains of all the values of the dictionary in a list.

Syntax:

dictionary.values()

Don’t know what is keys method in Python? Read: keys() method in Python Dictionary

Example 1:

s = {0:"CodeWindow", 1:"India", 2:"News"}
x = s.values()
print(x)

Output:

dict_values([‘CodeWindow’, ‘India’, ‘News’])

Explanation:

Here it returned a view object all the values of the dictionary in a list.

Example 2:

s = {"site":"CodeWindow", "country":"India", "type":"News", "platform":"IT"}
x = s.values()
print(x)

Output:

dict_values([‘CodeWindow’, ‘India’, ‘News’, ‘IT’])

Explanation:

Here it returned a view object all the values of the dictionary in a list.


You Missed

Also Checkout