❎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
notnum = 5
num < 10
True
not num < 10
False
not (num < 10)
False2. Operador or
ornum1 = 5
num2 = 10
num1 < 4
False
num1 < 4 or num2 > 5
True
(num1 < 4) or (num2 > 5)
True3. Operador and
andnum1 = 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