I am trying to check if an object is of type None before checking its length. To do this, I made an if statement with the or operator:
if (cts is None) | (len(cts) == 0): return
As far as I can tell, the cts object will be checked if it is None, and if so, the length check will not be performed. However, the following error occurs if cts is None:
TypeError: object of type 'NoneType' has no len()
Does python check both expressions in an if statement, even if the first is true?
python if-statement nonetype
Alex blundell
source share