Is it right to check if the argument value is part of a certain range of values?

I use the following "assert" to check the value of an argument in a function. I have a function "test" that accepts a logical input "arg1", which can be None, True or False. Is it ok to make sure "arg1" is only one of these possible values?

   def test(arg1=None):
       assert arg1 in set([None, True, False]), "Not a valid input"
...

My friend tells me the following:

I can’t do it. You must compare True, False, and None as identifiers (is not =). Doing in is equivalent to multiple = 's. You must support separate files.

It is right?

+4
source share
2 answers

None; , , "" ( ).

True False, , . , in , , bool(), .

, :

.

, , .

+4

, "is". , "in" . :

a = [0, 1]
False in a
>> True
a[0] is False
>> False

- 0, . .

+4

All Articles