Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Python dictionary | values()

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

values() is an inbuilt method in Python programming language that returns a view object. The view object contains the values of the dictionary, as a list. If you use the type() method on the return value, you get “dict_values object”. It must be cast to obtain the actual list.

Syntax:

dictionary_name.values()

Parameters:
There are no parameters

Returns:

returns a list of all the values available in a given dictionary.
the values have been stored in a reversed manner.

Error:

As we are not passing any parameters there
is no scope for any error.

Code#1:




# Python3 program for illustration 
# of values() method of dictionary 
  
  
# numerical values
dictionary = {"raj": 2, "striver": 3, "vikram": 4}
print(dictionary.values())  
  
  
# string values
dictionary = {"geeks": "5", "for": "3", "Geeks": "5"}
print(dictionary.values())  

Output:

dict_values([2, 3, 4])
dict_values(['5', '3', '5'])

Practical Application:
Given name and salary, return the total salary of all employees.

Code#2:




# Python3 program for illustration 
# of values() method in finding total salary
  
  
# stores name and corresponding salaries
salary = {"raj" : 50000, "striver" : 60000, "vikram" : 5000
  
# stores the salaries only
list1 = salary.values() 
print(sum(list1))  # prints the sum of all salaries

Output:

115000

My Personal Notes arrow_drop_up
Last Updated : 22 Nov, 2021
Like Article
Save Article
Similar Reads
Related Tutorials