filmov
tv
Python += Assignment Operator For Numbers, Strings & Lists

Показать описание
What is += in Python?
The assignment operator += adds to a numeric variable the number on the right of the operator.
For example, i += 2 will add the amount of 2 to the existing value of i.
The same += operator can be used with lists and strings by appending to both the value of what is being assigned.
For example, i += "1" will append the string "1" to the existing contents of the string contained for i.
Similarly, i += [1] will append to the end of the list contained already in the variable i the element 1.
The assignment operator += adds to a numeric variable the number on the right of the operator.
For example, i += 2 will add the amount of 2 to the existing value of i.
The same += operator can be used with lists and strings by appending to both the value of what is being assigned.
For example, i += "1" will append the string "1" to the existing contents of the string contained for i.
Similarly, i += [1] will append to the end of the list contained already in the variable i the element 1.