in
keyword. This will
loop over the keys one at a time. The values can be accessed with the
keys:
student = {"name": "Tom", "age": 17, "height": 68} for key in student: print(f"{key}: {student[key]}") # name: Tom # age: 17 # height: 68
.keys()
returns a list of the keys:
for key in student.keys(): print(key) # name # age # height
.values()
returns a list of the values:
for value in student.values(): print(value) # Tom # 17 # 68
.items()
returns both keys and their values, which can be
accessed by using two loop variables separated by a comma:
for key, value in student.items(): print(f"{key}: {value}") # name: Tom # age: 17 # height: 68
scores = {"Alice": 98, "Bob": 77, "Charlie": 85}
Your code
scores = {"Alice": 98, "Bob": 77, "Charlie": 85}
Your code
scores = {"Alice": 98, "Bob": 77, "Charlie": 85}
Your code
scores = {"Alice": 98, "Bob": 77, "Charlie": 85} # start of loop here print(f"{name} scored {score}")
Your code
scores = {"Alice": 98, "Bob": 77, "Charlie": 85} for name in scores: # print name and score here
Your code