Is this function overloading or something?

Question!
def func(a, b, c='four'):
    print 'a is %s, b is %s, c is %s' %(a, b ,c)

func('one','two','three')
func('one', 'two')

This code runs with no problem. But what is this called? 'overloading'?

btw, is this style only available in Python? Thank you!

By : pdxhiker


Answers

It's called default argument values.

It's not a Python-only feature, one example is C and there are more.

Python doesn't support function overloading (unlike C ). Function overloading is when you have more than one function with the same name and compiler figures out which one you're calling based on the number of passed arguments and their types.

By : yak


As others have noted, this is default arguments, not operator overloading.

The way Python does actual operator overloading is to have special method functions that you can optionally define in a class. Because Python does it this way, it is not possible to overload operations purely on built-in types; you cannot overload the operator in the expression 1 1. However, you can make a subclass of int and overload that subclass to do whatever you want. MyClass(1) 1 could possibly have an overloaded operator.

For more information on operator overloading in Python:

operator overloading in python

By : steveha


This video can help you solving your question :)
By: admin