
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program to Multiply All the Items in a Dictionary
When it is required to multiply all the elements in a dictionary, the key values in the dictionary are iterated over. The key is multiplied with the previous key, and output is determined.
The dictionary is a set of key-value pairs.
Example
Below is a demonstration for the same −
my_dict = {'Jane':99,'Will':54,'Mark':-3} my_result = 2 for key in my_dict: my_result = my_result * my_dict[key] print("The reuslt of multiplying keys in a dictionary is : ") print(my_result)
Output
The reuslt of multiplying keys in a dictionary is : -32076
Explanation
- A dictionary is defined.
- A variable is assigned a certain value.
- The ‘key’ in the dictionary is iterated over.
- In every step, this key is multiplied with the variable previously assigned.
- This value is assigned to the same variable itself.
- This is displayed on the console as the output.
- Related Articles
- Python program to find the sum of all items in a dictionary
- Python program to multiply all numbers in the list?
- Dictionary Methods in Python (cmp(), len(), items()…)
- Java Program to select all the items in a JList
- C# program to multiply all numbers in the list
- Delete items from dictionary while iterating in Python
- How to print all the keys of a dictionary in Python
- How to print all the values of a dictionary in Python?
- How to remove all the elements of a dictionary in Python?
- Python Program To Create A Dictionary With A Dictionary Literal
- Python - Get items in sorted order from given dictionary
- Program to count average of all special values for all permutations of a list of items in Python
- Python Program To Find The Largest Element In A Dictionary
- How to access nested Python dictionary items via a list of keys?
- Swift Program to Remove all the elements from Dictionary

Advertisements