In Place Operators

*Quick Post

An in place operator is basically a method of shortening some operators. For example rather than writing out the operation for “x = x + 3” you can just write the operator “x += 3” – both are the same and both will produce the same result.

The same kind of operation can be achieved for subtraction (-), multiplication (*), division (/), and remainder (%).


>>> x = 2

>>> print(x)

>>> print += 3


[Interpreter ]



In addition to numerical operations, in place operators can also be used on strings, for example:


>>> x = “Hello ”

>> print(x)

>>> x += “World”

>>> print(x)




Hello World



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s