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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:04:55+00:00 2026-05-13T16:04:55+00:00

In python is it possible to have the above code without raising an exception

  • 0

In python is it possible to have the above code without raising an exception ?

def myfunc():
    pass

# TypeError myfunc() takes no arguments (1 given)
myfunc('param')

Usually in php in some circumstances I launch a function without parameters and then retrieve the parameters inside the function.

In practice I don’t want to declare arguments in myfunc and then passing some arguments to it. The only one solution I found is myfunc(*arg). Are there any other methods ?

  • 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-13T16:04:55+00:00Added an answer on May 13, 2026 at 4:04 pm
    >>> def myFunc(*args, **kwargs):
    ...   # This function accepts arbitary arguments:
    ...   # Keywords arguments are available in the kwargs dict;
    ...   # Regular arguments are in the args tuple.
    ...   # (This behaviour is dictated by the stars, not by
    ...   #  the name of the formal parameters.)
    ...   print args, kwargs
    ...
    >>> myFunc()
    () {}
    >>> myFunc(2)
    (2,) {}
    >>> myFunc(2,5)
    (2, 5) {}
    >>> myFunc(b = 3)
    () {'b': 3}
    >>> import dis
    >>> dis.dis(myFunc)
      1           0 LOAD_FAST                0 (args)
                  3 PRINT_ITEM
                  4 LOAD_FAST                1 (kwargs)
                  7 PRINT_ITEM
                  8 PRINT_NEWLINE
                  9 LOAD_CONST               0 (None)
                 12 RETURN_VALUE
    

    And to actually answer the question: no, I do not believe there are other ways.

    The main reason is pretty simple: C python is stack based. A function that doesn’t require parameters will not have space allocated for it on the stack (myFunc, instead, has them in position 0 and 1). (see comments)

    An additional point is, how would you access the parameters otherwise?

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

Sidebar

Related Questions

Is it possible to have a list be evaluated lazily in Python? For example
Possible Duplicate: Python, compute list difference I have two lists For example: A =
Possible Duplicate: Calling Python from JavaScript I have a test.py and test.js . I
Possible Duplicate: Circular (or cyclic) imports in Python I have class B that imports
As python does not have concept of constants, would it be possible to raise
Possible Duplicate: True random number generator I have worked with random functions in python,ruby,
Possible Duplicate: how to parse hex or decimal int in Python i have a
Possible Duplicate: Converting unix timestamp string to readable date in Python I have a
I have an app that creates Python code and runs it. During this process
Possible Duplicate: Upgrade python without breaking yum I'm running a Redhat VM (2.6.18-274.el5 64

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.