Built-in Functions and Types

hash()

Obtain the integer hash used by hash-based collections. Equal hashable objects must have equal hashes, but unequal objects may collide. Lists and dictionaries are unhashable. Custom classes can define __hash__ alongside compatible equality; overriding equality without a hash normally makes instances unhashable. Hashes of strings and bytes are salted by default and should not be stored as stable identifiers or used for cryptography.

Formal Syntax & Structure

python syntaxpython
hash(object, /)

Parameters & Attributes

NameTypeDescription
objecthashable objectValue supporting the hash protocol.

Return Value

int

Hash value, not a unique identifier or cryptographic digest.

Working Example

Example Snippetpython
print(hash(1) == hash(1.0))print(hash((2, 3)) == hash((2, 3)))print({1: "yes"}[True])
Python Reference