❎Operadores lógicos
Los operadores lógicos modifican y unen expresiones evaluadas en contexto booleano para crear condiciones más complejas.
Operador
Ejemplo
Significado
not
not x
True
if x
is False
False
if x
is True
or
x or y
True
if either x
or y
is True
False
otherwise
and
x and y
True
if both x
and y
are True
False
otherwise
1. Operador not
not
num = 5
num < 10
True
not num < 10
False
not (num < 10)
False
2. Operador or
or
num1 = 5
num2 = 10
num1 < 4
False
num1 < 4 or num2 > 5
True
(num1 < 4) or (num2 > 5)
True
3. Operador and
and
num1 = 5
num2 = 10
num1 < 6 and num2 > 5
True
num1 < 4 and num2 > 5
False
(num1 < 5 or num2 > 3) and num2 == 10 and num1 < 8
True
Última actualización