What is the most pythonic way to check if multiple variables are not None?

后端 未结 5 1572
名媛妹妹
名媛妹妹 2021-01-30 19:48

If I have a construct like this:

def foo():
    a=None
    b=None
    c=None

    #...loop over a config file or command line options...

    if a is not None an         


        
5条回答
  •  面向向阳花
    2021-01-30 20:18

    Writing a separate answer as I do not know how to format code when added as a comment.

    Eternal_N00B's solution is not same as Daniel Roseman's solution. Consider for example:

    >>> all(v is not None for v in [False])
    True
    >>> all([False])
    False
    

提交回复
热议问题