0
variable value
how to change the value stored in the same variable
3 Respuestas
+ 9
Before we can help you, it's up to you to make a try by yourself. Please post the link to this code here. Thanks!
+ 5
May be you was asking for this?
a = 7
b = 2
a = a - b
print(a) # result is 5
+ 1
You cannot. Every primitive type in Python has a class associated to it so a variable is nothing but an object. Also all primitive types are immutable in Python. You have some mutable types like lists, dictionary and sets.
Every time you try to assign a new value to the same variable, you end up creating a new object.
Example
a = 2
b = a
print(id(a))
print(id(b))
a = 7
print(id(a))