Software engineering and personal development

Tag: class

How to Use Name Mangling in Python

In this article, we’re going to uncover a hidden gem of Python programming – the concept of “Name Mangling”. It may sound a bit like a fantasy novel, but it’s a practical and powerful feature that’s great to have in your coding toolkit. So, let’s dive right in!

What is Name Mangling?

“Name Mangling” is a unique Python trick involving a special use of the double underscore (__). When we use double underscores before a variable in a class, Python tweaks the variable’s name to make it harder to access unintentionally. This isn’t about creating secret variables, but rather, it’s about avoiding errors in larger programs with many moving parts.

Continue reading

© 2024 Fatos Morina

Theme by Anders NorenUp ↑