operator.not_()函数 (operator.not_() Function)
operator.not_() function is a library function of operator module, it is used to perform "NOT operation" on a given value and returns True if the given value is zero or any falsy value, False, otherwise.
operator.not_()函数是运营商模块的库函数,它被用于如果给定的值是零或任何falsy值, 假上的给定值并返回true执行“NOT操作”,否则。
Module:
模块:
import operator
Syntax:
句法:
operator.not_(x)
Parameter(s):
参数:
x – value on which NOT operation to be performed.
x-要对其执行NOT操作的值。
Return value:
返回值:
The return type of this method is bool, it returns True if x is zero or any falsy value, False, otherwise.
此方法的返回类型为布尔 ,如果x是零或任何falsy值, 假返回true,否则。
Example:
例:
# Python operator.not_() Function Example
import operator
print("operator.not_(True):", operator.not_(True))
print("operator.not_(False):", operator.not_(False))
print()
x = 1
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()
x = 10
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()
x = -10
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()
x = 0
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()
x = "Hello"
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()
x = ""
print("x:", x)
print("operator.not_(x):", operator.not_(x))
print()
Output:
输出:
operator.not_(True): False
operator.not_(False): True
x: 1
operator.not_(x): False
x: 10
operator.not_(x): False
x: -10
operator.not_(x): False
x: 0
operator.not_(x): True
x: Hello
operator.not_(x): False
x:
operator.not_(x): True
翻译自: https://www.includehelp.com/python/operator-not_-function-with-examples.aspx