表白:笑一笑,十年少~
講解對(duì)象:python3可哈希對(duì)象
作者:融水公子 rsgz
Python3教程
可哈希:python內(nèi)置函數(shù)__hash__()得出哈希值,哈希值是一個(gè)整型值就表示對(duì)象可哈希。
實(shí)例:
tuple可哈希#!/usr/bin/python3
o = (1, 2, 3, 4, 5 )
print(o.__hash__())
# -5659871693760987716
list是不可哈希對(duì)象#!/usr/bin/python3
o = [1, 2, 3, 4, 5]
print(o.__hash__())
# TypeError: 'NoneType' object is not callable
string可哈希#!/usr/bin/python3
o = "rsgz"
print(o.__hash__())
# -7021297014993999516
number可哈希#!/usr/bin/python3
o = 100
print(o.__hash__())
# 100
dict不可哈希#!/usr/bin/python3
dict = {'Name': 'rsgz', 'Age': 20, 'Class': 'First'}
print(o.__hash__())
# TypeError: 'NoneType' object is not callable
集合不可哈希#!/usr/bin/python3
o = {'Tom', 'Jim', 'Mary', 'Tom', 'Jack', 'Rose'}
print(o.__hash__())
# TypeError: 'NoneType' object is not callable
數(shù)組不可哈希#!/usr/bin/python3
from array import array
o = array('i', [0, 1, 2, 3, 4, 6, 7, 8, 9, 100])
print(o)
print(o.__hash__())
# TypeError: 'NoneType' object is not callable
謝謝大家的支持!可以點(diǎn)擊我的頭像,進(jìn)入我的空間瀏覽更多文章呢。建議大家360doc[www.360doc.com]注冊(cè)一個(gè)賬號(hào)登錄,里面真的有很多優(yōu)秀的文章,歡迎大家的到來(lái)。
---
聯(lián)系客服