![]() |
VOOZH | about |
dict.values() method in Python returns a view object that contains all the values of the dictionary. This object updates automatically when the dictionary changes and is useful when only values are needed.
Example: In this example, values() is used to get all values from a dictionary.
dict_values(['Python', 'Java', 'C++'])
Explanation: d.values() returns a view object containing all values of dictionary d.
dict_name.values()
Example 1: Here, the code retrieves all dictionary values and prints them using a loop. This helps access each value individually.
10 20 30
Explanation: d.values() returns all values and for v in d.values() accesses each value one by one.
Example 2: In this example, the values view object is converted into a list. This allows indexing and other list operations.
[1, 2, 3]
Explanation: list(d.values()) converts the view object into a list.
Example 3: Here, the code checks whether a specific value exists in the dictionary.
True
Explanation: d.values() provides all values and 200 in d.values() checks if value exists.