In the following example Python uses the same integer object in the memory for all three names x, y and z in the namespace
def main():
x = 0
y = 0
z = 0
print(x,y,z)
print(x is y is z)
y = 2
print(x,y,z)
print(x is y)
print(z is y)
print(x is z)
if __name__ == "__main__":main()
Output:
0 0 0
True
0 2 0
False
False
True
Why Python doesn't use the same tuple object here ( yes it is the choice of language designers but why) and a better questin to ask is when python creates new objects in memory
def main():
a = 1, 2, 3
b = (1, 2, 3)
c = 1, 2, 3
print(type(a) == type(b))
print(a == b)
print(a is b)
print(a == c)
print(a is c)
if __name__ == "__main__":main()
Output:
True
True
False
True
False