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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:39:44+00:00 2026-05-31T22:39:44+00:00

In Python I can define a function as follows: def func(kw1=None,kw2=None,**kwargs): … In this

  • 0

In Python I can define a function as follows:

def func(kw1=None,kw2=None,**kwargs):
   ...

In this case, I can call func as:

func(kw1=3,kw2=4,who_knows_if_this_will_be_used=7,more_kwargs=Ellipsis)

I can also define a function as:

def func(arg1,arg2,*args):
    ...

which can be called as

func(3,4,additional,arguments,go,here,Ellipsis)

Finally, I can combine the two forms

def func(arg1,arg2,*args,**kwargs):
    ...

But, what does not work is calling:

func(arg1,arg2,*args,kw1=None,kw2=None,**kwargs):  #SYNTAX ERROR (in Python 2 only, apparently this works in Python 3)
    ...

My original thought was that this was probably because a function

def func(arg1,arg2,*args,kw1=None):
    ...

can be called as

func(1,2,3)  #kw1 will be assigned 3

So this would introduce some ambiguity as to whether 3 should be packed into args or kwargs. However, with Python 3, there is the ability to specify keyword only arguments:

def func(a,b,*,kw=None):  # can be called as func(1,2), func(1,2,kw=3), but NOT func(1,2,3)
    ...

With this, it seems that there is no syntactic ambiguity with:

def func(a,b,*args,*,kw1=None,**kwargs):
    ...

However, this still brings up a syntax error (tested with Python3.2). Is there a reason for this that I am missing? And, is there a way to get the behavior I described above (Having *args with default arguments) — I know I can simulate that behavior by manipulating the kwargs dictionary inside the function.

  • 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-31T22:39:45+00:00Added an answer on May 31, 2026 at 10:39 pm

    You can do that in Python 3.

    def func(a,b,*args,kw1=None,**kwargs):
    

    The bare * is only used when you want to specify keyword only arguments without accepting a variable number of positional arguments with *args. You don’t use two *s.

    To quote from the grammar, in Python 2, you have

    parameter_list ::=  (defparameter ",")*
                        (  "*" identifier [, "**" identifier]
                        | "**" identifier
                        | defparameter [","] )
    

    while in Python 3, you have

    parameter_list ::=  (defparameter ",")*
                        (  "*" [parameter] ("," defparameter)*
                        [, "**" parameter]
                        | "**" parameter
                        | defparameter [","] )
    

    which includes a provision for additional parameters after the * parameter.

    UPDATE:

    Latest Python 3 documentation here.

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

Sidebar

Related Questions

I want to define a function that call imagemagick to convert an image. def
Do I have to formally define a function before I can use it as
I have a python function defined as follows which i use to delete from
In Python I can define a class 'foo' in the following ways: class foo:
In python, I defined a class 'number'. Now I wish to define a function
how do I define decimal range between 0 to 1 in python? Range() function
In python you can define a object having __getattr__(self,key) method to handle all unknown
How can I define a multi-statement function or procedure in using the MySQLdb lib
In python, you can have a function return multiple values. Here's a contrived example:
If I am creating my own class in Python, what function should I define

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.