Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
python - Get input argument's name of function

How can I get name of input argument in function?

Here is example

a=1
b=2
c=3
def test(x):
    print(?)

test(b)

and result should be

b

I think this is easy problem...? But not to me :)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Due to the fact that multiple variables can have the same value, the below function returns a list of all the variable names that holds the value passed in as argument:

a = 1
b = 2
c = 3
def test(x):
    print([k for k, v in globals().items() if v == x])

test(b)

Output:

['b']

Of course, you can always return after the first occurrence of a match:

a = 1
b = 2
c = 3
def test(x):
    for k, v in globals().items():
        if v == x:
            return print(k)

test(b)

Output:

b
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!