values() is an inbuilt method in Python programming language that returns a list of all the values available in a given dictionary.
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()) |
chevron_right
filter_none
Output:
dict_values([2, 3, 4]) dict_values(['5', '3'])
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 |
chevron_right
filter_none
Output:
115000
Recommended Posts:
- Python - Append Dictionary Keys and Values ( In order ) in dictionary
- Python - Filter dictionary values in heterogenous dictionary
- Python - Test for Even values dictionary values lists
- Python - Extract Unique values dictionary values
- Python - Remove duplicate values across Dictionary Values
- Python - Dictionary Values Mean
- Python - Unique Values of Key in Dictionary
- Python | Check for None values in given dictionary
- Python - Associated Values Frequencies in Dictionary
- Python - Check if all values are K in dictionary
- Python | Initialize dictionary with None values
- Python - Smallest K values in Dictionary
- Python | Selective key values in dictionary
- Python - Keys associated with Values in Dictionary
- Python | Max/Min of tuple dictionary values
- Python - Frequencies of Values in a Dictionary`
- Python | Check if all values are 0 in dictionary
- Python | N largest values in dictionary
- Python - Mapping key values to Dictionary
- Python - Test if all Values are Same in Dictionary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : bhaumik10

