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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:59:12+00:00 2026-06-11T12:59:12+00:00

For functions with closely related formal parameters, such as def add_two_numbers(n1, n2): return n1

  • 0

For functions with closely related formal parameters, such as

def add_two_numbers(n1, n2):
    return n1 + n2

def multiply_two_numbers(n1, n2):
    return n1 * n2

Is it a good idea to give the same names to the parameters in both functions, as shown above?

The alternative is to rename the parameters in one of the functions. For example:

def add_two_numbers(num1, num2):
    return num1 + num2

Keeping them the same in both functions looks more consistent since the parameters each one takes are analogous, but is that more confusing?

Similarly, which would be better for the example below?

def count(steps1, steps2):
    a = 0
    b = 0

    for i in range(steps1):
        a += 1

    for j in range(steps2):
        b += 1

    return a, b

def do_a_count(steps1, steps2):
    print "Counting first and second steps..."
    print count(steps1, steps2)

Otherwise, changing the arguments in the second function gives:

def do_a_count(s1, s2):
    print "Counting first and second steps..."
    print count(s1, s2)

Again, I’m a little unsure of which way is best. Keeping the same parameter names makes the relation between the two functions clearer, while the second means there is no possibility of confusing parameters in the two functions.

I have done a bit of searching around (including skimming through PEP-8), but couldn’t find a definitive answer. (Similar questions on SO I found included:
Naming practice for optional argument in python function
and
In Python, what's the best way to avoid using the same name for a __init__ argument and an instance variable?)

  • 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-11T12:59:13+00:00Added an answer on June 11, 2026 at 12:59 pm

    I would keep the names the same unless you have a good reason to use different names … Remember that even positional arguments can be called by keywords, e.g.:

    >>> def foo(a,b):
    ...     print a
    ...     print b
    ... 
    >>> foo(b=2,a=1)
    

    Keeping the “keywords” the same helps in that rare, but legal corner case …

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

Sidebar

Related Questions

PHP has 2 closely related functions, escapeshellarg() and escapeshellcmd() . They both seem to
PHP functions such as 'array_map' take a callback, which can be a simple function
Many functions in c take pointer to constant strings/chars as parameters eg void foo(const
This is part of a series of at least two closely related, but distinct
This is part of a series of at least two closely related, but distinct
Further delving into the mysteries of R evaluation...This is closely related to my previous
Concatenative languages have some very intriguing characteristics, such as being able to compose functions
Closely related to this question: Bash printf prefix I have the following Bash script
My question is closely related to how a DLL exports C++ classes and generic
This question is closely related to this one but i think is more general.

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.