请帮忙注释下,谢谢
def findStr(desStr, subStr):
count = 0
length = len(desStr)
if subStr not in desStr:
print('在目标字符串中未找到字符串!')
else:
for each1 in range(length-1):
if desStr == subStr:
if desStr == subStr:
count += 1
print('子字符串在目标字符串中共出现 %d 次' % count)
desStr = input('请输入目标字符串:')
subStr = input('请输入子字符串(两个字符):')
findStr(desStr, subStr)
def findStr(desStr, subStr): #定义函数,传入两字符串(目标串,子串)
count = 0#定义计数,初值为0
length = len(desStr) #取目标串长度,为下方遍历做准备
if subStr not in desStr: #子串不在其内
print('在目标字符串中未找到字符串!')
else: #子串在其内
for each1 in range(length-1): #遍历目标串每个字符
if desStr == subStr:
#判断目标串是否符合子串第一个字符
if desStr == subStr:#判断其后的字符
count += 1 #都符合的情况下,计数
print('子字符串在目标字符串中共出现 %d 次' % count)
desStr = input('请输入目标字符串:')
subStr = input('请输入子字符串(两个字符):')
findStr(desStr, subStr)#调用
如果满意,请给个最佳吧
页:
[1]