Wie verwende ich Methodenüberladung in Python?

Ich versuche, Methodenüberladung in Python zu implementieren:

<code>class A:
    def stackoverflow(self):    
        print 'first method'
    def stackoverflow(self, i):
        print 'second method', i

ob=A()
ob.stackoverflow(2)
</code>

aber die Ausgabe istsecond method 2; ähnlich:

<code>class A:
    def stackoverflow(self):    
        print 'first method'
    def stackoverflow(self, i):
        print 'second method', i

ob=A()
ob.stackoverflow()
</code>

gibt

<code>Traceback (most recent call last):
  File "my.py", line 9, in <module>
    ob.stackoverflow()
TypeError: stackoverflow() takes exactly 2 arguments (1 given)
</code>

Wie mache ich das?

Antworten auf die Frage(14)

Ihre Antwort auf die Frage