1. name = "aleX leNb "
请输出name变量对应的值中的"e" 所在索引位置
name = "aleX leNb"
index = 0 #手动记录索引
for c in name:
if c == 'e': #如果字母是e
print(index) #打印索引
index = index + 1
2.有字符串s = "123a4b5c"
1)通过对s切片形成新的字符串s1, s1 = "123"
s = "123a4b5c"
print(s[:3])
2)通过对s切片形成新的字符串s2,s2 = "a4b"
s = "123a4b5c"
print(s[3:6])
3)通过对s切片形成新的字符串s3,s3 = "1345"
s = "123a4b5c"
print(s[::2])
4)通过对s切片形成新的字符串s4,s4 = "2ab"
s = "123a4b5c"
print(s[1:6:2])
5)通过对s切片形成新的字符串s5,s5 = "c"
s = "123a4b5c"

本文介绍了Python编程中的基本操作,包括查找字符串中'e'的索引,字符串切片创建新字符串,使用for循环处理字符串并打印内容,倒计时显示,以及实现简单的整数加法计算器。同时,给出了计算特定数列和的代码示例。
最低0.47元/天 解锁文章
931

被折叠的 条评论
为什么被折叠?



