我想了解函数中定义的以下代码行

I want to understand the following code lines defined in the function

我是 python 和机器学习的初学者。在做书 "hands-on ML with sci-kit learn and TF" 中的一个项目时,我遇到了这种使用 hashlib 创建测试集的方法。 你能帮我理解一下return语句的逻辑吗,一步一步-

def test_set_check(identifier, test_ratio, hash):
    return hash(np.int64(identifier)).digest()[-1]<256 * test_ratio

假设 hash 来自 hashlib:

  • identifier 转换为 (numpy) 64 位整数
  • 散列演员表 identifier
  • 从散列
  • 中获取最后字节的值
  • 将该值与 (256 * test_ratio)
  • 进行比较
  • return 比较结果