输出字符串http://sports.sina.com.cn/,按要求输出以下结果
1、统计字母t出现的次数
2、字符串中"com"出现的位置
3、将字符串中所有的"."替换为"_"
4、分别使用正向切片和反向切片提取子字符串"sports"
5、将字符串中的字母全部变成大写
6、输出字符串的总字符个数
7、在字符串后拼接子字符串"index"
输出字符串http://sports.sina.com.cn/,按要求输出以下结果
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- CSDN专家-sinJack 2023-04-12 17:20关注
s = "http://sports.sina.com.cn/" count = s.count('t') print("字母t出现的次数为:", count) index = s.find('com') print('"com"出现的位置为:', index) new_s = s.replace('.', '_') print("替换后的字符串为:", new_s) sub_s1 = s[7:13] sub_s2 = s[-17:-11] print("正向切片提取的子字符串为:", sub_s1) print("反向切片提取的子字符串为:", sub_s2) new_s = s.upper() print("转换后的字符串为:", new_s) length = len(s) print("字符串的总字符个数为:", length) new_s = s + "index" print("拼接后的字符串为:", new_s)本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报 编辑记录解决 3无用