Write a Python program to prove that two string variables of the same value point to the same memory location.

Write a Python program to prove that two string variables of the same value point to the same memory location.

1
2
3
4
5
6
str1 = "Python"
str2 = "Python"
 
print("\nMemory location of str1 =", hex(id(str1)))
print("Memory location of str2 =", hex(id(str2)))
print()

Final output

Leave a Comment