-3

some_product += another_product

I have just started learning python so I am very new to the language, and I am struggling to understand what += means.

nandini
  • 7
  • 1
  • 1
    Same as `some_product = some_product + another_product`. – Austin Jan 04 '20 at 11:33
  • Did you try something like `a = 1 a += 2 print(a)`? – Nick Jan 04 '20 at 11:36
  • 2
    If only there was some sort of documentation which told you how these things? Oh, wait, there is: https://docs.python.org/3/reference/index.html - more specifically, for your question: https://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements – paxdiablo Jan 04 '20 at 11:41

1 Answers1

0

here is a very simple example of how to add to a variable a number:

a = 1
# we want to add to a 5
a = a + 5
print(a)
# output: 6

or:

a = 1
a += 5 # equivalent with a = a + 5
print(a)
# output: 6

similar: some_product += another_product is equivalent with: some_product = some_product + another_product, assuming that your variables are integers or other numeric types

kederrac
  • 16,819
  • 6
  • 32
  • 55