+ 1
What are lists for
I was just wondering what they are for
9 Respuestas
+ 4
Ma Boi ,
> lists allow us to store multiple values / objects / items in a single variable. the objects can be of any type.
> lists are also mutable, that means that we can replace items by an other one, add new items or remove items in an existing list.
> lists are iterables, that means that we can iterate over the items of the list by using loops.
+ 1
list is a collection of different data type.
example:
li = [1, 2, 'abc']
for i in li:
print (type(i))
+ 1
Here is a SoloLearn lesson about lists.
https://www.sololearn.com/learn/o-JUMP_LINK__&&__Python__&&__JUMP_LINK/2431/?ref=app
+ 1
Ma Boi ,
A list is for storing any number of different values under a single name.
Instead of doing this,
name0 = "Joe"
name1 = "Sid"
name2 = "Ann"
name3 = "Min"
you can do this.
names = ["Joe", "Sid", "Ann", "Min"]
+ 1
Let's say you have some things you want to store, like the amount of each product you have at a store. If the number of products never changes, like you only have apples, pears, and oranges daily, you /could/ use variables, like apples=1; pears=5; oranges=2. But if you want to add grapes, you must rewrite your program. (Dynamic) Lists can add things on the fly, meaning you don't need new variables, so you can add as many fruits as you want, like fruits=["apples, "pears", "oranges"]; amounts=[1, 5, 2], then when you update, you add "grapes" to fruits, and add your grapes stock to amounts.
0
Ok
0
Ok but what can i use them for?
0
hi
0
Hi