operator.ne_Python operator.ne()函数与示例

operator.ne

operator.ne()函数 (operator.ne() Function)

operator.ne() function is a library function of operator module, it is used to perform "not equal to operation" on two values and returns True if the first value is not equal to the second value, False, otherwise.

operator.ne()函数是运营商模块的库函数,它被用于在两个值并返回true执行“不等于操作”如果第一个值不等于所述第二值, 假 ,否则。

Module:

模块:

    import operator

Syntax:

句法:

    operator.ne(x,y)

Parameter(s):

参数:

  • x,y – values to be compared.

    x,y –要比较的值。

Return value:

返回值:

The return type of this method is bool, it returns True if x is not equal to y, False, otherwise.

此方法的返回类型为bool ,如果x不等于y ,则返回True ,否则返回False 。

Example 1:

范例1:

# Python operator.ne() Function Example

import operator

# integers
x = 10
y = 20

print("x:",x, ", y:",y)
print("operator.ne(x,y): ", operator.ne(x,y))
print("operator.ne(y,x): ", operator.ne(y,x))
print("operator.ne(x,x): ", operator.ne(x,x))
print("operator.ne(y,y): ", operator.ne(y,y))
print()

# strings
x = "Apple"
y = "Banana"

print("x:",x, ", y:",y)
print("operator.ne(x,y): ", operator.ne(x,y))
print("operator.ne(y,x): ", operator.ne(y,x))
print("operator.ne(x,x): ", operator.ne(x,x))
print("operator.ne(y,y): ", operator.ne(y,y))
print()

# printing the return type of the function
print("type((operator.ne(x,y)): ", type(operator.ne(x,y)))

Output:

输出:

x: 10 , y: 20
operator.ne(x,y):  True
operator.ne(y,x):  True
operator.ne(x,x):  False
operator.ne(y,y):  False

x: Apple , y: Banana
operator.ne(x,y):  True
operator.ne(y,x):  True
operator.ne(x,x):  False
operator.ne(y,y):  False

type((operator.ne(x,y)):  <class 'bool'>

Example 2:

范例2:

# Python operator.ne() Function Example
import operator

# input two numbers
x = int(input("Enter first number : "))
y = int(input("Enter second number: "))

# printing the values
print("x:",x, ", y:",y)

# comparing
if operator.ne(x,y):
  print(x, "is not equal to", y)
else:
  print(x, "is equal to", y)  

Output:

输出:

RUN 1:
Enter first number : 10
Enter second number: 20
x: 10 , y: 20
10 is not equal to 20

RUN 2:
Enter first number : 10
Enter second number: 10
x: 10 , y: 10
10 is equal to 10


翻译自: https://www.includehelp.com/python/operator-ne-function-with-examples.aspx

operator.ne

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值