突然想开始记录以前容易习惯性敲错的代码,欢迎回复各自的经历,也许之后会开个仓库~
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" ...]]): ...
对于字典的遍历
经常是
for k, v in d:
print("{}={}".format(k ,v))
结果报错,应该是
for k, v in d.items():
print("{}={}".format(k ,v))
SQL:
update tb set xx='val1' and yy='val2' ...
实际上应该是
update tb set xx='val1', yy='val2' ...