Font size
Worksheetsdictionary
Total questions: 16
Worksheet time: 11mins
以下哪个选项是一个字典
x = ('apple', 'banana', 'cherry')
x = {'type' : 'fruit', 'name' : 'banana'}
x = ['apple', 'banana', 'cherry']
词典创建后,词典条目就无法删除。
对
错
字典不能有两个同名的键。
对
错
您可以通过引用键名来访问字典项。
对
错
使用该get方法打印字典中“model”键的值car。
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
print( (a) )
考虑以下代码:打印结果是什么?
x = {'type' : 'fruit', 'name' : 'banana'}
print(x['type'])
banana
fruit
type = 'fruit'
考虑以下代码
x = {'type' : 'fruit', 'name' : 'banana'}
哪个代码可以把fruit改为berry
x{'type'} = 'berry'
x['type'] = 'berry'
x.get('type') = 'berry'
将“year”值从 1964 更改为 2020。
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
(a) =2020
考虑以下代码:
x = {'type' : 'fruit', 'name' : 'banana'}
下列哪个代码可以正确的将name键的值从banana改为apple
x.update({'name': 'apple'})
x.update('name' = 'apple')
x.update('name','apple')
以下哪一种字典方法可用于向字典中添加项目?
add()
insert()
update()
为字典添加一个键/值分别为"color"="red"
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
(a)
下面哪个方法可以在字典里面移除一个元素
delete()
remove()
pop()
使用pop方法移除在car字典里的"model"键
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
(a)
使用empty方法清空字典
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }
(a)
考虑以下代码:
a = {'name' : 'John', 'age' : '20'}
b = {'name' : 'May', 'age' : '23'}
customers = {'c1' : a, 'c2' : b}
下面哪个语句的输出是May
一个字典只能有一个级别的嵌套字典。
错
对
