Is it ok to skip “return None”?

后端 未结 7 1658
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 07:05

    Like you said, return None is (almost) never needed.

    But you should consider that the intention of your code is much clearer with an explicit return None. Remember: a piece of code also needs to be readable by human-beings, and being explicit usually helps.

提交回复
热议问题