更新时间:2023-11-25 23:18:34
使用中的 operator: p>
Use the in
operator:
if b in a:
演示:
>>> a = {'foo': 1, 'bar': 2}
>>> 'foo' in a
True
>>> 'spam' in a
False
你真的想开始阅读Python教程, 词典部分涵盖了这个主题。
You really want to start reading the Python tutorial, the section on dictionaries covers this very subject.