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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:28:41+00:00 2026-06-09T10:28:41+00:00

def f1(n): #accepts one argument pass def f2(): #accepts no arguments pass FUNCTION_LIST =

  • 0
def f1(n): #accepts one argument
    pass

def f2(): #accepts no arguments
    pass

FUNCTION_LIST = [(f1,(2)), #each list entry is a tuple containing a function object and a tuple of arguments
                 (f1,(6)),
                 (f2,())]

for f, arg in FUNCTION_LIST:
    f(arg)

The third time round in the loop, it attempts to pass an empty tuple of arguments to a function that accepts no arguments. It gives the error TypeError: f2() takes no arguments (1 given). The first two function calls work correctly – the content of the tuple gets passed, not the tuple itself.

Getting rid of the empty tuple of arguments in the offending list entry doesn’t solve the problem:

FUNCTION_LIST[2] = (f2,)
for f,arg in FUNCTION_LIST:
    f(arg)

results in ValueError: need more than 1 value to unpack.

I’ve also tried iterating over the index rather then the list elements.

for n in range(len(FUNCTION_LIST)):
    FUNCTION_LIST[n][0](FUNCTION_LIST[n][1])

This gives the same TypeError in the first case, and IndexError: tuple index out of range when the third entry of the list is (f2,).

Finally, asterisk notation doesn’t work either. This time it errors on the call to f1:

for f,args in FUNCTION_LIST:
    f(*args)

gives TypeError: f1() argument after * must be a sequence, not int.

I’ve run out of things to try. I still think the first one ought to work. Can anyone point me in the right direction?

  • 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-09T10:28:43+00:00Added an answer on June 9, 2026 at 10:28 am

    Your comment in this code snippet shows a misconception relevant in this context:

    FUNCTION_LIST = [(f1,(2)), #each list entry is a tuple containing a function object and a tuple of arguments
                     (f1,(6)),
                     (f2,())]
    

    The expressions (2) and (6) are not tuples – they are integers. You should use (2,) and (6,) to denote the single-element tuples you want. After fixing this, your loop code should look thus:

    for f, args in FUNCTION_LIST:
        f(*args)
    

    See Unpacking Argument Lists in the Python tutorial for an explanation of the *args syntax.

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

Sidebar

Related Questions

My assignment ask to make a function call readFasta that accepts one argument: the
I have a function that accepts wildcard keyword parameters: def func(**kargs): doA doB How
I have a function foo that accepts a Boolean function def foo( f:(_)=>Boolean )
Is there a method to pass a variable number of arguments to a function
If I have a function which accepts more than one string parameter, the first
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
Is it possible to create a dbus method that accepts multiple arguments? I wish
I have a function that is taking an arbitrary set of arguments and then
I'm writing a function that exponentiates an object, i.e. given a and n, returns
Possible Duplicate: Having more then one parameter with def in python I need to

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.