Difference between “if x” and “if x is not None”

后端 未结 5 1019
萌比男神i
萌比男神i 2020-12-04 23:32

It appears that \"if x\" is almost like short-hand for the longer \"if x is not None\" syntax. Are they functionally identical or are there cases where for a given value of

5条回答
  •  广开言路
    2020-12-05 00:11

    The former tests trueness, whereas the latter tests for identity with None. Lots of values are false, such as False, 0, '', and None, but only None is None.

提交回复
热议问题