What is a Inplace Operations in Python?

By Neha, 7 months ago
  • Bookmark
0

What is inplace operations and how to use it in python?

Inplace operations
1 Answer
0
Ashiqmukkil*

Inplace Operations :


It is common within applications to need to have code like this:


a = a + 1

or

a = a * 2


There is an effective shortcut for these in place operations:


a += 1

and

a *= 2


Any mathematic operator can be used before the '=' character to make an inplace operation:


-= decrement the variable in place

+= increment the variable in place

*= multiply the variable in place

/= divide the variable in place

//= floor divide the variable in place # Python 3

%= return the modulus of the variable in place

**= raise to a power in place


Other in-place operators exist for the bitwise operators ( ^ , | etc)

Your Answer

Webinars

Live Masterclass on "Python for Artificial Intelligence"

Dec 4th (7:00 PM) 212 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More