Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




values( ) FUNCTION


The values( ) Function is used to return all the values in the Dictionary.


Example :


x = {
    5 : "Is a Number", 
    "John": "Is a Name", 
    "Python": "Is a Language"
}
for i in x.values():
    print(i)


Output :



  Is a Number
  Is a Name
  Is a Language

So, in the above code we have created a 'Dictionary' using braces '{ }' and 'Key' and 'Value' pairs.


x = {
    5 : "Is a Number", 
    "John": "Is a Name", 
    "Python": "Is a Language"
}

And initialised to the variable 'x'.


java_Collections

In the next line we have used the 'for loop' to Iterate through the 'Dictionary' just to get the 'Values'.


for i in x.values():
    print(i)

Now, since there is a 'Key' and 'Value' pair in a 'Dictionary', we have used the 'values( )' Function, that will only print the 'Values' and not the 'Keys'.


And if you see the Output, just the 'Values' are printed.


Output :



  Is a Number
  Is a Name
  Is a Language