Re: [問題] membership test
※ 引述《huggie (huggie)》之銘言:
: 我自訂了一個 class ..裡面有個 dictionary 的 member
: 對 dictionary inheritance 不熟,貪快所以直接用包的。
: __getitem__ 可以用來做 index
: 我就用來 proxy (是這樣稱呼嗎) 裡面的那個 dictionary
: 但是 membership test 好像不能用 (例如 'xxx' in dic)
: 明明沒有在 dictionary 裡面居然 pass 了
: 請問要怎麼用?
http://docs.python.org/ref/comparisons.html
For user-defined classes which define the __contains__() method, x in y is
true if and only if y.__contains__(x) is true.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.143.225.229
推
03/31 23:03, , 1F
03/31 23:03, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章