共計 155 個字符,預計需要花費 1 分鐘才能閱讀完成。
可以使用 Python 中的 count() 方法來計算字符串中子串出現的次數。
count()
示例代碼如下:
s = "hello world hello" sub = "hello" count = s.count(sub) print(count)
以上代碼輸出結果為 2,即子串”hello”在字符串”s”中出現了 2 次。
丸趣 TV 網 – 提供最優質的資源集合!
python數組扁平化處理的方法是什么
python怎么獲取post請求結果