Collective Data Types - BenWare-FED/Python GitHub Wiki
Lists: A colletion of elements(int, float, string, or boolean, could be any combo) ex: list_combo = [ 1, 1.2, True, "Tuesday"]
Features:
-
Lists are ordered: indexing is 0 to length -1 eg if a list has 12 things in it, the indexing goes from 0 to 11 with the first item being assigned index 0. Use print(list[2]): To print the second indexed thing.
-
Lists are mutable: You can add and subtract elements. The two ways you can add is either at the end of the list or at a given index.
-
Lists allow duplicates
Access/operations on every element in the list
- Indexing list_1 = [2,3,4,5,6,7,8,9,10]
for i in range(0,len(list_1)): len is a keyword for length
print(list_1[i]) The i becomes the reference to the index number being called
- Use the element
for num in list_1: means for each element in the list
print(num)