Lists in python are quite powerful, it is essentially a variable that can hold multiple values
Code:
list = [1, 2, 3, 4 ,5]
print(list)
Result:
[1, 2, 3, 4, 5]
You can also call specific items in a list as well as append an item to the append end of the list, the lists start at 0 not 1, be sure to keep that in mind. list_name.append(New Value). You can also insert items and a specific index this will push all other items in the index up 1 in front of it list list_name(index, value)
Code:
list = []
list.append(1)
print(list[0])
list.append(0,5)
print(list)
Result:
1
[5, 1]
I’m sure you’re starting to get tired of all this list so let me finish off by saying you can use del list_name[index] to delete an item in your list there is also the len command which displays the number of items currently in your list. Last but not least you can use the for loop, mentioned in post #37 https://joseph-t-gordon.tech/index.php/2023/03/21/post-37-the-power-of-loops-in-python/ to go through all the items within a list.
Code:
list = [1, 2, 3, 4, 5]
del list[0]
list_total = 0
print(len(list))
print(list)
for i in list:
list_total += i
print(list_total)
Result:
4
[2, 3, 4, 5]
14