python - Why is operator giving different output for immutable objects? -



python - Why is operator giving different output for immutable objects? -

this question has reply here:

why comparing strings in python using either '==' or 'is' produce different result? 11 answers

the code "python" "python" returns true. why (1,2,3) (1,2,3) homecoming false? though both immutable objects, is operator evaluating differently. why?

the operators is , is not test object identity: x y true if , if x , y same object. x not y yields inverse truth value.

you can think of identity object’s address in memory. 2 tuple same index have different address ! and in case based on interpreter , above stuff in interpreter equal strings point 1 memory address

for improve understanding see below demo:

>>> a=(0,1) >>> b=a >>> b true >>> c=(0,1) >>> c false

python

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -