Basic Features of Python I
Part2
For Loop in List vs Dictionary
Bentuk umum for Loop di Python
for <var> in <iterable>:
<statement(s)>
Schematic Diagram of a Python for Loop
For Loop in List
Example:
For Loop in Dictionary
Example:
As you can see, when a for loop iterates through a dictionary,
the loop variable is assigned to the dictionary’s KEYS
For Loop in Dictionary
To access the dictionary VALUES within the loop, you can make a
dictionary reference using the key as usual: