Setting the default value of a function input to equal another input in Python

后端 未结 3 1613
天涯浪人
天涯浪人 2021-02-05 07:13

Consider the following function, which does not work in Python, but I will use to explain what I need to do.

def exampleFunction(a, b, c = a):
    ...function bo         


        
3条回答
  •  既然无缘
    2021-02-05 07:31

    One approach is something like:

    def foo(a, b, c=None):
        c = a if c is None else c
        # do something
    

提交回复
热议问题