Tutorial Study Image

Python values()

The values() function in python returns the view object of all the available values in the dictionary as in the form of a list. Actually, it provides a dynamic view of dictionary values.


dictionary.values()
 

values() Parameters:

values() method doesn't take any parameters. The result values of this method are stored in a reversed manner.

values() Return Value

Any changes in the dictionary also reflect the values of the view object.

Input Return Value
dictionary view object

Examples of values() method in Python

Example 1: How to get all values from the dictionary in Python


# random fruits dictionary
fruits = { 'mango': 5, 'banana': 4, 'strawberry': 3 }
 

Output:


dict_values([5, 3, 4])

Example 2: How values() works when dictionary is modified?


# random fruits dictionary
fruits = { 'mango': 5, 'banana': 4, 'strawberry': 3 }

keyvalues = fruits.values()
print('Original list:', keyvalues)

# delete an item from dictionary
del[fruits['mango']]
print('Updated list:', keyvalues)
 

Output:


Original list: dict_values([5, 3, 4])
Updated list: dict_values([3, 4])