|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def findStr(desStr,subStr):
count = 0
length = len(desStr)
if subStr not in desStr:
print("在目字符串未找到字符串!")
else:
for each1 in range(length -1):
if desStr[each1] == subStr[0]:
if desStr[each1+1] == subStr[1]:
count += 1
print("字符串再目标字符串中出现 %d 次" % count)
desStr = input("请输入目标字符串:")
subStr = input("请输入子字符串(两个字符):")
findStr(desStr,subSt)
这个代码有错吗??为什么这么搞都是 ”在目标字符串中未找到字符串!”
请输入目标字符串:"You cannot improve your past, but you can improve your future. Once time is wasted, life is wasted."
请输入子字符串(两个字符):"im"
在目标字符串中未找到字符串! |
|