Here is an example:
# class.py
class MyString:
def __init__(self, str):
self.str = str
def __div__(self, sep):
return self.str.split(sep)
>>> m = MyString('abcdabcdabcd')
>>> print m / 'b'
['a', 'cda', 'cda', 'cd']
The __init__ method takes two parameters: the first one, self, is the instance object itself and str, the second, is a parameter passed in by the call. Is using __init__ the only way to get values into the instance of my class?
Or, if I don't declare the method __init__, will expressions like m = MyString('abcdabcdabcd') cease to work?