Pythonトレーニング


4-3-1-4 文字列の探索

①find

w_str = "abcXYZabc"
print(w_str.find("abc"))
->0

print(w_str.find("aaa"))
->-1

②rfind

w_str = "abcXYZabc"
print(w_str.rfind("abc"))
->6

③count

w_str = "abcXYZabc"
print(w_str.count("abc"))
->2