dimanche 25 octobre 2020

Python if statement executes on False condition [closed]

I'm writing a function:

def get_second_element(table):
  text = "Some text"
  if len(table) > 1 and text not in table[1]:
    print(len(table) > 1 and text not in table[1])
    print(table[1])
    return table[1]
  else:
    return None

Calling a function:

table = ['Other', 'Some text']
get_second_element(table)

Gives me an output:

False
Some text

The if part is not supposed to be executed at all. Have anybody had similar issue before?

Aucun commentaire:

Enregistrer un commentaire