mardi 27 juillet 2021

Python Dictionary if clause [duplicate]

as you can tell, I just recently started to learn python.

While practising, I stumbled upon an issue, for which I don´t have an answer to why this is the case.

My Code looks like this:

d = {"Groningen": "GRO", "Berlin": "BER", "Rotterdam": "RTD"}
if "Budapest" or "Saigon" in d:
    print("Budapest or Saigon are in the dictionary")
else: 
    print("Budapest or Saigon are not in the dictionary")

Python now prints the if clause, even though "Budapest" or "Saigon" are not in the dictionary.

The solution is probably super simple, but I just can't figure it out myself. Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire