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

  • Home
  • SEARCH
  • 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 1062731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:40:21+00:00 2026-05-16T18:40:21+00:00

What are the advantages of having Optional args in Python. Instead of overloading one

  • 0

What are the advantages of having Optional args in Python. Instead of overloading one function (or method) with args + optional args, wouldn’t Polymorphism with Inheritance suffice?

I am just trying to understand the burning reason to have this feature. or is it the case of being able to do one thing many ways?

P.S: I can see that it makes sense to have it in functional programming, to avoid having to define many functions practically doing almost the same thing, but are there any other…

  • 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-16T18:40:21+00:00Added an answer on May 16, 2026 at 6:40 pm

    Optional args have little to do with polymorphism (and don’t even need you to have classes around!-) — it’s just (main use!) that often you have “rarely needed” arguments for choices that are generally made in a certain way, but it might be useful for the caller to set differently.

    For example, consider built-in open. Most often, you open text files rather than binary opens, you open them for reading rather than for writing, and you’re happy with the default buffering — so, you just open('thefile.txt') and live happily ever after. Being able to specify the way in which you want to open (binary, for overwrite, for append, …) as the second (optional) argument, instead of its default 'r' value, is of course often useful. Once in a blue moon you want a file object with peculiar buffering options, and then having the buffering as the third (optional) argument (with a default value of course) pays big dividends… without it being in your way for the vast majority of the files you open!

    Inheritance and polymorphism would not really help one bit in getting the convenience of with open('blah.txt') as f: so concisely, while still allowing the same built-in function to serve many more use cases (e.g., when you need to open a file for binary append without any buffering… maybe once a year if you code a lot;-). And of course the convenience principles that apply to such built-in functions apply to the functions you write just as well!-)

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

Sidebar

Related Questions

Are there any advantages compiling for .NET Framework 3.5 instead of 2.0? For example
One of the biggest advantages of object-oriented programming is encapsulation, and one of the
What are the advantages of having declarations in a .inl file? When would I
What are the advantages and disadvantages of having a single instance compared to multiple
What are the advantages, if any exist, of having an an index for every
Obviously having whitespace in css, aspx and html pages is a great advantage at
What advantages does SQLServer CLR offer over T-SQL? Is using .NET syntax easier than
What are the advantages/disadvantages of keeping SQL in your C# source code or in
What are the advantages/disadvantages between MS VS C++ 6.0 and MSVS C++ 2008? The
What are the advantages and disadvantages of turning NOCOUNT off in SQL server queries?

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.