The Python dictionary values function returns a view object of the list of available values in a dictionary (total items). The view object updates whenever there is a change in the original dictionary. For instance, if we update or delete a key-value pair in a dictionary, the values() function view object automatically updates.
In this section, we discuss how to use the dictionary values() function, and the syntax of the method is
dictionary_name.values()
Python Dictionary values example
The values function returns the list of total items available in a given one. The code below prints the numbers in the emp and employ. Please refer to the Dictionary in this language to understand. For more information, please refer to the dictionary methods article.
emp = {'name': 'Kevin', 'age': 25 , 'job': 'HR', 'Sal': 725000}
print("Dictionary: ", emp)
# Print
print("Dictionary Values: ", emp.values())
# Creating an Empty
employ = {}
print("\nDictionary: ", employ)
# Print
print("Dictionary Values: ", employ.values())

In this program, we are going to insert a new one into the dict and print that number. Next, we updated and displayed the updated number.
To get only dictionary keys, use the keys() function, and for all key-value pairs as a tuple, use the dict.items() method. However, to access a specific key value, use the dict.get() method.
emp = {'name': 'John', 'age': 25 , 'job': 'HR'}
print(emp)
print(emp.values())
emp['age'] = 27
print(emp.values())
emp['Sal'] = 725000
print(emp.values())
{'name': 'John', 'age': 25, 'job': 'HR'}
dict_values(['John', 25, 'HR'])
dict_values(['John', 27, 'HR'])
dict_values(['John', 27, 'HR', 725000])
Python dictionary values to list
By default, if we use the built-in values() function, it returns a view object of type dict_values. We must use the list() function to convert that object to a list of dictionary values.
emp = {"name": "Tracy","age": 25, "city": "New York"}
print(emp.values())
val = list(emp.values())
print(val)
dict_values(['Tracy', 25, 'New York'])
['Tracy', 25, 'New York']
How to iterate over dict.values()?
We can use the for loop to iterate over the dictionary values view object returned by the dict.values() function. Inside the loop, use the print() function to display the dictionary values.
emp = {"name": "Tracy","age": 25, "city": "New York"}
for val in emp.values():
print(val)
Tracy
25
New York
How to check if values exist in the dictionary values?
We can use the combination of the if else statement and a dict.values() function to check whether the given value exists in the dictionary or not.
emp = {"name": "Tracy","age": 25, "city": "New York"}
if "Tracy" in emp.values():
print("User exists")
else:
print("User does not exist")
User exists
How to find the Python dictionary values sum and max?
In the Python programming language, there are common built-in sum() and max() functions that we can use on any iterable. In the following example, we use the sum() function to find the sum of all dictionary values. Next, use the max() function to get the maximum value within a dictionary.
fruits = {"Apple": 50, "Banana": 100, "Cherry": 200, "Orange": 95}
total = sum(fruits.values())
print(total)
largest = max(fruits.values())
print(largest)
445
200
What is the difference between Python dict.values and dict.keys()?
The dict.keys() function returns the view object of total keys in a dictionary. On the other hand, the dict.values() function returns the view object of total values in a given dictionary. We can use the list () function to convert the view objects into a list and perform other operations.
fruits = {"Apple": 50, "Banana": 100, "Cherry": 200, "Orange": 95}
k = fruits.keys()
print(k)
print(list(k))
v = fruits.values()
print(v)
print(list(v))
dict_keys(['Apple', 'Banana', 'Cherry', 'Orange'])
['Apple', 'Banana', 'Cherry', 'Orange']
dict_values([50, 100, 200, 95])
[50, 100, 200, 95]