When hash() method is called in Python 3, I noticed that it doesn't return a long-length integer when taking in int data type but with string type.
Is this supposed to work this way? If that actually is the case, for the int type to have a short hash value, won't it cause collision since it's too short?
for i in [i for i in range(5)]:
print(hash(i))
print(hash("abc"))
The Result:
0
1
2
3
4
4714025963994714141
hashdoes is implementation-dependent; don't make any assumptions about what it returns.hashis not a cryptographic hash. if you are interested in those usehashlib. the built-inhashis just about unique identifiers.a long-length integerisn't code, it's English prose; likewise forshort hash value. If you want to emphasize prose, italics are usually the right choice. See Highlighting technical words? on Meta Stack Exchange.