Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
184_notes:lists [2022/04/20 15:08] – woodsna1 | 184_notes:lists [2022/05/06 22:01] – [Lists and For Loops] woodsna1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Coding: Lists ====== | ====== Coding: Lists ====== | ||
- | We often need a way to represent a group of objects or values in code. Python makes this easy with lists. A list gives a name to a collection of any Python objects. In Glowscript, we often use lists that include spheres, arrows, rings, and other shapes. Creating a list is easy: | + | We often need a way to represent a group of objects or values in code. Python makes this easy with lists. A list gives a name to a collection of any Python objects. |
+ | |||
+ | In Glowscript, we often use lists that include spheres, arrows, rings, and other shapes. Creating a list is easy: | ||
< | < | ||
Line 13: | Line 15: | ||
</ | </ | ||
- | You can think of a list like a column in an excel spreadsheet, | + | You can also access each bucket in a list to update or retrieve the object within it. One way is by using list indexing. Indices in a Python list start at 0 for the first element: |
< | < | ||
Line 42: | Line 44: | ||
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 |
</ | </ | ||