美文网首页程序员《做与学系列》
疯狂的Python-10(is not ...` 并不是 `i

疯狂的Python-10(is not ...` 并不是 `i

作者: 景行1023 | 来源:发表于2018-09-08 11:59 被阅读2次

    is not ... 并不是 is (not ...)

    >>> 'something' is not None
    True
    >>> 'something' is (not None)
    False
    

    :bulb: 解释

    • is not 是一个单独的二元运算符, 和分开使用的isnot作用是不同的。
    • is not 只有在两边的操作数相同时(id相同)结果才为False,否则为True

    is not ... 并不是 is (not ...)

    >>> 'something' is not None
    True
    >>> 'something' is (not None)
    False
    

    :bulb: 解释

    • is not 是一个单独的二元运算符, 和分开使用的isnot作用是不同的。
    • is not 只有在两边的操作数相同时(id相同)结果才为False,否则为True

    相关文章

      网友评论

        本文标题:疯狂的Python-10(is not ...` 并不是 `i

        本文链接:https://www.haomeiwen.com/subject/pzogwftx.html