+ 2
List and variable
what are the differents between a variable and a list?
4 Answers
+ 4
The main difference is that a variable contains a value (e.g. numbers, false/true, strings of texts ecc.), while a list is a dinamic set of elements. Dinamic means that you can add, delete, interchange and replace, the elements of the list during the execution of the script. Elements are pretty much the same thing as variables but sometimes grouping some of them up in a list could be useful instead of having only separated ones.
Hope I helped you and code on ;)
+ 1
a variable can contain a list, actually. but a list can only contain values (of variables if any)
0
Here's another way to put it, you have a very big closet, a variable is a shelf in this said closet, you can place an item on it and later on change it if you want to. A list is the closet, made out of several shelves, and you can have an item on each shelve.
In Python this translates to
shelve="jeans"
shelve2="t-shirt"
closet=["book",shelve, shelve2,"watch","underwear"] ..
hope that helped ;)
0
Variable can store one value at a time
List can store multiple value at a time