#Python# 查找子字符串在目标字符串中出现的次数

def findstr(str1,str2):
  if str2 in str1:
    times = str1.count(str2)
    print("子字符串在目标字符串中共出现了%d次" %times)
  else:
    print("子字符串在目标字符串中共出现了0次")

str1 = input("请输入目标字符串:")
str2 = input("请输入子字符串(两个字符):")
findstr(str1,str2)

posted on 2021-09-08 14:42  Restart_beth  阅读(210)  评论(0)    收藏  举报