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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:20:42+00:00 2026-05-28T14:20:42+00:00

I was wondering if the ‘a=a’, and ‘b=b’ can lead to problems/unexpected behaviour? code

  • 0

I was wondering if the ‘a=a’, and ‘b=b’ can lead to problems/unexpected behaviour? code works fine in the example.

def add_func(a=2,b=3):
   return a+b

a=4
b=5
answer = add_func(a=a, b=b)

Thanks

  • 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-28T14:20:43+00:00Added an answer on May 28, 2026 at 2:20 pm

    Not that I know of, although I’d love to be proved wrong.

    The formal language reference defines the lexical structure of a function call. The important bit is that it defines a “keyword_item” as identifier "=" expression. Also, here’s what it says about how the arguments to the call are interpreted:

    If keyword arguments are present, they are first converted to
    positional arguments, as follows. First, a list of unfilled slots is
    created for the formal parameters. If there are N positional
    arguments, they are placed in the first N slots. Next, for each
    keyword argument, the identifier is used to determine the
    corresponding slot (if the identifier is the same as the first formal
    parameter name, the first slot is used, and so on). If the slot is
    already filled, a TypeError exception is raised. Otherwise, the value
    of the argument is placed in the slot, filling it (even if the
    expression is None, it fills the slot). When all arguments have been
    processed, the slots that are still unfilled are filled with the
    corresponding default value from the function definition.

    This lists a few possible scenarios.

    In the simple case, like you mentioned, where there are two formal arguments (a and b), and if you specify the function call using keyword parameters like add_func(a=a, b=b), here’s what happens:

    1. Two slots are created to hold the parameters.
    2. Since you didn’t provide any positional arguments in the call (just keyword arguments), none of the slots are filled initially.
    3. Each of your keyword arguments are analyzed individually, and the identifier of your argument (the “a” in the a= part) is compared with all of the formal parameters names of the function (the names that were given the parameters when the function was defined, in our case, a and b).
    4. When a match occurs, the value of the keyword arguments (in this case, 4!) is used to fill the corresponding slot.
    5. This repeats until all keyword arguments are analyzed. If all slots aren’t filled, then Python tries to assign a default value to the remaining slots if one exists. If not, an error is raised.

    So, Python treats the “identifier” in a keyword argument completely differently. This is only true for keyword arguments, though; obviously, if you tried something like add_func(b, a), even though your parameters themselves are called b and a, this would not be mapped to the formal parameters in the function; your parameters would be backwards. However, add_func(b=b, a=a) works fine; the positions don’t matter as long as they are keyword arguments.

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

Sidebar

Related Questions

Wondering if anyone can help me understand how the localisation works with keywords. I
Wondering if anyone can help me with this annoying but trivial (in terms of
wondering how I can replace all special chars on my string like: hello this
Wondering if anyone can help me. I'm trying to put together a weekly photo
Wondering if anyone can assist.. I am adding some jquery to my site, but
Wondering if there is some preference I can set in excel so that when
Wondering what the point of if (self = [super ... in the following code
Wondering if anybody knows where I can find any high resolution pictures for iPhone,
Wondering if it's possible to print a carriage return without a line feed in
Wondering if someone can answer something that has stumped me. I have a Timer

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.