思維定勢引起容易寫錯的代碼(預計長期更新)

突然想開始記錄以前容易習慣性敲錯的代碼,歡迎回復各自的經歷,也許之後會開個倉庫~
python:

if "xx" or "yy" in something: ...

結果恆爲True,實際應該爲

if "xx" in something or "yy" in something: ...
# 如果量大,可寫
if any([pattern in something for pattern in ["xx", "yy", "zz" ...]]): ...

SQL:

update tb set xx='val1' and yy='val2' ...

實際上應該是

update tb set xx='val1', yy='val2' ...
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章