The Python Magic Methods are special methods that add "magic" to your classes. They're also known as dunder methods, short for "double under" These methods are not meant to be invoked directly by you, but the invocation happens internally from the class on a certain action.

6m read timeFrom stackabuse.com
Post cover image
Table of contents
IntroductionWhat are Magic Methods?Understanding __str__ MethodUnderstanding __repr__ MethodDifferences Between __str__ and __repr__Why and When to Use __str__Why and When to Use __repr__Examples: Using the __str__ MethodExamples: Using the __repr__ MethodConclusion

Sort: