What is the difference between dictionary items, keys, and values in Python

1 Answer

0 votes
dic = {'firstname': 'Tom', 'lastname': 'Leia', 'age': 61}
 
print(dic.items()) # Returns an object that displays a list of dictionary key-value tuple pairs
print(dic.keys()) # Returns an object that displays a list of all the keys in the dictionary
print(dic.values()) # Returns an object that displays a list of all the values in the dictionary
 
 
 
'''
run:
 
dict_items([('firstname', 'Tom'), ('lastname', 'Leia'), ('age', 61)])
dict_keys(['firstname', 'lastname', 'age'])
dict_values(['Tom', 'Leia', 61])
 
'''

 



answered Dec 16, 2024 by avibootz
...