samedi 2 septembre 2017

Odd behaviour from conditional statement?

dummy_list = ["1", "2", "3", "4"]

f 1 in dummy_list is [0]:
    print ("it is the first element")
else:
    print ("no it is not the first element")

I am trying to check through a list, identify if a variable's position in the list is within a specified locale. Now, despite the fact that [0] IS 1, (i verified this by the following):

print (dummy_list[0]) 

Which returned 1; I am confused then as to why the conditional statement is stating otherwise.

Aucun commentaire:

Enregistrer un commentaire