开发者

Python equivalent of the ! operator

For the following construct what can the more pythonic way?

If it were C 开发者_Python百科I could just use ! but what is it equivalent in 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

Python Docs - Expressions - 5.1 Boolean Expressions


The not keyword.

if not os.path.exists(file_path):
    file_path ...


Simply:

file_path = # something 
if not os.path.exists(file_path):
    file_path = # make new path 

Operator not is also in C++, btw, as a synonym for !.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜