Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
说如果我有以下情况:
mydict = { a: 'A' }
如何检查a字典中是否存在密钥?伪代码如下:
a
%if 'a' in mydict.keys() ${mydict['a']} %endif
您可以使用in:
in
from mako.template import Template t = Template(""" % if key in d: key is in dictionary % else: key is not in dictionary % endif """) print t.render(key='a', d={'a': 'A'}) # prints "key is in dictionary"