当前位置:网站首页>第016讲:序列 | 课后测试题及答案
第016讲:序列 | 课后测试题及答案
2022-06-22 20:05:00 【ChaseTimLee】
测试题:
0. 我们根据列表、元组和字符串的共同特点,把它们三统称为什么?
序列,因为他们有以下共同点:
1)都可以通过索引得到每一个元素
2)默认索引值总是从0开始(当然灵活的Python还支持负数索引)
3)可以通过分片的方法得到一个范围内的元素的集合
4)有很多共同的操作符(重复操作符、拼接操作符、成员关系操作符)
1. 请问分别使用什么BIF,可以把一个可迭代对象转换为列表、元组和字符串?
list([iterable]) 把可迭代对象转换为列表
tuple([iterable]) 把可迭代对象转换为元组
str(obj) 把对象转换为字符串
>>> temp = 'I love FishC.com!'
>>> list(temp)
['I', ' ', 'l', 'o', 'v', 'e', ' ', 'F', 'i', 's', 'h', 'C', '.', 'c', 'o', 'm', '!']
2. 你还能复述出“迭代”的概念吗?
所谓迭代,是重复反馈过程的活动,其目的通常是为了接近并到达所需的目标或结果。每一次对过程的重复被称为一次“迭代”,而每一次迭代得到的结果会被用来作为下一次迭代的初始值。
3. 你认为调用 max(‘I love FishC.com’) 会返回什么值?为什么?
会返回:‘v’,因为字符串在计算机中是以ASCII码的形式存储(ASCII对照表:http://bbs.fishc.com/thread-41199-1-1.html),参数中ASCII码值最大的是’v’对应的118。
4. 哎呀呀,现在的小屁孩太调皮了,邻居家的孩子淘气,把小甲鱼刚写好的代码画了个图案,麻烦各位鱼油恢复下代码~~

name = input('请输入待查找的用户名:')
score = [['迷途', 85], ['黑夜', 80], ['小布丁', 65], ['福禄娃娃', 95], ['怡静', 90]]
IsFind = False
for each in score:
if name in each:
print(name + '的得分是:', each[1])
IsFind = True
break
if IsFind == False:
print('查找的数据不存在!')
动动手:
0. 猜想一下 min() 这个BIF的实现过程
def min(x):
least = x[0]
for each in x:
if each < least:
least = each
return least
print(min('123456789'))
1. 视频中我们说 sum() 这个BIF有个缺陷,就是如果参数里有字符串类型的话就会报错,请写出一个新的实现过程,自动“无视”参数里的字符串并返回正确的计算结果
def sum(x):
result = 0
for each in x:
if (type(each) == int) or (type(each) == float):
result += each
else:
continue
return result
print(sum([1, 2.1, 2.3, 'a', '1', True]))
边栏推荐
猜你喜欢
![[redis] cluster and common errors](/img/a5/94906b62b1ec0d549f9b72ff3db7f2.png)
[redis] cluster and common errors
![[21. merge two ordered linked lists]](/img/ce/45b8cc740c8632f0cedc3ffd31620a.png)
[21. merge two ordered linked lists]
![[redis]发布与订阅](/img/50/0c2fbbb8f56fccdd3222b77efdd723.png)
[redis]发布与订阅
![[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!](/img/f0/4f237e7ab1bff9761b6092dd4ef3d9.png)
[book delivery at the end of the article] AI has spread all over the Internet to color old photos. Here is a detailed tutorial!
![[redis]Redis6的事务操作](/img/50/639867a2fcb92082ea262a8a19bb68.png)
[redis]Redis6的事务操作

【142. 环形链表 II】

The access succeeds but an exception is thrown: could not find acceptable representation

Moke 6. Load balancing ribbon

Cannot re-register id: PommeFFACompetition-v0问题解决

Numpy learning notes (6) -- sum() function
随机推荐
One line of code binds swiftui view animation for a specific state
53页智慧校园智能化系统设计方案(附下载)
[20. valid brackets]
密码学系列之:PKI的证书格式表示X.509
Cannot re-register id: PommeFFACompetition-v0问题解决
ByteDance proposes a lightweight and efficient new network mocovit, which has better performance than GhostNet and mobilenetv3 in CV tasks such as classification and detection
Baijia forum Wu Zetian
查看苹果产品保修状态
88- widely circulated parameter optimization, honey or poison?
2022年起重机械指挥考试模拟100题及模拟考试
超快变形金刚 | 用Res2Net思想和动态kernel-size再设计 ViT,超越MobileViT
Baijia forum Daqin rise (lower part)
[206. reverse linked list]
【ICML2022】利用虚拟节点促进图结构学习
Extended ribbon supports metadata based version management
74- how to remedy the loss of Oracle to MySQL for this kind of SQL optimization?
性能测试(一)
Moke 6. Load balancing ribbon
Three ways of extending ribbon to support Nacos weight
94-SQL优化案例一则(用到的写法经常是被嫌弃的)