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 trialLuke Maschoff
820 PointsI don't get what += means?
In this Python video, he used +=, what does this do exactly?
3 Answers
Rachel KTY Johnson
Treehouse Project ReviewerHey Luke Maschoff ! It means "add the following to the existing string". To elaborate..
counter = counter + 10;
Is the same as:
counter += 10;
It just makes writing code faster :)
Cynthia Ansu-Kyeremeh
1,568 Pointsit is the same as a = a + 1 or a+=1
marin stefan daniel
5,422 Pointsa = a + 2 same as a += 2
Eric M
11,546 PointsEric M
11,546 PointsYep, this sort of variation or shortening of acceptable syntax is often called syntactic sugar because it makes code easier, or "sweeter", to read.
Many languages also sugar integer increments of one,
x = x + 1
, to not justx += 1
but alsox++
.