Python內置函數(28)——hash


英文文檔:

hash(object)Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0).

 

說明:  

  1. 返回對象的哈希值,用整數表示。哈希值在字典查找時,可用於快速比較鍵的值。

>>> hash('good good study')
1032709256

  2. 相等的數值,即使類型不一致,計算的哈希值是一樣的。

>>> 1.0 == 1
True
>>> hash(1.0)
1
>>> hash(1)
1
>>> hash(1.0000)
1

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM