Always true when testing if string == various OR'ed alternatives

前端 未结 5 1663
时光取名叫无心
时光取名叫无心 2020-11-30 14:57

So the problem I am currently having is that my program always calls the \'md5cypher\' class which I have defined, even if the input is not in that list:

def         


        
5条回答
  •  悲&欢浪女
    2020-11-30 15:11

    if toe=='md5' or 'M' or 'm' or 'Md5' or 'MD5':

    will always be evaluated to

    if toe=='md5' or True or True or True or True :

    What you want is:

    if toe in ('md5', 'M', 'm', 'Md5', 'MD5'):
        print("Md5 Encryption Cypher")
        md5cypher()
    .
    .
    .
    

提交回复
热议问题