简体   繁体   中英

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?

您还需要检查最后一个find调用 - -1不会自动被视为错误。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM