Ibuprofeno.py馃拪| #101: Explica este c贸digo Python

Cristian Fernando - May 8 - - Dev Community

Explica este c贸digo Python

Dificultad: Intermedio

text = "hi"
a = len(text) == 2
b = text.endswith("i")
c = text.islower()

if all([a, b, c]):
    print("馃憣")
else:
    print("馃敶")
Enter fullscreen mode Exit fullscreen mode

馃憠 A. SyntaxError
馃憠 B. 馃憣
馃憠 C. 馃敶
馃憠 D. ValueError


Respuesta:

馃憠 B. 馃憣

En Python tenemos palabras clave para agrupar un conjunto de condiciones, en este caso vemos all que significa que todas las condiciones tienen que evaluar a True para que pase y se ejecute el bloque de c贸digo siguiente.

En nuestro ejemplo la palabra hi cumple las condiciones a, b y c por lo tanto pasa y se ejecuta el if.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .