Consider the following example of an iterative class which makes factorials from a given number:
import math
class Factorial(object):
def __init__(self, num, maxsize=10e12):
self.num = num
self.maxsize = maxsize
def __repr__(self):
if __name__ == '__main__':
return f'<{self.__class__.__name__} object at {hex(id(self.__class__))}>'
else:
return '<' + self.__class__.__module__ + '.' + self.__class__.__name__ + ' object at ' + hex(id(self.__class__)) + '>'
def __iter__(self):
for i in range(1,self.num+1):
if math.factorial(i) > self.maxsize:
break
yield math.factorial(i)
So, of course we have the methods __init__, __repr__, and __iter__, which I have all read about online. I have two questions:
What would you call these methods? I know you can describe
__init__as a sort of constructor, but is there a special name that all of those__<blah>__methods fall under when it comes to classes?Is there a list of all of these so-called "special" or "built-in" class functions that tells what they are and what they do in a class context? The ones I already know of are
__init__,__enter__,__next__,__exit__,__iter__,__str__,__repr__, and__call__. Or is this pretty much a complete list, except for a few?
I've been scratching my head about this for a while now (mostly because I don't know what to call these functions so I can't really research them).