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.
Sur cette page du site, vous pouvez voir la vidéo en ligne Python special functions | Python magical functions | Python tutorial for absolute beginners Hindi durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur CodeWithRajat 09 mars 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 57 fois et il a aimé 1 téléspectateurs. Bon visionnage!