是的,您可以使用内置的
hashlib
模块或内置的 hash
函数。然后,对整数形式的哈希使用模运算或字符串切片运算来切掉最后八位数字:
>>> s = 'she sells sea shells by the sea shore'>>> # Use hashlib>>> import hashlib>>> int(hashlib.sha1(s).hexdigest(), 16) % (10 ** 8)58097614L>>> # Use hash()>>> abs(hash(s)) % (10 ** 8)82148974



