0

The answer should be very easy and should have been answer already, but I cannot find it.

()           is None # False
(None)       is None # True
(None, None) is None # False

Results of all of these checks are kind of expected, but altogether looks strange. So to questions:

  1. Why is (None) is None - is it because of unpacking?
  2. Why then () is not None? I.e. if (None) is already None why () is not?
Xronx
  • 1,160
  • 7
  • 23

2 Answers2

2
() is not None

because () is an empty tuple, not None.

(None, None) is not None

because (None, None) is a tuple with two None elements, which is obviously not the same as one None element.

(None) is None

because (None) is not at tuple. These kind of brackets are used to indicate mathematical groupings/computation orders, and can be left out in this case, resulting in None is None.

(None,) is not None

which is probably what you were trying to create, a tuple with one None element.

Finomnis
  • 18,094
  • 1
  • 20
  • 27
0
  1. Because putting parentheses around and expression does not change its value.

  2. Why should it be None? () is actually an empty tuple.

Stop harming Monica
  • 12,141
  • 1
  • 36
  • 56