TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python Dictionary values() method with Examples

Python Dictionary values() method with Examples on clear(), copy(), fromkeys(), get(), len(), items(), keys(), setdefault(), values(), ascii(), enumerate(), update(), pop() etc.

<< Back to PYTHON

Python Dictionary values() Method

Python values() method is used to collect all the values from a dictionary. It does not take any parameter and returns a dictionary of values. It returns an empty dictionary if the dictionary has no value. The syntax and examples of this method are given below.

Signature

values()

Parameters

No Parameter

Return

It returns a dictionary of values.

Let?s see some examples of values() method to understand it?s functionality.

Python Dictionary values() Method Example 1

It is a simple example which returns all the values from the dictionary. An example is given below.

# Python dictionary values() Method
# Creating a dictionary
einventory = {'Fan': 200, 'Bulb':150, 'Led':1000}
# Calling function
stock = einventory.values()
# Displaying result
print("Stock available",einventory)

Output:

Stock available {'Fan': 200, 'Bulb': 150, 'Led': 1000}

Python Dictionary values() Method Example 2

If the dictionary is already empty, this method also returns an empty dictionary except any error or exception. See an example below.

# Python dictionary values() Method
# Creating a dictionary
einventory = {}
# Calling function
stock = einventory.values()
# Displaying result
print("Stock available",einventory)

Output:

Stock available {}

Python Dictionary values() Method Example 3

This example uses various methods to get information about dictionary such as length, keys etc.

# Python dictionary values() Method
# Creating a dictionary
einventory = {'Fan': 200, 'Bulb':150, 'Led':1000}
# Applying functions
length = len(einventory)
print("Total number of values:",length)
keys = einventory.keys()
print("All the Keys:",keys)
item = einventory.items()
print("Items:",einventory)
p = einventory.popitem()
print("Deleted items:",p)
stock = einventory.values()
print("Stock available",einventory)

Output:

Total number of values: 3
All the Keys: dict_keys(['Fan', 'Bulb', 'Led'])
Items: {'Fan': 200, 'Bulb': 150, 'Led': 1000}
Deleted items: ('Led', 1000)
Stock available {'Fan': 200, 'Bulb': 150}

Next TopicPython Dictionary




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf