Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAnna Phipps
124 PointsWhen reassigning value to a variable, will the interpreter run with the old value up until the point of the new value?
If you had previously assigned this value for example in the first line of your code: dessert = "ice cream" and you used the variable dessert several times until let's say line 15 of your code where you reassign a new value to that variable: dessert = dessert + " and cookies" will the script be run with the new value after that point and with the old value before that point even though they technically have the same variable name?
2 Answers
Daniel Svens
6,043 PointsYes (If i understood you question correctly), You can try it like this.
dessert = 'ice cream'
print(dessert) # ice cream
dessert = dessert + ' and cookies'
print(dessert) # ice cream and cookies
Sumiya Malik
3,976 PointsYes, Consider the variables as boxes. For example you have 3 boxes and you named them as b1, b2, b3 and data types as fruits(in this case). Now you added an apple in b1. So you have an apple in that box until and unless you replace it with another value, lets take orange. So the value apple will be replaced by orange. and it will have the orange in it until you replace it with something else. b1="apple" print(b1) b1="orange" print(b1) Hope that helps!