Python operator.not_()函数与示例

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值