当前位置:网站首页>序列基础练习题
序列基础练习题
2022-08-05 05:13:00 【非鱼丶丶】
列表基础练习题
选择题
下列选项中能正确表示一个列表的是(D)。
A.
{1, 2, 3}B.
[10, abc, 123]C.
[10 20 30]D.
[1, 2, 3](多选)已知一个列表
nums = [10, 20, '小明', [1, 2]],以下表达式结果是小明的是?(CD)A.
nums[-3]B.
nums[3]C.
nums[-2]D.
nums[2]以下选项关于列表说法错误的是?(C)
A. 列表可以放在
for循环的in后面B. 列表是可变的序列
C. 列表是有序的,只支持增删改,不支持查操作
D. 列表的
in操作可以判断元素是否存在已知一个列表
names = ['小乔', '甄姬', '王昭君', '妲己', '女娲', '西施', '嬴政'],下面的表达式中结果是[]的是?(C)A. names[1:]
B. names[:1]
C. names[1:4:-1]
D. names[1:4:2]
已知列表
list1 = [10, [1, 2], 100, 1000],下列表达式结果是True的是?(D)A.
100 not in list1B.
1 in list1C.
2 in list1D.
[1, 2] in list1下列选项中不属于序列的是?(C)
A. []
B. ‘100’
C. {1, 2}
D. 100
已知
student = {'name': '小明', 'age': 18, 'gender':'男'}下列关于字典的操作正确的是?(D)A.
student('name')B.
student[name]C.
student['小明']D.
student['age']下列表达式有误的是?(D)
A.
100 + 30.03B.
188 * '12'C.
188 * 12D.
188 + '12'(多选)下列表达式能产生
[1, 2, 3]的是?(ABD)A.
[1, 2] + [3]B.
[1, 2].append(3)C.
[1, 2].extend(3)D.
[1, 2, 3] * 1(多选)下列选项中属于可变序列的是?(AC)
A. 列表
B. 元组
C. 字典
D. 字符串
填空题
- python中获取指定数据的类型可以使用(type)函数。
- 查看数据地址的函数是( )。
- 如果要将数据转换成列表,需要使用(list)。
- (count)函数可以用来获取任意序列中元素的个数。
- 如果需要将一个数据插入到列表的中间需要使用函数(insert)。
- Python中数学集合运算中求交集、并集、差集和对称差集的符号分别是( )、( )、( )、( )。
- 请列举出你知道的Python中的不可变的数据类型:(字符串、元组 )。
- 获取字符编码值和获取编码值对应的字符的函数分别是(ord)、(chr)。
- 如果要判断序列中是否存在某个元素可以使用(in)来判断。
- 如果要判断两个数据的地址是否相等可以使用(index)。
编程题
已知一个列表
names = ['胡歌', '王凯', '王俊凯', '杨幂', '刘德华', '张国荣', '王祖贤', '张伟']。1)依次打印列表中的每个元素
2)统计列表中姓
张的人的个数。3)统计名字是两个字的人的个数。
names = ['胡歌', '王凯', '王俊凯', '杨幂', '刘德华', '张国荣', '王祖贤', '张伟' for x in names: print(x, end=',') print("--------------------分割线--------------------") count = 0 for x in names: if x[0] == '张': count += 1 print(count) print("--------------------分割线--------------------") count = 0 for x in names: if len(x) == 2: count += 1 print(count)已知字典
dog = {'name': '大黄', 'color': 'yellow', 'age': 3, 'kind': '土狗'}1)打印所有key对应的值
2)将name的值修改成 ‘旺财’
3)添加狗的价格对应的键值对
4)清空dog字典
dog = { 'name': '大黄', 'color': 'yellow', 'age': 3, 'kind': '土狗'} print([dog[x] for x in dog]) print("--------------------分割线--------------------") dog['name'] = '旺财' print(dog) print("--------------------分割线--------------------") dog.setdefault('价格', 100) print(dog) print("--------------------分割线--------------------") dog = { 'name': '大黄', 'color': 'yellow', 'age': 3, 'kind': '土狗'} for x in dog.copy(): del dog[x] print(dog)已知字符串
message = 'You see see, one day day!'1)统计字符串中非字母的字符个数
2)提取出所有的小写字母
count = 0 for x in message: if not (x.isupper() or x.islower()): count += 1 print(count) print("--------------------分割线--------------------") new_message = '' for x in message[:]: if x.islower(): new_message += x print(new_message)
边栏推荐
猜你喜欢
随机推荐
【过一下14】自习室的一天
数据库 单表查询
Flutter Learning 4 - Basic UI Components
ES6 生成器
小白一枚各位大牛轻虐虐
How can Flutter parent and child components receive click events
【cesium】Load and locate 3D Tileset
开发一套高容错分布式系统
位运算符与逻辑运算符的区别
Flutter learning 2-dart learning
day10-字符串作业
Distributed systems revisited: there will never be a perfect consistency scheme...
Xiaobai, you big bulls are lightly abused
【Untitled】
Excel Paint
学习总结week3_2函数进阶
Analysis of Mvi Architecture
Returned object not currently part of this pool
pycharm中调用Matlab配置:No module named ‘matlab.engine‘; ‘matlab‘ is not a package
redis复制机制









