0

I having a confusion in python is keyword

a=3
b=3
print(a is b)

This above code will print True.

Meanwhile,

a=[3,3]
b=[3,3]
print(a is b)

This code will print False.

And I know is compare object reference

Can anyone can explain in detail or provide the link of documentation, how memory allocation and memory reference implemented in python ???? And explain how these two programs are different??

  • 1
    https://nedbatchelder.com/text/names.html – 001 Oct 14 '22 at 14:54
  • Python's semantics require that distinct instances of the *mutable* type `list` be created for `a` and `b`. Since `int` values are *immutable*, it's an implementation detail whether or not the same object is produced by the two uses of the literal `3`. – chepner Oct 14 '22 at 15:02

0 Answers0