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 operatorSyntax:
句法:
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 Exampleimport operator# integers x = 10 y = 20print("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): Falsex: Apple , y: Banana operator.ne(x,y): True operator.ne(y,x): True operator.ne(x,x): False operator.ne(y,y): Falsetype((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 20RUN 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
總結
以上是生活随笔為你收集整理的operator.ne_Python operator.ne()函数与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: scala字符替换_如何替换Scala中
- 下一篇: “身表既非我”下一句是什么