yangwooyel
yangwooyel

Reputation: 41

I don't know why 'if' statement is true

This is my Python code:

funcName = 'anything'
if funcName.find("Start") > 0 or funcName.find("start") > 0 or 
funcName.find("Main") > 0 or funcName.find("main"):
    print 'success'
else:
    print 'fail'

The code output is success, but I think output must be fail.

Why is the output success?

Upvotes: 1

Views: 85

Answers (1)

Jack Bashford
Jack Bashford

Reputation: 44087

You need to check the last find call too - -1 won't be automatically regarded as false.

if funcName.find("Start") > 0 or funcName.find("start") > 0 or funcName.find("Main") > 0 or funcName.find("main") > 0:

Upvotes: 8

Related Questions