python统计字符串中指定字符出现次数的方法

yipeiwu_com7年前Python基础

本文实例讲述了python统计字符串中指定字符出现次数的方法。分享给大家供大家参考。具体如下:

python统计字符串中指定字符出现的次数,例如想统计字符串中空格的数量

s = "Count, the number of spaces."
print s.count(" ")
x = "I like to program in Python"
print x.count("i")

PS:本站还提供了一个关于字符统计的工具,感兴趣的朋友可以参考一下:

在线字数统计工具:

http://tools.jb51.net/code/zishutongji

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python实现自主查询实时天气

python实现自主查询实时天气

本文实例为大家分享了python实现自主查询实时天气的具体代码,供大家参考,具体内容如下 用到了urllib2 json  很简单的一个应用 如下 获取城市编号 #cod...

python实现将一个数组逆序输出的方法

方法一: def printTheReverseArray(self): list_1 = [1, 2, 3, 4, 5, 6, 7] length = len(list_1...

python对象销毁实例(垃圾回收)

我就废话不多说了,直接上代码吧! '''python对象销毁(垃圾回收)''' class Point: 'info class' def __init__(self,x...

Python 调用DLL操作抄表机

# -*- coding: GBK -*- from ctypes import * dll = windll.LoadLibrary('JBA188.dll') a = dll.tes...

python自动化测试实例解析

本文实例讲述了python自动化测试的过程,分享给大家供大家参考。 具体代码如下: import unittest ##############################...