以Python 3.x版本为主 字符串函数:count、find、index 1、字符串字母处理函数 编号 函数名 说明 1 count 返回a字符串在b字符串出现的次数,可指定字符串范围内的出现的次数 2 find
以Python 3.x版本为主
字符串函数:count、find、index
1、字符串字母处理函数
编号
函数名
说明
1
count
返回a字符串在b字符串出现的次数,可指定字符串范围内的出现的次数
2
find
查看a字符串在b字符串首次出现的下标值
3
index
同find一样
- 代码如下
# -*- coding: utf-8 -*-
# Apr 14, 2022 22:50 AM
prize='【51CTO】奖品5选3护腕鼠标垫/悟字钥匙扣/WuKong熊单肩包/商务笔记本/WuKong熊手办(新版'
str='WuKong'
print('字符串%s\n' % (prize))
# 1、返回出现的次数 - count
myStr_New=prize.count(str)
print('%s在字符串中出现的次数:%s次\n' % (str,myStr_New))
# 2、是否包含字符串 - find
num=prize.find('51CTO')
print('%s字符串中的下标值:%s\n' % (str,num))
# 3、是否包含字符串 - index
num=prize.find('51CTO')
print('%s字符串中的下标值:%s\n' % (str,num))
- 效果如下