使用
not布尔运算符:
nyval = not myval
not返回一个 布尔 值(
True或
False):
>>> not 1False>>> not 0True
如果必须有一个整数,则将其返回:
nyval = int(not myval)
但是,python
bool类型是的子类
int,因此可能不需要:
>>> int(not 0)1>>> int(not 1)0>>> not 0 == 1True>>> not 1 == 0True

使用
not布尔运算符:
nyval = not myval
not返回一个 布尔 值(
True或
False):
>>> not 1False>>> not 0True
如果必须有一个整数,则将其返回:
nyval = int(not myval)
但是,python
bool类型是的子类
int,因此可能不需要:
>>> int(not 0)1>>> int(not 1)0>>> not 0 == 1True>>> not 1 == 0True