2024-05-19 09:48:52 发布
网友
如果我有:
map = { 'stack':'overflow' } try: map['experts-exchange'] except: <--- What is the Exception type that's thrown here? print( 'is not free' )
在网上找不到。=(一)
它被称为键错误
>>d={1:2} >>d[2] Traceback (most recent call last): File "<stdin>", line 1, in ? KeyError: 2
KeyError。
KeyError
>>> x = {'try': 1, 'it': 2} >>> x['wow'] Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> x['wow'] KeyError: 'wow'
如果你在控制台上不使用try块,就会告诉你
>>> a = {} >>> a['invalid'] Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 'invalid' >>>
它被称为键错误
KeyError
。如果你在控制台上不使用try块,就会告诉你
相关问题 更多 >
编程相关推荐