zoukankan      html  css  js  c++  java
  • Is there a difference between `==` and `is` in Python?

    There is a simple rule of thumb to tell you when to use == or is.

    • == is for value equality. Use it when you would like to know if two objects have the same value.
    • is is for reference equality. Use it when you would like to know if two references refer to the same object.
    >>> a = 500
    >>> b = 500
    >>> a == b
    True
    >>> a is b
    False

    注: 判断None的只能用xxx is None来做

    ref: http://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is-in-python

    https://segmentfault.com/q/1010000000150947

  • 相关阅读:
    Vue-发布订阅机制(bus)实现非父子组件的传值
    01. jupyter环境安装
    人工智能
    Javascript
    JavaScript
    MongoDB
    MongoDB
    人工智能
    Flask
    Flask
  • 原文地址:https://www.cnblogs.com/pinganzi/p/6225423.html
Copyright © 2011-2022 走看看