Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:16:00+00:00 2026-05-31T13:16:00+00:00

def func(a, b, c=’four’): print ‘a is %s, b is %s, c is %s’

  • 0
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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:16:01+00:00Added an answer on May 31, 2026 at 1:16 pm

    Python calls those ‘default argument values‘. It is a very simple form of function overloading (overloading on ‘arity‘ (i.e. how many arguments the function has)). This is as complex as you can get with function overloading in Python though.

    Because of a combination of a desire to keep the language fairly simple and the fact that Python variables only have a type at runtime, Python cannot overload by type. You can use isinstance to roll your own overloading if you like, but the resulting code is quite messy, and I wouldn’t recommend it.

    Other languages also have default arguments. C++, for example, also allows default arguments, and C++ explicitly treats default arguments as a form of function overloading.

    One thing about Python default arguments that differs from C++ is that Python has named arguments, which means you can explicitly override a particular default value without overriding the others.

    For example:

    def foo(bar, baz="A baz", qux=0):
        return "(%r, %r, %r)" % (bar, baz, qux)
    
    foo(5)
    (5, 'A baz', 0)
    foo(5, qux=2)
    (5, 'A baz', 2)
    

    There are other languages that allow this as well. I believe, for example, that this is something Ruby allows, though I’m not sure what the syntax is.

    Lastly, Python, weirdly enough, has operator overloading. This is managed through functions with special reserved names that are part of a class. Such functions always have the form __name__. The rules for exactly how operator overloading works in the case of any individual operator can be a little odd, and I would generally recommend against using this feature in most cases, especially for overloading numeric or relational operators.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run this code def func(x, y, *w, **z): print x print y
I created two modules, one with def _func(): print hi and another def func():
Help me with this part of code: class Ooo attr_accessor :class_array end def func(ctx)
This is a module named XYZ. def func(x) ..... ..... if __name__==__main__: print func(sys.argv[1])
CODE 1: x=4 def func(): print(HELLO WORLD) y=x+2 print (y) print (x) # gives
Suppose I have @someDecorator def func(): '''this function does something''' print 1 Now, the
I have a code.py : def funA(): print('A') funA() def funB(): print('B') def funC():
I'm pretty new at python and I was wondering if this: def func(self, foo):
def log(func): def wraper(*a, **kw): return func(*a, **kw) return wraper @log def f(): print
Here's a snippet of code from within TurboGears 1.0.6: [dispatch.generic(MultiorderGenericFunction)] def run_with_transaction(func, *args, **kw):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.