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.
我经常使用以下结构:
try: x = d[i] except KeyError: x = '?'
有时,插入“?” 我使用 0 或None. 我不喜欢这种结构。它太冗长了。有没有更短的方法来做我所做的事情(就在一行中)。就像是。
None
x = get(d[i],'?')
你正在寻找这个:
x = d.get(i, '?')