Python Forum

Full Version: dict problem with if
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi , I have a little problem with my code , can you explain the problem to me and help to fix it please ? What should I do ? Thanks

dict={"Name":"Adem",
     "Surname":"Ben rhouma"}

if "Name"=="Adem":
    print("My name is {}".format("Name"))
else:
    print("Dont remember my name")
why doesn t it show me "My name is Adem" ?
Try to be careful not to name something that is a built in name, you named your dictionary as dict which is a built in.
you are not accessing the dictionary it should be like this
person = {"Name": "Adem",
        "Surname": "Ben rhouma"}

if person["Name"] == "Adem":
    print("My name is {}".format(person["Name"]))
else:
    print("Dont remember my name")
Output:
My name is Adem
thanks a lot it's working! have a nice day
(Sep-21-2019, 08:55 PM)Adem Wrote: [ -> ]
if "Name"=="Adem":

Do you understand why the expression "Name" == "Adem" evaluates to False?