Python Dictionary values() Method

Returns a list of the values in the dictionary. The returned object is a dict_values object, which in Python is a "view object" - it cannot be changed, only viewed, iterated over, or converted to a list or other collection.

Syntax

Python
dictionary.values()

Example

Python
fish = {
    'guppy': 2,
    'zebra' : 5,
    'betta': 10
}

print(fish.values())

Output

dict_values([2, 5, 10])

Notes

Often a dict_values object is converted to a list which makes it easy to sum values that are a number value type or perform other calculations.

Example

Python
fish = {
    'guppy': 2,
    'zebra' : 5,
    'betta': 10
}

countsOfFish = list(fish.values())
print(countsOfFish)
total = sum(countsOfFish)
print(f'I have a total of {total} different kinds of fish.')

Output

[2, 5, 10]
I have a total of 17 different kinds of fish.