How do I use method overloading in Python

0 votes

I am trying to implement method overloading in Python:

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

ob=A()
ob.stackoverflow(2)

but the output is second method 2; similarly:

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

ob=A()
ob.stackoverflow()

gives

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

How do I make this work?

Apr 26, 2022 in Python by Edureka
• 13,620 points
277 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

How do I use method overloading in Python?

It's method overloading, not method overriding. And in Python, ...READ MORE

answered Jan 4, 2023 in Python by Elton
• 400 points
297 views
0 votes
1 answer

How do I use urllib to see if a website is 404 or 200 in Python?

For Python 3, try doing this: import urllib.request, ...READ MORE

answered Nov 29, 2018 in Python by Nymeria
• 3,560 points

edited Dec 11, 2018 by Nymeria 13,360 views
0 votes
0 answers

how do i use the XOR operator in python regular expression?

can u give an example? READ MORE

Mar 26, 2019 in Python by Waseem
• 4,540 points
1,425 views
0 votes
1 answer

How do I use lambda() with reduce() in python?

The reduce() function in Python takes in ...READ MORE

answered May 20, 2019 in Python by Umer
1,654 views
0 votes
3 answers

How do I use raw_input in Python 3?

raw_input() was renamed to input() in Python 3. Another example ...READ MORE

answered Jan 4, 2021 in Python by Carlos
2,750 views
0 votes
2 answers

How do I copy a file in python?

copy a file in python  from shutil ...READ MORE

answered Mar 27, 2019 in Python by rajesh
• 1,270 points
959 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,056 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP