Python Dictionary values

Python values Dictionary function returns the list of available values in a dictionary (total values). In this section, we discuss how to use this Dictionary values function. The syntax of the dictionary values function is

dictionary_name.values()

Python Dictionary values Example

The dictionary values function to return the list of total values available in a given dictionary. The code below prints the values in the emp dictionary and employ.

TIP: Please refer to the Dictionary to understand Python Dictionaries.

# Python Dictionary values Example

emp = {'name': 'Kevin', 'age': 25 , 'job': 'HR', 'Sal': 725000}
print("Dictionary: ", emp)

# Print Values
print("Dictionary Values: ", emp.values())

# Creating an Empty Dictionary
employ = {}
print("\nDictionary: ", employ)

# Print Values
print("Dictionary Values: ", employ.values())
Python Dictionary Values 1

values in a Dictionary Example 2

In this program, we are going to insert a new value to the dictionary and print values. Next, we updated a value and displayed the dictionary updated values.

# Python Dictionary values Example

emp = {'name': 'John', 'age': 25 , 'job': 'HR'}
print("Dictionary: ", emp)

# Print Values
print("Dictionary Values: ", emp.values())

emp['age'] = 27
print("\nDictionary Values: ", emp.values())

# Print Values
emp['Sal'] = 725000
print("\nDictionary Values: ", emp.values())

Dictionary values function output

Dictionary:  {'name': 'John', 'age': 25, 'job': 'HR'}
Dictionary Values:  dict_values(['John', 25, 'HR'])

Dictionary Values:  dict_values(['John', 27, 'HR'])

Dictionary Values:  dict_values(['John', 27, 'HR', 725000])