Skip to content
Advertisement

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

If I have a construct like this:

JavaScript

What is the preferred syntax in python to check if all variables are set to useful values? Is it as I have written, or another better way?

This is different from this question: not None test in Python … I am looking for the preferred method for checking if many conditions are not None. The option I have typed seems very long and non-pythonic.

Advertisement

Answer

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:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement