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

后端 未结 5 1567
名媛妹妹
名媛妹妹 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 19:55

    There's nothing wrong with the way you're doing it.

    If you have a lot of variables, you could put them in a list and use all:

    if all(v is not None for v in [A, B, C, D, E]):
    

提交回复
热议问题