Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell a python function received a default value or keyword parameter?

def func(a, b = 100):
  return a + b

func(a)
func(a,b = 100)

Is there any way to tell when func is called, b value 100 is taken from the default or keyword parameter?

like image 974
johnsam Avatar asked Dec 22 '22 01:12

johnsam


1 Answers

No, not as you've written your code. However, you can do:

def func(a, b=None):
    if b is None:
        b = 100
    return a + b
like image 88
Greg Hewgill Avatar answered Jan 31 '23 05:01

Greg Hewgill