统计字符串中子串重复次数
emmmm,来成都华迪实训基地的第一天上午,挺基础的,之后应该会越来越有趣吧。
python代码
def find_substr_count(orgstr, substr):
count = 0
for i in range(len(orgstr)):
if orgstr[i:i + len(substr)] == substr:
count += 1
return count
orgstr = input("输入字符串\n")
while True:
substr = input("要查找的子串?如不查找请输入!q\n")
if substr == "!q":
exit(0)
print(find_substr_count(orgstr, substr))