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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:40:05+00:00 2026-05-18T04:40:05+00:00

Please see the code below:- #!/usr/bin/python # Filename: total.py def total(initial=5, *numbers, **keywords): count

  • 0

Please see the code below:-

#!/usr/bin/python
# Filename: total.py

def total(initial=5, *numbers, **keywords):
    count = initial
    for number in numbers:
        count += number
    for key in keywords:
        count += keywords[key]
    return count

print(total(10, 1, 2, 3, vegetables=50, fruits=100))

Can someone please explain how is *numbers and **keywords picking up the arguments?
A simple explaination is very much appreciayed
Thanks in advance

  • 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-18T04:40:06+00:00Added an answer on May 18, 2026 at 4:40 am

    In your code numbers is assigned the (1,2,3) tuple. keywords is assigned a dictionary, containing vegetables and fruits.

    One star (*) defines positional arguments. This means that you can receive any number of arguments. You can treat the passed arguments as a tuple.

    Two stars (**) define keywords arguments.

    The reference material is available here.

    Examples

    Python 2.x (before keyword-only arguments)

    def foo(x, y, foo=None, *args): print [x, y, foo, args]
    
    foo(1, 2, 3, 4)            --> [1, 2, 3, (4, )]  # foo == 4
    foo(1, 2, 3, 4, foo=True)  --> TypeError
    

    Python 3.x (with keyword-only arguments)

    def foo(x, y, *args, foo=None): print([x, y, foo, args])
    
    foo(1, 2, 3, 4)           --> [1, 2, None, (3, 4)]  # foo is None
    foo(1, 2, 3, 4, foo=True) --> [1, 2, True, (3, 4)]
    
    def combo(x=None, *args, y=None): ...  # 2.x and 3.x styles in one function
    

    Although a seasoned programmer understands what happened in 2.x, it’s counter-intuitive (a positional argument gets bound to foo= regardless of keyword arguments as long as there are enough positional arguments)

    Python 3.x introduces more intuitive keyword-only arguments with PEP-3102 (keyword arguments after varargs can only be bound by name)

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

Sidebar

Related Questions

Please see code below. The destructors are never called. Anyone know why and how
Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
Please see my code below. ifstream myLibFile (libs//%s , line); // Compile failed here
Please see the code below. I expect it to print either 10 because I
I'm trying to create a dynamic ItemizedOverylay (please see the code below) on Google
I am using vb.net code. I have grid view, please see the code below:
I am using struts 2.1.6 with ONGL. Please see the code below and tell
Please see code below. DeviceDAO, Device, and Mobileuser are hibernate generated objects. the process
Does GWT has LazyPanel .I can not see it .Please let me know .If
Please suggest some good resources to start writing Java Web services.

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.