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 trialmohan Abdul
Courses Plus Student 1,453 Pointsreassigning the variable? the teacher reassigned the variable three times. when reassigning the old variable, do you typ
do you type the previous label?
eg. """dessert = ' choc & candy' dessert = dessert + ' ben & jerries' dessert += yum' dessert += ' !' * 20""" so each time i want to change the variable or make addition I type/input the previous label? i am I correct in that? how do i make a further addition to the variable?
3 Answers
Steven Parker
231,236 PointsA normal assignment ("=
") replaces the contents of a variable. It creates a new variable if one doesn't exist.
A concatenating assignment ("+=
") adds on to what's already there. This form can only be used on variables that have already been created.
mohan Abdul
Courses Plus Student 1,453 PointsSteven Parker, thanks for the speedy response its cleared up a few long standing questions, there is one thing thats nagging me from your response though. Top line """var sample""" should i ignore the "var" as the rest of the labels are just """sample""". once again thank you.
Steven Parker
231,236 PointsSorry, I got confused for a moment after answering a question about a different language. I've revised my answer.
Tyrone Roberts
1,182 PointsSteven Parker your answer answers a lot of the questions being asked on the forum about this reassigning process.
Thank you!
Steven Parker
231,236 PointsIt's nice to know the old answers are still helping folks. Happy coding!
mohan Abdul
Courses Plus Student 1,453 Pointsmohan Abdul
Courses Plus Student 1,453 PointsSteven Parker , so there is no way to delete a variable? or you can only change it? In the video teacher only made additions, how do you completly change an already existing variable so its completly different instead of making additions? please code examples if you can. thanks?
Steven Parker
231,236 PointsSteven Parker
231,236 Points