# # 1. 将字符串 "abcd" 转成大写
# str = 'abcd'
# print(str.upper())
# # 2. 计算字符串 "cd" 在 字符串 "abcd"中出现的位置
# print(str.find('cd', 1))
# # 3. 字符串 "a,b,c,d" ,请用逗号分割字符串,分割后的结果是什么类型的?
# print(str.split(',',maxsplit=0))
# # 4. "{name}喜欢{fruit}".format(name="李雷") 执行会出错,请修改代码让其正确执行
# # 5. string = "Python is good", 请将字符串里的Python替换成 python,并输出替换后的结果
# # String = "Python is good"
# # print(String.replace('Python', 'python'))
# # 6. 有一个字符串 string = "python修炼第一期.html",请写程序从这个字符串里获得.html前面的部分,要用尽可能多的方式来做这个事情
# string = 'python修炼第一期.html'
# print(string[0:11])
# # 7. 如何获取字符串的长度?
# print(len(str))
# # 8. "this is a book",请将字符串里的book替换成apple
# a="this IS a book"
# print(a.replace('book', 'apple'))
# # 9. "this is a book", 请用程序判断该字符串是否以this开头
# print(a.startswith("this"))
# # 10. "this is a book", 请用程序判断该字符串是否以apple结尾
# print(a.endswith("apple"))
# # 11. "This IS a book", 请将字符串里的大写字符转成小写字符
# print(a.lower())
# # 12. "This IS a book", 请将字符串里的小写字符,转成大写字符
# print(a.swapcase())
# # 13. "this is a book\n", 字符串的末尾有一个回车符,请将其删除
# i="this is a book\n"
# i.replace()
# 1.元组元素求和b=(1,2,3,4,5,6,7,8,9)
# 有没有人写过求和方法sum;每一个数,循环 for i in b:
b=(1,2,3,4,5,49,17,8,9)
print(sum(b))
# 2.输出元组内7的倍数及个位为7的数
for i in b:
if i%7==0 or i%10==7:
print(i)
# 1、二个条件2、满足逻辑表达是and 还or 3、num%7==0 str[-1]==7
# 3.列表倒数 输出 a = [321, 7654, 21, 6543]
a=[123,4567,12,3456]
a.reverse()
print(a)
关于字符串操作的题
最新推荐文章于 2022-10-20 11:10:33 发布