+ 5

Can i do function overloading in python like java?

25th Nov 2018, 4:32 AM
Maninder $ingh
Maninder $ingh - avatar
7 odpowiedzi
+ 11
I don't think so. Only the last definition of the function would be used. But we could define one function that takes, for example, 1, 2, or 3 arguments--like the built-in range().
25th Nov 2018, 4:51 AM
Kishalaya Saha
Kishalaya Saha - avatar
25th Nov 2018, 1:18 PM
Sarvesh Yadav
Sarvesh Yadav - avatar
+ 4
Okay, thanks Sarvesh! That's what I alluded to in my first comment in this post. But despite having similar effect, it's not exactly the same as function overloading in Java--which, as far as I know, refers to having more than one function with the same name and typically similar job but different number/type of arguments. Here you have just one function.
25th Nov 2018, 1:36 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 4
I have studied only this way of function overloading in python
25th Nov 2018, 1:42 PM
Sarvesh Yadav
Sarvesh Yadav - avatar
+ 4
Nice, but that's not function overloading, even though it gives you the same result.
26th Nov 2018, 4:34 AM
Chris
Chris - avatar
+ 2
Yes ,can be done
25th Nov 2018, 11:25 AM
Sarvesh Yadav
Sarvesh Yadav - avatar
+ 1
Sarvesh ✓ , would you mind giving an example? Thanks.
25th Nov 2018, 12:46 PM
Kishalaya Saha
Kishalaya Saha - avatar