基础题
1.已知字符串:“this is a test of Python”
a.统计该字符串中字母s出现的次数: count()
str1 = "this is a test of Python"
print(str1.count("s"))
b.取出子字符串“test”, 用切片,不能数: 使用find(),len()
str1 = "this is a test of Python"
start=str1.find('test')
end=start+len("test")
print(str1[start:end])
c.采用不同的方式将字符串倒序输出: 切片,循环
# 方式一:切片方式
str1 = "this is a test of Python"
print(str1[::-1])
# 方式二:
print("".join(list(reversed(str1))))
d.将其中的"test"替换为"exam" : replace
str1 = "this is a test of Python"
print(str1.replace("test","exam"))
2.去掉字符串123@zh@qq.com中的@;
提示: replace
str2 = "123@zh@qq.com"
print(st