我有以下代码:
#!/usr/bin/python3
import configparser
config = configparser.ConfigParser()
config.read('bindslash.ini')
print([name for name in config.sections() if name is not 'bindslash'])
bindslash.ini
看起来像这样:
[bindslash]
[somethingelse]
运行此程序会生成['bindslash', 'somethingelse']
。但是,如果我将列表解析中的is not
改为!=
,则程序会正确生成['somethingelse']
。据我了解,这些应该完全相同。为什么没有is not
工作?
我在Python 3.5.0上,在OS X上从Homebrew安装。