首页 > 其他 > 详细

sh_15_字符串统计操作

时间:2019-09-14 16:34:04      阅读:64      评论:0      收藏:0      [点我收藏+]

 

sh_15_字符串统计操作

hello_str = "hello hello"

# 1. 统计字符串长度
print(len(hello_str))

# 2. 统计某一个小(子)字符串出现的次数
print(hello_str.count("llo"))
print(hello_str.count("abc"))

# 3. 某一个子字符串出现的位置
print(hello_str.index("llo"))
# 注意:如果使用index方法传递的子字符串不存在,程序会报错!
print(hello_str.index("abc"))

 

sh_15_字符串统计操作

原文:https://www.cnblogs.com/shaohan/p/11519377.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!