wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

dictionary

Total questions: 16

Worksheet time: 11mins

Name
Class
Date
1.

以下哪个选项是一个字典

a)

x = ('apple', 'banana', 'cherry')

b)

x = {'type' : 'fruit', 'name' : 'banana'}

c)

x = ['apple', 'banana', 'cherry']

2.

词典创建后,词典条目就无法删除。

a)

b)

3.

字典不能有两个同名的键。

a)

b)

4.

您可以通过引用键名来访问字典项。

a)

b)

5.

使用该get方法打印字典中“model”键的值car。

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

print( (a)   )

6.

考虑以下代码:打印结果是什么?

x = {'type' : 'fruit', 'name' : 'banana'}
print(x['type'])

a)

banana

b)

fruit

c)

type = 'fruit'

7.

考虑以下代码

x = {'type' : 'fruit', 'name' : 'banana'}

哪个代码可以把fruit改为berry

a)

x{'type'} = 'berry'

b)

x['type'] = 'berry'

c)

x.get('type') = 'berry'

8.

将“year”值从 1964 更改为 2020。

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

(a)   =2020

9.

考虑以下代码:

x = {'type' : 'fruit', 'name' : 'banana'}

下列哪个代码可以正确的将name键的值从banana改为apple

a)

x.update({'name': 'apple'})

b)

x.update('name' = 'apple')

c)

x.update('name','apple')

10.

以下哪一种字典方法可用于向字典中添加项目?

a)

add()

b)

insert()

c)

update()

11.

为字典添加一个键/值分别为"color"="red"

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

(a)  

12.

下面哪个方法可以在字典里面移除一个元素

a)

delete()

b)

remove()

c)

pop()

13.

使用pop方法移除在car字典里的"model"键

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

(a)  

14.

使用empty方法清空字典

car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

(a)  

15.

考虑以下代码:

a = {'name' : 'John', 'age' : '20'}
b = {'name' : 'May', 'age' : '23'}
customers = {'c1' : a, 'c2' : b}

下面哪个语句的输出是May

a)

print(customers['c2']['name']

b)

print(customers.c2.b['name']

16.

一个字典只能有一个级别的嵌套字典。

a)

b)