python get dictionary values code example

Example 1: python get dictionary keys

# To get all the keys of a dictionary use 'keys()'
newdict = {1:0, 2:0, 3:0}
newdict.keys()
# Output:
# dict_keys([1, 2, 3])

Example 2: list of dict values

list(d.values())

Example 3: how to get all the values from the dict in python

a = {1:2 , 2:3 , 3:4}
values = a.values()

Example 4: how to get the value of key in python

print(dict.get("key"))

Example 5: get a value from a dictionary python

#!/usr/bin/python

dict = {'Name': 'Zabra', 'Age': 7}
print "Value : %s" %  dict.get('Age')
print "Value : %s" %  dict.get('Education', "Never")