vendredi 30 avril 2021

Why does Python print the else statement here?

The output of the below code is

Hello
Hola

Why does it print the "Hola"? Shouldn't the else statement be exempt when passing 'en' into the function?

def greet(lang):
    if lang == 'en':
        print("Hello")
    if lang == 'fr':
        print('Bonjour')
    else:
        print('Hola')

greet('en')

Aucun commentaire:

Enregistrer un commentaire