operator.eq
operator.eq()函数 (operator.eq() Function)
operator.eq() function is a library function of operator module, it is used to perform "equal to operation" on two values and returns True if the first value is equal to the second value, False, otherwise.
operator.eq()函数是运营商模块的库函数,它被用于在两个值并返回true执行“等于操作”如果第一个值等于所述第二值, 假 ,否则。
Module:
模块:
import operator
Syntax:
句法:
operator.eq(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 equal to y, False, otherwise.
此方法的返回类型为bool ,如果x等于y ,则返回True ,否则返回False 。
Example 1:
范例1:
# Python operator.eq() Function Example
import operator
# integers
x = 10
y = 20
print("x:",x, ", y:",y)
print("operator.eq(x,y): ", operator.eq(x,y))
print("operator.eq(y,x): ", operator.eq(y,x))
print("operator.eq(x,x): ", operator.eq(x,x))
print("operator.eq(y,y): ", operator.eq(y,y))
print()
# strings
x = "Apple"
y = "Banana"
print("x:",x, ", y:",y)
print("operator.eq(x,y): ", operator.eq(x,y))
print("operator.eq(y,x): ", operator.eq(y,x))
print("operator.eq(x,x): ", operator.eq(x,x))
print("operator.eq(y,y): ", operator.eq(y,y))
print()
# printing the return type of the function
print("type((operator.eq(x,y)): ", type(operator.eq(x,y)))
Output:
输出:
x: 10 , y: 20
operator.eq(x,y): False
operator.eq(y,x): False
operator.eq(x,x): True
operator.eq(y,y): True
x: Apple , y: Banana
operator.eq(x,y): False
operator.eq(y,x): False
operator.eq(x,x): True
operator.eq(y,y): True
type((operator.eq(x,y)): <class 'bool'>
Example 2:
范例2:
# Python operator.eq() 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.eq(x,y):
print(x, "is equal to", y)
else:
print(x, "is not equal to", y)
Output:
输出:
RUN 1:
Enter first number : 10
Enter second number: 10
x: 10 , y: 10
10 is equal to 10
RUN 2:
Enter first number : 10
Enter second number: 20
x: 10 , y: 20
10 is not equal to 20
翻译自: https://www.includehelp.com/python/operator-eq-function-with-examples.aspx
operator.eq