身份運算子

  1. 身份(identity)運算子,身份運算子用於比較是否相同物件(objects),而不是比較物件是否相等。x 跟 y 兩個串列內容都一樣,但不是同一個串列,所以 x is y 回傳 False, x == y 回傳 True,z 跟 x 是同一個串列,所以 x is z 回傳 True。
    [dywang@kvm8 10827000]$ python3
    Python 3.6.8 (default, Mar 19 2021, 05:13:41)
    [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> x=["abc",123]
    >>> y=["abc",123]
    >>> x is y
    False
    >>> x == y
    True
    >>> z=x
    >>> x is z
    True
    >>> quit()