Python-测验| Python词典测验 |问题 11
问题 11:求以下程序的输出:
dictionary = {'GFG' : 'geeksforgeeks.org',
'google' : 'google.com',
'facebook' : 'facebook.com'
}
del dictionary['google'];
for key, values in dictionary.items():
print(key, end=" ")
dictionary.clear();
for key, values in dictionary.items():
print(key)
del dictionary;
for key, values in dictionary.items():
print(key)
(A) B 和 D
(B) GFG 脸书
(C)脸书 GFG
(D) NameError: name 'dictionary' 未定义
答案:(一)
说明:语句:del字典;删除整个字典,因此迭代已删除的字典会引发运行时错误,如下所示:
Traceback (most recent call last):
File “cbeac2f0e35485f19ae7c07f6b416e84.py”, line 12, in
for key, values in dictionary.items():
NameError: name ‘dictionary’ is not defined
这个问题的测验