Python special functions | Python magical functions | Python tutorial for absolute beginners Hindi
In Python, special methods are a set of predefined methods you can use to enrich your classes. They are easy to recognize because they start and end with double underscores, for example _init_ or __str__.
As it quickly became tiresome to say under-under-method-under-under Pythonistas adopted the term “dunder methods”, a short form of “double under.”
These “dunders” or “special methods” in Python are also sometimes called “magic methods.” But using this terminology can make them seem more complicated than they really are—at the end of the day there’s nothing “magical” about them.
Special Methods and the Python Data Model
This elegant design is known as the Python data model and lets developers tap into rich language features like sequences, iteration, operator overloading, attribute access, etc.
You can see Python’s data model as a powerful API you can interface with by implementing one or more dunder methods. If you want to write more Pythonic code, knowing how and when to use dunder methods is an important step.
For a beginner this might be slightly overwhelming at first though. No worries, in this article I will guide you through the use of dunder methods using a simple Account class as an example.
_repr__: The “official” string representation of an object. This is how you would make an object of the class. The goal of __repr_ is to be unambiguous.
__str__: The “informal” or nicely printable string representation of an object. This is for the enduser.
On this page of the site you can watch the video online Python special functions | Python magical functions | Python tutorial for absolute beginners Hindi with a duration of hours minute second in good quality, which was uploaded by the user CodeWithRajat 09 March 2021, share the link with friends and acquaintances, this video has already been watched 57 times on youtube and it was liked by 1 viewers. Enjoy your viewing!