当前位置:考试网  > 试卷库  > 计算机类  > 等级考试  > 计算机二级  > Python语言程序设计  > 简述元组与列表的异同。并简述它们各自的用途。
试题预览

简述元组与列表的异同。并简述它们各自的用途。

查看答案
收藏
纠错
正确答案:

Python元组和列表一样, 都是有序序列, 在很多情况下可以相互替换, 很多操作也类似,但它们也有区别:元组是不可变的序列类型,元组能对不需要改变的数据进行写保护,使数据更安全。列表是可变的序列类型,可以添加、删除或搜索列表中的元素。元组使用小括号定义用逗号分隔的元素, 而列表中的元素应该包括在中括号中。虽然元组使用小括号,但访问元组元素时,要使用中括号按索引或分片来获得对应元素的值。元组可以在字典中作为关键字使用,而列表不能作为字典关键字使用,因为列表不是不可改变的。只要不尝试修改元组,那么大多数情况下把它们作为列表来进行操作用途:列表可被用于保存多个互相独立对象的数据集合元组用于描述一个不会改变的事务的多个属性

答案解析:

暂无解析

你可能感兴趣的试题

表达式1001==0x3e7的结果是:

以下程序的输出结果是:

img1=[12,34,56,78]

img2=[1,2,3,4,5]

defdispl():

print(img1)

defmodi():

img1=img2

modi()

displ()

请用Python语言编写一个简易的计算器程序。

以下程序的输出结果是:

deftest(b=2,a=4):

globalz

z+=a*b

returnz

z=10

print(z,test())

执行以下程序,输入la,输出结果是:

la='python'

try:

s=eval(input('请输入整数:'))

ls=s*2

print(ls)

except:

print('请输入整数')

热门试题 更多>
试题分类: 市场信息学
练习次数:0次
Relaxation therapy ( = treatment). If you read the sentence out loud, your blood pressure will go up. If you talk to another person, it will go still higher. If the talk is with your boss, your pressure will go even higher. If you speak to someone of the opposite sex, your pressure may show less change if you ’ re married than if you ’ re single. Dozens of times each day, your blood pressure changes with what you ’ re feeling and doing. These “ ups and downs” take place in everyone, but they are more severe in people with high blood pressure. That discovery is the basis for the newest therapy: controlling blood pressure by learning skills to control everyday stress. Many patients control their blood pressure with the relaxation response. This takes four simple things: a quiet environment, a comfortable position (sitting or lying down), the repeating of a word, prayer or phrase each time you breathe and having none of other thoughts. Something remarkable happens when you do this, according to research in Boston. Relaxation of the mind and body has the effect that some blood-p ressure pills would have. What ’ s more, the blood pressure stays lower, just as it would with a pill, after you have stopped the relaxation and have returned to the stress of daily life.  31. The first paragraph tells us the reason why your blood pressure goes up is that__________.  A. you read aloud a sentence B. the man you talk to is your boss C. you ’ re not married D. you ’ re nervous 32. Which of the following statements is not true? A. One ’ s blood pressure changes many times every day. B. Your blood pressure changes with your feelings. C. When you ’ re doing different things, your blood pressure, perhaps, is different. D. The changes of blood pressure only happen to people with high blood pressure. 33. The last paragraph tells us relaxation therapy__________. A. needs a new kind of medicine B. has the same effect as blood-pressure pills C. is more than blood-pressure pills D. is working and can be improved
试题分类: 电子商务英语
练习次数:0次
试题分类: 互联网数据库
练习次数:0次
试题分类: 商法(二)
练习次数:0次
试题分类: 文学概论
练习次数:0次
试题分类: 电子商务网站设计原理
练习次数:0次
试题分类: 电子商务网站设计原理
练习次数:0次
试题分类: 教育管理原理
练习次数:0次
试题分类: 电子商务网站设计原理
练习次数:0次
试题分类: 电子商务与电子政务
练习次数:0次
扫一扫,手机做题