0

Is it possible to use a default variable based on previously passed positional arguments?

I'm trying to do something similar:

def ex(a, b=a+1):
    return a+b
Alex
  • 21
  • 3

1 Answers1

0

You can do that inside of the body, but not the signature.

def ex(a, b=None):
    if b is None:
       b=a+1
    return a+b
Alpa
  • 71
  • 1
  • 3