Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 Johnson
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rachel 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,507 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++.