Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| 184_notes:lists [2022/05/06 22:00] – woodsna1 | 184_notes:lists [2022/05/07 01:20] (current) – woodsna1 | ||
|---|---|---|---|
| Line 22: | Line 22: | ||
| </ | </ | ||
| - | To change the value in a bucket, simply use = to assign to it: | + | To change the value in a bucket, simply use "=" |
| < | < | ||
| list_of_numbers[0] = 250 # Change the first element | list_of_numbers[0] = 250 # Change the first element | ||
| Line 29: | Line 29: | ||
| ===== Lists and For Loops ===== | ===== Lists and For Loops ===== | ||
| + | ==== Lecture Video ==== | ||
| + | |||
| + | {{youtube> | ||
| We often want to move through a list and read or change each value one-by-one. The easiest way to iterate through a list in Python is using a for loop. | We often want to move through a list and read or change each value one-by-one. The easiest way to iterate through a list in Python is using a for loop. | ||
| Line 44: | Line 47: | ||
| index = 0 | index = 0 | ||
| - | while index < len(list_of_numbers): | + | while index < len(list_of_numbers): |
| - | list_of_numbers[index] += 1 | + | list_of_numbers[index] += 5 # Increase each number by 5 |
| - | index += 1 | + | index += 1 # Increment the counter variable |
| </ | </ | ||