Python 'is' vs JavaScript ===

前端 未结 4 1478
一向
一向 2021-02-04 03:01

The Python use of \'is\' seems to be similar to JavaScript \'===\' but not quite.

Here they talk about exact instances: http://www.learnpython.org/en/Conditions

<
4条回答
  •  青春惊慌失措
    2021-02-04 03:37

    Python's is keyword compares references (and so is about identity) while === does a minimal amount of coercion (and is therefore concerned with equality, at least in the case of primitives) so they are different.

    As I understand it, things that are concerned with identity are concerned with uniqueness from the runtime's point of view (do these two variables point to the same address in memory) while equality is concerned with the uniqueness of the contents of the variables (are these two variables equivalent, regardless of where they are placed in memory relative to each other).

提交回复
热议问题