Is it ok to skip “return None”?

后端 未结 7 1662
Happy的楠姐
Happy的楠姐 2020-12-03 06:17

I wonder if it is bad manner to skip return None, when it is not needed.

Example:

def foo1(x):
    if [some condition]:
        return B         


        
7条回答
  •  生来不讨喜
    2020-12-03 06:57

    def foo1(x):
        try:
            return Baz(x)
        except:
            raise ValueError('Incorrect value fo Bac')
    

    or

    def foo3(x):
        return Baz(x) if  else False
    

    I do not believe in half defined function, but this False can be usefull in search type failure pruning.

提交回复
热议问题