hash() Hash of object

Last updated: 2026-09-22

hash() Hash of object

hash() returns the integer hash of a hashable object; a is b implies hash(a) == hash(b).

CategoryBuilt-in Functions
KindBuilt-in Function
Python Versionall

📝 Syntax

hash(object)

⚙️ Parameters

object RequiredThe object to hash; it must be hashable.

Returns:The integer hash of the object; equal objects always hash equal.

💥 Raises

▶ Example

Edit the code, press Run, and see the result in the output panel:

Output:

529344067295497451
ℹ️ Info Immutable containers are hashable; list / set / dict are not.
More case studies coming soon — check back later.

❓ FAQ

QWhy does hash([1, 2]) raise a TypeError?
AA list is mutable — its contents can change — so its hash cannot be stable, hence it is unhashable. The same applies to dict and set.
QWhich objects are hashable?
AImmutable types are usually hashable: int, float, str, bytes, tuple, frozenset, None, etc. Note that a tuple containing a list is not hashable either.
QDo equal objects always have the same hash?
AAlways in one direction: if a == b then hash(a) == hash(b). But the reverse is not guaranteed — different objects may collide on the same hash (equal hash does not imply equality).
QDoes hash('abc') stay the same each time I run the program?
ANot necessarily. String hashing is randomized by default (PYTHONHASHSEED), so it is not stable across processes; do not use hash values for persistence or cross-process passing.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏