English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The values() method returns a view object that displays a list of all values in the dictionary.
The syntax of values() is:
dictionary.values()
The values() method does not take any parameters.
The values() method returns a view object that displays a list of all values in the given dictionary.
# Dictionary sales = { 'apple': 2, 'orange': 3, 'grapes': 4 } print(sales.values())
When running the program, the output is:
dict_values([2, 4, 3])
# Dictionary sales = { 'apple': 2, 'orange': 3, 'grapes': 4 } values = sales.values() print('Original item:', values) # Delete an item from the dictionary del[sales['apple']] print('Updated item after update:', values)
When running the program, the output is:
Original item: dict_values([2, 4, 3]) Updated item after update: dict_values([4, 3])
The view object values itself does not return a list of sales item values, but returns a view of all values in the dictionary.
If the list is updated, the changes will be reflected in the view object itself, as shown in the above program.