Python operator.ge () Función : Aquí, vamos a aprender acerca de la función operator.ge () con ejemplos en el lenguaje de programación Python.
operator.ge () Función
operator.ge () función es una función de biblioteca de módulo operador , que se utiliza para realizar “mayor que o igual a la operación” en dos valores y los verdaderos rendimientos si el primer valor es mayor o igual que el segundo valor, Falso , de lo contrario.
Módulo:
import operator
Sintaxis:
operator.ge(x,y)
Parámetro (s):
- x, y – valores que se compararán.
class valor:
El tipo class de este método es bool , devuelve Verdadero si x es mayor que o igual a y , False , de lo contrario.
Ejemplo 1:
# Python operator.ge() Function Example
import operator
# integers
x = 10
y = 20
print("x:",x, ", y:",y)
print("operator.ge(x,y): ", operator.ge(x,y))
print("operator.ge(y,x): ", operator.ge(y,x))
print("operator.ge(x,x): ", operator.ge(x,x))
print("operator.ge(y,y): ", operator.ge(y,y))
print()
# strings
x = "Apple"
y = "Banana"
print("x:",x, ", y:",y)
print("operator.ge(x,y): ", operator.ge(x,y))
print("operator.ge(y,x): ", operator.ge(y,x))
print("operator.ge(x,x): ", operator.ge(x,x))
print("operator.ge(y,y): ", operator.ge(y,y))
print()
# printing the return type of the function
print("type((operator.ge(x,y)): ", type(operator.ge(x,y)))
salida:
x: 10 , y: 20
operator.ge(x,y): False
operator.ge(y,x): True
operator.ge(x,x): True
operator.ge(y,y): True
x: Apple , y: Banana
operator.ge(x,y): False
operator.ge(y,x): True
operator.ge(x,x): True
operator.ge(y,y): True
type((operator.ge(x,y)): <class 'bool'>
Ejemplo 2:
# Python operator.ge() 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.ge(x,y):
print(x, "is greater than or equal to", y)
else:
print(x, "is not greater than or equal to", y)
salida:
RUN 1:
Enter first number : 20
Enter second number: 10
x: 20 , y: 10
20 is greater than or equal to 10
RUN 2:
Enter first number : 10
Enter second number: 10
x: 10 , y: 10
10 is greater than or equal to 10
RUN 3:
Enter first number : 10
Enter second number: 20
x: 10 , y: 20
10 is not greater than or equal to 20