Python special functions | Python magical functions | Python tutorial for absolute beginners Hindi

Veröffentlicht am: 09 März 2021
auf dem Kanal: CodeWithRajat
57
1

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.


Auf dieser Seite können Sie das Online-Video Python special functions | Python magical functions | Python tutorial for absolute beginners Hindi mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer CodeWithRajat 09 März 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 57 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!