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 9122915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:12:55+00:00 2026-06-17T06:12:55+00:00

This is similar to method overloading. When print Hello(1, 2, 3) gets executed it

  • 0

This is similar to method overloading. When print Hello(1, 2, 3) gets executed it returns "a and b" whereas I want it to return "a and b and c". I know I could have said if (a and b and c is None) then it would have worked. But if I had 20 parameter and I have to handle every case it would be just multiple if statements which I don’t think should be necessary. Is there a better way I should be doing such a problem?

 def Hello(a=None, b=None, c=None):
    if(a and b):
        return "a and b"
    if(a and c):
       return "a and c"
    if(a and b and c):
       return "a and b and c"

print Hello(1, 2, 3)
  • 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-06-17T06:12:57+00:00Added an answer on June 17, 2026 at 6:12 am

    You need to rethink your program logic, really. Usually, an API will not have all-optional parameters where you need to build a large decision tree from all the inputs.

    In other words, in a real program you won’t normally encounter a function where the behaviour is completely different for each of the different combinations of inputs. Invariably, the legal combinations is much, much smaller even for a larger number of optional parameters.

    For your toy example, you can come up with other ways to create your return value not involving a decision tree:

    • map responses:

      responsemap = {
          (True,  True,  False): "a and b",
          (True,  False, True):  "a and c",
          (True,  True,  True):  "a and b and c"
      }
      
      def Hello(a=None, b=None, c=None):
          return responsemap.get((bool(a), bool(b), bool(c)), None)
      
    • build a string based on the inputs:

      def Hello(a=None, b=None, c=None):
          return ' and '.join([n for n in ('a', 'b', 'c') if locals()[n]])
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a constructor method similar to this: public class Foo { public Foo
I have a method somewhat similar to the one written bellow(this is just a
I have the need for a method similar to this: // takes in a
In my C application, I have a logging method similar to this: void logError(const
I have a method similar to this public void method(final Object A){ .... }
I have simple remoting API that has method similar to this: bool FillMyList(List<string> ListToFill)
I have an Obj-C method similar to this: -(void)getUserDefaults:(BOOL *)refreshDefaults { PostAppDelegate *appDelegate =
All the generated webservice-stubs from our backend have an equals-method similar to this one:
I have this simple method that returns a user: User usr = ReliableExecution.RetryWithExpression<User, User>(u
I have a method similar to this: public List<MyClass> DoSomething(string Name, string Address, string

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.