對於下面的構造什麼可以更pythonic的方式?相當於Python的! operator
如果它是C我可以只使用!
但它在Python中等價嗎?
file_path = # something
if os.path.exists(file_path):
pass
else:
file_path = # make new path
對於下面的構造什麼可以更pythonic的方式?相當於Python的! operator
如果它是C我可以只使用!
但它在Python中等價嗎?
file_path = # something
if os.path.exists(file_path):
pass
else:
file_path = # make new path
file_path = # something
if not os.path.exists(file_path):
file_path = #make new path
只需:
file_path = # something
if not os.path.exists(file_path):
file_path = # make new path
算not
也是在C++中,順便說一句,作爲用於!
的同義詞。
not
關鍵字。
if not os.path.exists(file_path):
file_path ...
使用python語法,它經常用於嘗試簡單的英語! – wim