What is the difference between hash() and id() in Python?

88 views

What is the difference between hash() and id() in Python?

What is the difference between hash() and id() in Python?

solveurit24@gmail.com Changed status to publish February 13, 2025
0
  • hash(): Returns the hash value of an object (used for dictionary keys).
  • id(): Returns the memory address of an object.

my_var = "Hello"
print(hash(my_var))  # Output: Some hash value
print(id(my_var))    # Output: Memory address (e.g., 140464720949648)

solveurit24@gmail.com Changed status to publish February 13, 2025
0