首页 › 题库 › Python编程考级 › 4.3 访问值

Python编程二级 题库

共 6 道题 · 按题型筛选,点「查看答案」核对解析
1 单选题 适中 Python编程考级 ·Python编程二级 · 4.3 访问值

执行下列程序的结果为?( ) 

message1={'name':'Tom','age':14,'city':'London'}
for v in message1.values():
    print(v,end='')


A
Tom14London
B
nameageLondon
C
name:Tom
D
Tom
答案与解析
正确答案:A
这道题暂未补解析。
题目详情
2 单选题 适中 Python编程考级 ·Python编程二级 · 4.3 访问值

执行以下代码后输出的结果是?( )

d={1:'monkey',2:'panda',3:'bird',4:'fish'}
d[5]='sheep'
del d[3]
d[3]='dog'
print(d)


A
{1: 'monkey', 2: 'panda', 4: 'fish', 5: 'sheep', 3: 'cat'}
B
{1: 'monkey', 2: 'panda', 4: 'fish', 5: 'sheep', 3: 'dog'}
C
{1: 'monkey', 2: 'panda', 3: 'dog, 5: 'sheep', 4: 'duck'}
D
{1: 'monkey', 2: 'panda', 3: 'cat', 5: 'sheep', 4: 'duck'}
答案与解析
正确答案:B

d[5]='sheep' #{1: 'monkey', 2: 'panda', 3: 'bird', 4: 'fish', 5: 'sheep'} del d[3] #{1: 'monkey', 2: 'panda', 4: 'fish', 5: 'sheep'} d[3]='dog'#{1: 'monkey', 2: 'panda', 3: 'dog', 5: 'sheep'} d[3]='dog'#{1: 'monkey', 2: 'panda', 4: 'fish', 5: 'sheep', 3: 'dog'}

题目详情
3 单选题 适中 Python编程考级 ·Python编程二级 · 4.3 访问值

已知列表animal = ['cat','dog','monkey','tiger','lion'],要想得到'cat'的输出结果,以下哪个选项的语句是不正确的?( )

A

animal[0]

B

animal[1]

C

animal.reverse()

animal[4]

D

animal.reverse()

animal[-1]

答案与解析
正确答案:B

列表元素的索引是从0开始的,所以获取第一个元素’cat’需用animal[0]而不是animal[1];reverse()方法的作用是将列表中的元素反转,animal列表反转后,第一个元素’cat’变成了最后一个元素,可以通过索引值4或者逆序索引值-1进行访问。所以本题答案为B。

题目详情
4 判断题 偏易 Python编程考级 ·Python编程二级 · 4.3 访问值

字典的元素可以通过键来访问,也可以通过索引(下标)来访问。(?)

A
对
B
错
答案与解析
正确答案:错

字典的元素只能通过键来访问。

题目详情
5 判断题 偏易 Python编程考级 ·Python编程二级 · 4.3 访问值

字典(dictionary)和列表(list)的共同点是都可以通过下标访问内容。( )

A
对
B
错
答案与解析
正确答案:错

考察字典的概念,字典存储的是键值对,只能通过键值访问。

题目详情
6 判断题 偏易 Python编程考级 ·Python编程二级 · 4.3 访问值

字典的访问方式是通过键来获取值,而不能通过值获取键。( )

A
对
B
错
答案与解析
正确答案:对
字典的核心结构是键值对,键是唯一的,值可以重复,所以Python 中字典的常规访问方式是通过键获取值,无法直接通过值获取对应的键。
题目详情