'Is calling method of a class rather than an object of that class/type valid or a thing?
To explain inheritance in Python, the author of a book (by Charles Dierbach) uses the following example of an exploded string class, which takes a string as input (Hello World
) and outputs it as H e l l o W o r l d
without quotes when the explode()
method of the subclass is called:
class ExplodedStr(str):
def __init__(self, value = ''):
str.__init__(value)
...
Question: The str.__init___(value)
method of class is called rather than method of an object of that type/class. Should I just take this for granted (memorize it) and proceed, or is there a logic?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|