Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "+=" (plus equals) mean?

Tags:

operators

ruby

I am doing some ruby exercises and it said I need to go back and rewrite the script with += shorthand notations.

This exercise deals primarily with learning new methods. The problem is, I have no idea what += means when I tried to look it up online.

like image 296
F F Avatar asked Oct 03 '11 17:10

F F


People also ask

What does += mean in C++?

+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand. C += A is equivalent to C = C + A.

What is plus equal in C?

The += operator in C is one of the language's compound assignment operators. It is essentially a shorthand notation for incrementing the variable on the left by an arbitrary value on the right. The following two lines of C code are identical, in terms of their effect on the variable z: z = z + y; // increment z by y.

What is plus equal in Python?

The Python += operator adds two values together and assigns the final value to a variable. This operator is called the addition assignment operator. This operator is often used to add values to a counter variable that tracks how many times something has happened.


1 Answers

+= is a shorthand operator.

someVar += otherVar 

is the same as

someVar = someVar + otherVar 
like image 106
Justin Niessner Avatar answered Sep 24 '22 14:09

Justin Niessner