Python | value method and keys method


Python | value method and keys method
value method

The values() method returns a view object that displays a list of all the values in the dictionary.

 user_info_value = user_info.values()
 
user_info_value=user_info.values()user_info_value
 = user_info.values()
print(user_info_value

 # OutPut = dict_values([‘pramod’, 22,’17691a05b9′,‘B-Tech’])

 
Python dictionary value () method The python values ​​() method is used to gather all values ​​from a dictionary. It takes no parameters and gives a dictionary of values. If the dictionary has no value then it returns an empty dictionary. The syntax and examples of this method are given below.
signature Values ​​() 
Parameter 
No parameters
The return 
It gives a dictionary of values.
See some examples of the values ​​() method to understand values? working capacity.
 Python dictionary value () method example
This is a simple example that returns all values ​​from the dictionary. An example is given below.
# Python dictionary value () method
 # Creating a Dictionary 
Inventory = {‘fan’: 200, ‘bulb’: 150, ‘LED’: 1000} 
# Calling function 
Share = einventory.values ​​() 
# Displaying Results Print (“stock available”, eventry)

Table of Contents

Output:

 Stock available {‘Fan’: 200, ‘Bulb’: 150, ‘LED’: 1000}
Python dictionary value () method example 2
 If the dictionary is already empty, this method also returns an empty dictionary except for any errors or exceptions. See an example below.
 # Python dictionary
 value () method 
# Creating a Dictionary 
Inventory = {} 
# Calling function
 Share = einventory.values ​​()
 # Displaying Results 
Print (“stock available”, eventry)
Output:
 stock available {}
Python dictionary value () method example 3
 This example uses various methods such as length, keys etc. to get information about the dictionary.
# Python dictionary value () method 
# Creating a Dictionary 
Inventory = {‘fan’: 200, ‘bulb’: 150, ‘LED’: 1000}
 # to work Length = Lane (inventory) 
Print (“Total number of values:”, length)
 Keys = einventory.keys ()
 Print (“All keys:”, key) 
Item = einventory.items ()
 Print (“item:”, einventory) 
p = einventory.popitem () 
Print (“Deleted Items:”, p) 
Share = einventory.values ​​()
 Print (“stock available”, eventry)
Output:
Total number of values: 3
All Keys: Tana_Key ([‘Fan’, ‘Bulb’, ‘Led’])
Item: {‘Fan’: 200, {Bulb ‘: 150,: Led’: 1000}
Deleted Items: (‘LED’, 1000)
Stock available {‘Fan’: 200, ‘Bulb’: 150}

Keys method

The keys() method returns a view object that displays a list of all the keys in the dictionary.
for i in user_info.keys():
    print(user_info[i])

      OutPut
pramod
2217691a05b9
B-Tech

      OR

user_info_value2 = user_info.keys()
print(user_info_value2)       
  # OutPut = dict_keys(['name', 'age', 'rollno',
              'class'])

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.