+ 2

List and variable

what are the differents between a variable and a list?

6th Jan 2017, 12:43 PM
yu xinyang
yu xinyang - avatar
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 ;)
6th Jan 2017, 8:55 PM
infinity
infinity - avatar
+ 1
a variable can contain a list, actually. but a list can only contain values (of variables if any)
7th Jan 2017, 5:29 PM
Amaras A
Amaras A - avatar
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 ;)
9th Jan 2017, 3:23 AM
ramzi
ramzi - avatar
0
Variable can store one value at a time List can store multiple value at a time
18th Jan 2017, 5:10 PM
vaibhav patel