Python 3.1 快速導覽 - 內建函數 hash()

內建函數 (function) hasattr() ,回傳參數 (parameter) object 的雜湊值

函數描述
hash(object)回傳 object 的雜湊值


舉例示範如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Demo:
    def __init__(self, i):
        self.i = i
        self.x = "xxx"
        self.y = "yyy"
        self.z = "zzz"
     
    def __str__(self):
        return str(self.i)
          
    def hello(self):
        print("hello " + self.__str__())
 
print(hash(Demo(22)))
print(hash(Demo(22)))
print(hash(Demo(23)))
print(hash(22))
print(hash(22))
print(hash(23))
print(hash("22"))
print(hash("22"))
print(hash("23"))
 
# 《程式語言教學誌》的範例程式
# 檔名:hash.py
# 功能:示範 Python 程式
# 作者:張凱慶
# 時間:西元 2010 年 12 月


執行結果如下



中英文術語對照
函數function
參數parameter


內建函數




沒有留言: