if “Hello” in my_string:

if my_string.find(“World”) != -1:

str.find() 若搜尋不到
會return -1

str.endswith()
#不要漏掉s

判斷fpath的附檔名
非常好用

elif fpath.endswith((“.csv”,”.txt”)):
the endswith() method in Python supports passing a tuple of suffixes, so fpath.endswith((".csv", ".txt")) will work as expected. It will check if fpath ends with either “.csv” or “.txt”.
但如果使用in的話,
tuple則非我們預期的結果
if ("Hello", "World") in my_string will not work as intended because it is checking if the tuple ("Hello", "World") exists as a whole in the string my_string.
str.startswith()
#不要漏掉s

用str.find()實做:

.startswith()

.endswith(ext)

推薦hahow線上學習python: https://igrape.net/30afN

![Python: 自定義函數計算計程車車資(先typing,再用預設值), 巢狀字典以及typing.Union[ ], assert 斷言 Python: 自定義函數計算計程車車資(先typing,再用預設值), 巢狀字典以及typing.Union[ ], assert 斷言](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220923222039_57.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python 打造高容錯搜尋引擎:BM25、Bigram 與difflib自動糾錯實戰; from rank_bm25 import BM25Okapi ; bm25 = BM25Okapi(corpus_tokens) #corpus_tokens: list[list[str]] Python 打造高容錯搜尋引擎:BM25、Bigram 與difflib自動糾錯實戰; from rank_bm25 import BM25Okapi ; bm25 = BM25Okapi(corpus_tokens) #corpus_tokens: list[list[str]]](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2026/02/20260209150527_0_a24c17.png?quality=90&zoom=2&ssl=1&resize=350%2C233)





近期留言