+ 1

What are lists for

I was just wondering what they are for

21st Dec 2023, 3:27 PM
Ma Boi
Ma Boi - avatar
9 ответов
+ 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.
21st Dec 2023, 4:20 PM
Lothar
Lothar - avatar
+ 1
list is a collection of different data type. example: li = [1, 2, 'abc'] for i in li: print (type(i))
21st Dec 2023, 3:32 PM
A͢J
A͢J - avatar
21st Dec 2023, 3:35 PM
Stefanoo
Stefanoo - avatar
+ 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"]
21st Dec 2023, 5:11 PM
Rain
Rain - avatar
+ 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.
21st Dec 2023, 7:02 PM
Alexander Mcclure
Alexander Mcclure - avatar
0
Ok
21st Dec 2023, 3:32 PM
Ma Boi
Ma Boi - avatar
0
Ok but what can i use them for?
21st Dec 2023, 4:53 PM
Ma Boi
Ma Boi - avatar
0
hi
23rd Dec 2023, 1:21 PM
Mustafa Dwood
Mustafa Dwood - avatar
0
Hi
23rd Dec 2023, 1:23 PM
Ma Boi
Ma Boi - avatar