Python字符串中含有某子字符串的个数 str1 = "abskfirgnlskgabndf" str2 = "ab" num = (len(str1) - len(str1.replace(str2,""))) // len(str2)