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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:21:10+00:00 2026-06-17T12:21:10+00:00

This example is taken from Beazley, Python Essential Reference 4e, pg:101. How is he

  • 0

This example is taken from Beazley, Python Essential Reference 4e,
pg:101.

How is he doing:

func(*args, **kwargs)

where ‘func’ is the square-function which takes 1 argument. Earlier in
the chapter he sqawks about how the position and number of arguments
must match in a call/definition or a TypeError would be raised.

Also,

@trace
def square(x):
    ...
square = trace(square)

trace returns ‘callf’ so this is equivalent to writing: square = callf
which is fine because since square refers to a new-function-object, you can
call it with *args, **kwargs. But, then in callf he does func(*args...

Given that we just made ‘square’ refer to some other object, how is
the original square accessible inside? What mechanism is coming into
play?

@trace
def square(x):
    return x*x

enable_tracing = True
if enable_tracing:
    debug_log = open("debug.log","w")

def trace(func):
    if enable_tracing:
        def callf(*args,**kwargs):
            debug_log.write("Calling %s: %s, %s\n" % 
                (func.__name__, args, kwargs))
            r = func(*args,**kwargs) #????????
            debug_log.write("%s returned %s\n" % (func.__name, r))
            return r
        return callf
    else:
        return func
  • 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-17T12:21:11+00:00Added an answer on June 17, 2026 at 12:21 pm

    The *-prefix means, “Use this sequence of values as the positional parameters to the function.” The **-prefix means, “Use this dictionary as the named parameters to the function.” If the sequence is empty, then no positional parameters are passed. If the dictionary is empty, then no named parameters are passed.

    When you define a function with those prefixes, then the unaccounted for positional parameters go into the *-prefixed argument, and the unaccounted for named parameters go into the **-prefixed argument. So if you define a function like this:

    def wrapper(*args, **kwargs):
    

    then the function can be invoked with any arguments whatsoever. If that function then calls another function with those arguments, then it will be called however the wrapper was called.

    Note that you can call a function with (*args, **kwargs) even if wasn’t defined that way:

    >>> def square(x):
    ...     return x*x
    ...
    >>> args = (10,)
    >>> kwargs = {}
    >>> square(*args, **kwargs)
    100
    

    Because kwargs is empty, there are no named parameters passed to the function. It gets only the one positional arguments in args.

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

Sidebar

Related Questions

Given this example taken from http://php.net/manual/en/function.crypt.php crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') Firstly: What is the length that
The following example is taken from: http://php.net/manual/en/function.curl-multi-close.php#example-3540 This example will create two cURL handles,
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT
I have taken this example from net . But when i tried it is
The ListNode example , taken from Scalas homepage goes like this: case class ListNode[+T](h:
This example is taken from the Java programming book; 4th Edition. After stumbling upon
Can anyone please explain this code? This example is taken from javascript.info. I don't
this is an example taken from Effective C++ 3ed , it says that if
this is an example taken from Effective C++ 3ed , it says that if
I'm trying to use this code which is an example taken from here https://gist.github.com/2383248

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.