当前位置:网站首页>序列基础练习题
序列基础练习题
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 list1
B.
1 in list1
C.
2 in list1
D.
[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.03
B.
188 * '12'
C.
188 * 12
D.
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)
边栏推荐
- The software design experiment four bridge model experiment
- The underlying mechanism of the class
- RL强化学习总结(一)
- pycharm中调用Matlab配置:No module named ‘matlab.engine‘; ‘matlab‘ is not a package
- Reverse theory knowledge 4
- 数字_获取指定位数的小数
- Flutter learning 5-integration-packaging-publish
- HQL语句执行过程
- ESP32 485 Illuminance
- [Software Exam System Architect] Software Architecture Design ③ Domain-Specific Software Architecture (DSSA)
猜你喜欢
MySQL Foundation (1) - Basic Cognition and Operation
OFDM 十六讲 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems
【过一下3】卷积&图像噪音&边缘&纹理
The mall background management system based on Web design and implementation
Basic properties of binary tree + oj problem analysis
Reverse theory knowledge 4
Flutter learning three-Flutter basic structure and principle
server disk array
The difference between span tag and p
jvm 三 之堆与栈
随机推荐
Flutter真机运行及模拟器运行
Returned object not currently part of this pool
软件设计 实验四 桥接模式实验
LeetCode: 1403. Minimum subsequence in non-increasing order [greedy]
server disk array
jvm three heap and stack
The mall background management system based on Web design and implementation
Opencv中,imag=cv2.cvtColor(imag,cv2.COLOR_BGR2GRAY) 报错:error:!_src.empty() in function ‘cv::cvtColor‘
【过一下3】卷积&图像噪音&边缘&纹理
【微信小程序】WXML模板语法-条件渲染
SQL(二) —— join窗口函数视图
MySQL Foundation (1) - Basic Cognition and Operation
How to quickly upgrade your Taobao account to a higher level
Dashboard Display | DataEase Look at China: Data Presents China's Capital Market
重新审视分布式系统:永远不会有完美的一致性方案……
【读书】长期更新
Flutter real machine running and simulator running
将照片形式的纸质公章转化为电子公章(不需要下载ps)
UVA10827
ES6 生成器