PythonNoobie
PythonNoobie

Reputation: 29

i have some problem with if statement(Python)

I was working on reading some data from excel. However, i have countered a simple if statement. Not quite sure what have i missed. When i run my code, it will not go into the if statement but it will instead jump to else statement even though the value specified is exactly the same. below is my code. Thank you in advance!

from openpyxl import load_workbook
wb = load_workbook()
sheet_ranges = wb['Sheet1']
xd_date_count = 3
cookie = sheet_ranges['A' + str(xd_date_count)].value # i have a value "None" stored in A3 in this excel
print(cookie) # when i print this, it prints out None
if cookie == "None":
    print("ok")
else:
    print("no")

Upvotes: 0

Views: 45

Answers (1)

David
David

Reputation: 699

If you are looking for a None object, you should try None in stead of "None", as this will be interpreted as a string.

In addition

if cookie is None:

is nicer to read, but that's just a personal flavor thing

Upvotes: 1

Related Questions