''' 输入两个字符串str1和str2,字符串只能由0和1组成,str1的长度小于str2的长度, 判断str1在str2中出现的次数 ''' def main(): str1 = input("输入第一个字符串:") str2 = input("输入第二个字符串:") count = 0 for i in range(len(str2) - len(str1)): if str2[i:i + len(str1)] == str1: count += 1 print('总次数:',count) if __name__ == '__main__': main()
7,python实现----判断字符串出现的次数
猜你喜欢
转载自blog.csdn.net/qq_41686130/article/details/80385779
今日推荐
周排行