Abstract
In Python, some names are spelled in a peculiar manner, with two leading and two trailing underscores. You have already encountered some of these (_ _future_ _, for example). This spelling signals that the name has a special significance—you should never invent such names for your own programs. One very prominent set of such names in the language consists of the magic (or special) method names. If your object implements one of these methods, that method will be called under specific circumstances (exactly which will depend on the name) by Python. There is rarely any need to call these methods directly.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 1.
Thanks to Alex Martelli for pointing out this idiom and the importance of using it here.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2017 Magnus Lie Hetland
About this chapter
Cite this chapter
Hetland, M.L. (2017). Magic Methods, Properties, and Iterators. In: Beginning Python. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0028-5_9
Download citation
DOI: https://doi.org/10.1007/978-1-4842-0028-5_9
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-0029-2
Online ISBN: 978-1-4842-0028-5
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)