I have a question for Python if.

Asked 2 years ago, Updated 2 years ago, 130 views

per1="25"
per2  = ".75"
if row[23] == 'sale1' or row[23] == 'sale2':
    if row[27].find(per1) == -1:
        cursor.execute(sql)
else:
    cursor.execute(sql)

Or 

per2  = ".75"
if row[23] == 'sale1' or row[23] == 'sale2':
    if row[27].find(per2) == -1:
        cursor.execute(sql)
else:
    cursor.execute(sql)


If I do this, it'll be filtered properly 

per1 = ".25"
per2  = ".75"
if row[23] == 'sale1' or row[23] == 'sale2':
    if row[27].find(per1) == -1 and row[27].find(per2) == -1:
        cursor.execute(sql)
else:
    cursor.execute(sql)
In this case, it doesn't filter at all.
Why is that?

python if-else find

2022-09-21 14:16

1 Answers

per1 = ".25"
per2  = ".75"
if row[23] == 'sale1' or row[23] == 'sale2':
    if row[27].find(per1) == -1 or row[27].find(per2) == -1:
        cursor.execute(sql)
else:
    cursor.execute(sql)

Change "and" to "or".


2022-09-21 14:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.