vendredi 2 septembre 2016

Checking if the value of a string is true - python

Hello fellow developers,

I am trying to see if a string is true or false but im stuck... In the following code I have made a list of statements that I want to evaluate, I have put them in strings because the variables need to be declared after the list is. I want to run through all of the items in the list and if it is a true statement then do something... Here is my code: (There is no output generated)

a = ['b > c', 'b = c', 'b < c']

b = 5
c = 3

for item in a:
    if exec(item):
       print(item)

plz help

Aucun commentaire:

Enregistrer un commentaire