Usando o operador "and"
Python tem um operador lógico chamado and. O operador and recebe dois valores booleanos e retorna True se ambos os valores forem True.
Considere a and b:
- Verifica-se se
aéTrueouFalse. - Se
aforFalse,Falseserá retornado. - Verifica-se se
béTrueouFalse. - Se
bforFalse,Falseserá retornado. - Caso contrário,
Trueserá retornado (porqueaebsãoTrue).
O operador and só retornará True para True and True.
Crie uma função usando o operador and.
Exemplos
And(True, False) ➞ False
And(True, True) ➞ True
And(False, True) ➞ False
And(False, False) ➞ FalseNotas
N/A