Python 相当于 !运算符(operator)

标签 python operators

对于下面的构造还有什么更pythonic的方式呢?

如果它是 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

Python Docs - Expressions - 5.1 Boolean Expressions

关于Python 相当于 !运算符(operator),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6937473/

相关文章:

python - 与服务器上运行的python程序通信

java - 如何导入我在 jython 中创建的 java 类并调用方法

perl - || =的含义是什么

python - 使用常规 python 脚本运行 Nose 测试

python - 使用正则表达式的 Django 过滤器

python - KBinsDiscretizer bin 边缘

MySql 搜索查询无法返回内部包含 %20 的行

c++ - 没有第二个操作数的三元运算符

c++ - 如何改进我的类(class)的运算符重载?

swift - &/and &% 从 Swift 语言中移除了吗?