Python dictionary Method - values()

www.igift‮di‬ea.com

The values() method is a built-in method in Python dictionaries that returns a view object that contains the values of the dictionary.

Syntax:

dictionary.values()

Example:

# create a dictionary
my_dict = {'apple': 2, 'banana': 4, 'orange': 6}

# get the values of the dictionary
values = my_dict.values()

print(values) # dict_values([2, 4, 6])

The returned view object is a dynamic view of the dictionary's values. Any changes made to the dictionary will be reflected in the view object and vice versa. The view object can be converted into a list or a tuple using the list() or tuple() method, respectively.