Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果这是第一个字符串:ABCD
ABCD
如果这是第二个字符串:ABCD is ABCD
ABCD is ABCD
我想计算第二个字符串中第一个字符串的出现次数,以及 python 中的出现次数。我该怎么做?我是 python 新手,所以面临一些问题。谁能告诉我解决方案或提供相同的代码。
使用str.count():
str.count()
>>> str1 = "ABCD" >>> str2 = "ABCD is ABCD" >>> str2.count(str1) 2