jeudi 5 août 2021

Check for word in an integer variable's name passed in a function

I have a question regarding how to check the name of the argument passed in a function and use it for a condition. Let's say I have:

def something(A,B):
  do_something = A + B
  if 'bla' in A:
    do_something = (A+B)*2
  else:
    do_something = do_something*10
  return do_something

Then I call the function:

x = something(bla_result,some_result)

Is this possible in python? Considering that I am not entering a string as an argument, but a variable type int. I would like the function to assess the name of the variable and do something depending on what is present in the name.

Any suggestions are greatly appreciated!

Thanks

Aucun commentaire:

Enregistrer un commentaire