Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check None in multiples variables

Tags:

python

a = 'asd'
b = 'dsa'

if a is not None and b is not None:
    pass

there is any way to improve this segment of code?

Also tried:

if not (a is None, b is None):

if not (a, b is None):

Both are not working.

like image 304
user2983258 Avatar asked May 15 '26 22:05

user2983258


1 Answers

Use the in-built function all()

a = 'asd'
b = 'dsa'

print all([a,b])
#True

In case one or more of the variables is None It would produce False


So if you want to use this with some condition, The code would be:

a = 'asd'
b = 'dsa'

if all([a,b]):
    print 'All True!!!!'
#All True!!!!
like image 189
K DawG Avatar answered May 17 '26 12:05

K DawG