+ 9

What's the difference between lists and variables in python?

They both store values right?

16th Jun 2023, 2:59 PM
シュラッダ🦋
シュラッダ🦋 - avatar
11 Answers
+ 12
You are asking the wrong question. It's like asking: what is the difference between holidays and Sundays. While your program is run, the computer must store certain values in its memory. A variable is a name, a label, which points to a specific memory location. We use variables so that we have an easier time remembering where is our data in computer memory. A list is a data structure which can hold multiple values. We can also give a name to a list, then this name is a variable. In Python we can freely reuse these names and assign different values to them in the course of the program. We can even assign another value that has different type (this is not possible in every language).
16th Jun 2023, 5:11 PM
Tibor Santa
Tibor Santa - avatar
+ 7
Lists can hold multiple values, whereas variables, can hold 1 string, integer, list dictionary, etc. Variables can also, hold multiple values, if there is a concatenation going on. Variables are like boxes, which store content. You can later on, call the variable, to extract the content inside it. A list is a collection of values, where you can store, manipulate and delete value, so that you can save all the relevant content in one part. Here is an example of both a variable and a list: favorite_food = ["pizza", "fried chips", "burger"] favorite_food is a variable, which contains a list. The list contains some values, which are all relevant to the topic, which is favorite foods. Hope this helps.
16th Jun 2023, 3:12 PM
Danish Zubair
Danish Zubair - avatar
+ 7
Thankyou ^_^
16th Jun 2023, 5:05 PM
シュラッダ🦋
シュラッダ🦋 - avatar
+ 6
variable not variables A variable stores only 1 value A list can store many values. If you talking about variables it means different variable and different variable can store different value but at the time only 1 value. a list is collection of 1 or more values.
16th Jun 2023, 3:07 PM
A͢J
A͢J - avatar
+ 6
Ok 👍
16th Jun 2023, 5:36 PM
シュラッダ🦋
シュラッダ🦋 - avatar
+ 5
Ok thanks 👍
18th Jun 2023, 5:27 AM
シュラッダ🦋
シュラッダ🦋 - avatar
+ 4
lists and variable can store values, but they do so in different ways. A variable is a named location in memory that stores a single value. The value stored in a variable can be of any data type, such as a number, string or bool. Example: x=5 Here, we create a variable named x and assign it the value 5. A list is a data structure that can store multiple values in a single, ordered collection. The value in a list can be of any data type, and a single list can contain values of different types. Example: my_list=[ 1,'hello',True ] Here, we create a list named my_list that contain three values Read More on https://W3School.com
17th Jun 2023, 7:18 AM
Vaibhav
Vaibhav - avatar
+ 2
Variables: Variables are used to store a single value or object in memory. They provide a way to assign a name to a value, allowing you to reference and manipulate it later. Lists: Lists are used to store multiple values or objects in a specific order. They are mutable, meaning you can add, remove, or modify elements within the list.
18th Jun 2023, 4:37 AM
HANUMANTHA B
HANUMANTHA B - avatar
+ 2
Take it easy Variable is the box or container where we store our data in the memory While list is the container in a memory with consective memory location but difference is in variable we can store data of only one datatype while in list we can store mulitiple data with multiple datatype…
18th Jun 2023, 5:11 AM
Muhammad Kabeer Daudzai
Muhammad Kabeer Daudzai - avatar
+ 2
Yes he is right
18th Jun 2023, 9:35 AM
Kotha Acc
Kotha Acc - avatar