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 trial

Python Python Basics Types and Branching Strings and Operators

Luke Maschoff
Luke Maschoff
820 Points

I don't get what += means?

In this Python video, he used +=, what does this do exactly?

3 Answers

Rachel KTY Johnson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rachel KTY Johnson
Treehouse Project Reviewer

Hey 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 :)

Eric M
Eric M
11,545 Points

Yep, 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 just x += 1 but also x++.