"Magic Methods" 🪄 The Dunder Methods are a type of method used in Python. The term "dunder" stands for "double under," represented by two underscores on either side of the method name. As a Python developer, you've likely used them without even realizing it.
An example is the constructor, which you may be familiar with in other programming languages, and in Python it's defined as "double underscore init double underscore." There seems to be some confusion over the number of underscores; while it may seem like it should be called "quadruple underscore" since it has four underscores, it's actually referred to as "double underscore methods." Python provides many more double underscore methods apart from the constructor. Trey Hunter recommends that Python developers should memorize three particular dunder methods. The first is "init," which is essentially a necessity for all programs.
The second one is "reper," which offers a more readable version of your program. The use of "reper" can make your program easier to understand and debug, as it provides more human-friendly text than memory references. The initialization constructor is perhaps the most widely used double underscore method in Python.
This function can be used to perform some initial setup games and save some data for later use. Other dunder methods include "eq" for equality comparison and mathematical operators such as addition and subtraction. it's vital to take into account the sidedness of some operators. Other potential issues that can arise with dunder methods include the sidedness problem, which occurs when an operator like "add" fails when the operands are reversed.
Additional functions like "r" can help you avoid such issues. In Python, you can define your own dunder methods to decide how two objects should interact based on operators like "plus" or "equals." Python provides a variety of other dunder methods for various purposes, including representations, comparisons, mathematical operations, type conversions, string formatting, iterators, and much more. keep in mind that some dunder methods may not be as crucial, depending on the complexity and needs of your Python program.
Auf dieser Seite können Sie das Online-Video Python Double Underscore Dunder Methods and Operator Overloading mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Stephen Blum 09 Januar 2025 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 618 Mal angesehen und es wurde von 14 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!