0

variable value

how to change the value stored in the same variable

11th Jun 2020, 3:56 PM
Anudeep Naidu
Anudeep Naidu - avatar
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!
11th Jun 2020, 4:00 PM
Lothar
Lothar - avatar
+ 5
May be you was asking for this? a = 7 b = 2 a = a - b print(a) # result is 5
11th Jun 2020, 4:42 PM
Lothar
Lothar - avatar
+ 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))
11th Jun 2020, 4:16 PM
Avinesh
Avinesh - avatar