python哈希函数等价

2024-09-27 00:12:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图找到与python哈希函数等价的Go:

hash("test")

我发现this post是一个非常类似的函数,它返回一个整数,然而,它使用了fnv,这似乎是一个不同于python version的散列方法

我要做的是把一个字符串传递给hash函数,这样它在两种语言中为同一个字符串返回完全相同的整数。你知道吗


Tags: 方法函数字符串test语言goversion整数
1条回答
网友
1楼 · 发布于 2024-09-27 00:12:03

By default, the __hash__() values of str, bytes and datetime objects are “salted” with an unpredictable random value. Although they remain constant within an individual Python process, they are not predictable between repeated invocations of Python.

在Python脚本的不同调用之间会得到不同的数字。所以我觉得你想要什么都不可能。你知道吗

资料来源:https://docs.python.org/3.5/reference/datamodel.html#object.__hash__

相关问题 更多 >

    热门问题