Differentiate false and 0

I have a stupid question. Suppose I have a list with different values. Like this:

[1,2,3,'b', None, False, True, 7.0]

And I want to iterate over it and check that each element is not in the list of some forbidden values. For example, this list [0,0.0].

And when I check False in [0,0.0], I get True. I understand that python distinguishes Falseup to 0here. But how can I avoid this and make this check correct - that the value is Falsenot in the list [0,0.0]?

+4
source share
2 answers

False 0, is . False . , , False, :

all(x is not False for x in a_list)

BTW, Python : Booleans - , False 0, .

+8

is == .

y = 0
print y == False # True
print y is False # False

x = False
print x == False # True
print x is False # True
+1

Source: https://habr.com/ru/post/1660986/


All Articles