Python check multiple variables for none


I have multiple variables in my python script.

I would like to check if any variable is None out of my variables.

Following are my variables:

a = 'a'
b = 'b'
c = None

Python has a built in method called “all” which return True if all elements of the iterable are true (or if the iterable is empty).

So here I am using all method to check if any declared variables are None. I am using following code:

print all([a, b, c])



print all([a, b])



If we observe above two print statements with all method, first statement output is False since variable c is None and second statement output is True since variables a and b are not None.

One comment on “Python check multiple variables for none

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s