for loop can also iterate over the keys or both keys and valuesfor in spam keys()print(kcolor age for in spam items()print( ('color''red'('age' when you use the keys()values()and items(methodsa for loop can iterate over the keysvaluesor key-value pairs in dictionaryrespectively notice that the values in the dict_items value returned by the items(method are tuples of the key and value if you want true list from one of these methodspass its list-like return value to the list(function enter the following into the interactive shellspam {'color''red''age' spam keys(dict_keys(['color''age']list(spam keys()['color''age'the list(spam keys()line takes the dict_keys value returned from keys(and passes it to list()which then returns list value of ['color''age'you can also use the multiple assignment trick in for loop to assign the key and value to separate variables enter the following into the interactive shellspam {'color''red''age' for kv in spam items()print('keyk valuestr( )keyage value keycolor valuered checking whether key or value exists in dictionary recall from the previous that the in and not in operators can check whether value exists in list you can also use these operators to see whether certain key or value exists in dictionary enter the following into the interactive shellspam {'name''zophie''age' 'namein spam keys(true dictionaries and structuring data