dimanche 29 septembre 2019

Python, Difference between if and elif

What is the difference beetwen if and elif?

Example code

If statement with elif statement

if x == y:
 print(x)
elif x == "a":
 print(x)

If statement without elif statement

if x ==y:
 print(x)
if x =="a" and x != y:
 print(x)

What's the difference? Because the second if statement used "and" key

Aucun commentaire:

Enregistrer un commentaire