as someone who just learned the python basics, this might be a weird and stupid question but I got confused.
a = (1,2,3) #if people call this a tuple
b = [1,2,3] #this as a list
c = 1,2,3 #this as a tuple
d = 1 #then what do people call this? a normal value inside a variable?
Also, please correct me if there's mistake, thanks in advance.
CodePudding user response:
d = 1
Since you just put a number, 1 being the number, the variable type is an integer. Python putting a decimal number is a float.
CodePudding user response:
I think you are confused by the assignment form in this case.
The left hand side is the name you want to assign to and the right hand side
is a value, e.g. a = 1
, a
is the name and 1
is the value.
Therefore (1,2,3)
is a tuple and a
is tuple after you have
assigned a = (1,2,3)
. The same holds for any other data-type; lists, integers, floats and so on.
It's nice to think of variables (the left hand side) as values but they are not. They are not boxes with values inside either but it may help when reasoning about code.
If you need to talk about it in prose you can say that "the a variable's value is ..." because a variable always refers to a value when it is assigned.