Overwriting in Python: Tricky. Dangerous. Powerful | by Marcin Kozak | Apr, 2024

Editor
1 Min Read


PYTHON PROGRAMMING

Although overwriting objects is a typical Python coding technique, it can lead to unexpected effects. You need to know how to use it to utilize its strengths.

Overwriting in Python: Do not enter without reconsideration. Can be dangerous.
Overwriting in Python can be dangerous: Don’t enter without reconsideration. Photo by Raúl Nájera on Unsplash

I’ve overwritten plenty of various objects in Python. If you’ve spent your share of hours coding in Python, you have, too. This is because, at least in Python, overwriting objects lies at the core of the language.

I’ve overwritten variables but also functions, classes, and class methods — even exceptions:

And indeed, we’ll differentiate between overwriting variables and callables. The difference between these two processes is actually quite significant, with the latter being more tricky. And even though our focus is on overwriting callables, as it’s a more advanced technique, we’ll also discuss overwriting variables, as it offers a good starting point for our discussion.

Share this Article
Please enter CoinGecko Free Api Key to get this plugin works.