Search code examples
pythonassert

Python assert all elements in list is not none


I was wondering if we could assert all elements in a list is not None, therefore while a = None will raise an error.

The sample list is [a, b, c]

I have tried assert [a, b, c] is not None, it will return True if any one of the elements is not None but not verifying all. Could you help figure it out? Thanks!!


Solution

  • Unless you have a weird element that claims it equals None:

    assert None not in [a, b, c]