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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:22:00+00:00 2026-05-15T03:22:00+00:00

In code like zip(*x) or f(**k) , what do the * and ** respectively

  • 0

In code like zip(*x) or f(**k), what do the * and ** respectively mean? How does Python implement that behaviour, and what are the performance implications?


See also: Expanding tuples into arguments. Please use that one to close questions where OP needs to use * on an argument and doesn’t know it exists. Similarly, use Converting Python dict to kwargs? for the case of using **.

See What does ** (double star/asterisk) and * (star/asterisk) do for parameters? for the complementary question about parameters.

  • 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-15T03:22:01+00:00Added an answer on May 15, 2026 at 3:22 am

    A single star * unpacks a sequence or collection into positional arguments. Suppose we have

    def add(a, b):
        return a + b
    
    values = (1, 2)
    

    Using the * unpacking operator, we can write s = add(*values), which will be equivalent to writing s = add(1, 2).

    The double star ** does the same thing for a dictionary, providing values for named arguments:

    values = { 'a': 1, 'b': 2 }
    s = add(**values) # equivalent to add(a=1, b=2)
    

    Both operators can be used for the same function call. For example, given:

    def sum(a, b, c, d):
        return a + b + c + d
    
    values1 = (1, 2)
    values2 = { 'c': 10, 'd': 15 }
    

    then s = add(*values1, **values2) is equivalent to s = sum(1, 2, c=10, d=15).

    See also the relevant section of the tutorial in the Python documentation.


    Similarly, * and ** can be used for parameters. Using * allows a function to accept any number of positional arguments, which will be collected into a single parameter:

    def add(*values):
        s = 0
        for v in values:
            s = s + v
        return s
    

    Now when the function is called like s = add(1, 2, 3, 4, 5), values will be the tuple (1, 2, 3, 4, 5) (which, of course, produces the result 15).

    Similarly, a parameter marked with ** will receive a dict:

    def get_a(**values):
        return values['a']
    
    s = get_a(a=1, b=2)      # returns 1
    

    this allows for specifying a large number of optional parameters without having to declare them.

    Again, both can be combined:

    def add(*values, **options):
        s = 0
        for i in values:
            s = s + i
        if "neg" in options:
            if options["neg"]:
                s = -s
        return s
            
    s = add(1, 2, 3, 4, 5)            # returns 15
    s = add(1, 2, 3, 4, 5, neg=True)  # returns -15
    s = add(1, 2, 3, 4, 5, neg=False) # returns 15
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is how I handle iPhone (and similar) devices [not… May 17, 2026 at 1:53 am
  • Editorial Team
    Editorial Team added an answer Your project build type must be 'Class Library' to generate… May 17, 2026 at 1:53 am
  • Editorial Team
    Editorial Team added an answer No, it's not possible as the client-side code can never… May 17, 2026 at 1:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to unzip a 14MB archive with PHP with code like this: $zip
One of the core steps in file compression like ZIP is to use the
So here's my problem. I have a python script that takes a zipfile and
I need to find the 5 nearest zip code of a zip code. For
I'm using monorail, activerecord, and jquery. I have a form with a zip code
UPDATED CODE TO LATEST ITERATION The following function consumes a webservice that returns address
are there any free web services out there that will detect the IP Address
We are doing some performance tests on our website and we are getting the
I have controls like Textbox, dropdown on my CustomerDetails.ascx partialview. Now can we do
My code: protected void Page_Load(object sender, EventArgs e) { String userHost = Request.UserHostName }

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.