zqxqx

字符串

count:(python中的count()函数,从字面上可以知道,他具有统计功能)

Python count() 方法用于统计字符串里某个字符出现的次数。可选参数为在字符串搜索的开始与结束位置

语法

count()方法语法:

str.count(sub, start= 0,end=len(string))

参数

  • sub -- 搜索的子字符串
  • start -- 字符串开始搜索的位置。默认为第一个字符,第一个字符索引值为0。
  • end -- 字符串中结束搜索的位置。字符中第一个字符的索引为 0。默认为字符串的最后一个位置。

返回值

该方法返回子字符串在字符串中出现的次数。

 列一

1 strings="How do you do"
2 
3 print(strings.count("o"))

输出结果:4

 

列二

1 strings="How do you do"
2 
3 print(strings.count("do"))

输出结果:2

列三

1 strings="How do you do"
2 
3 print(strings[0:6].count("o"))

输出结果:2

 

分类:

技术点:

相关文章:

  • 2021-08-28
  • 2021-11-10
  • 2021-09-10
  • 2021-11-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-11-12
  • 2021-10-18
  • 2021-11-24
相关资源
相似解决方案