简体   繁体   English

值是预期值,但如果语句无法识别?

[英]Value is the expected value, but if statement won't recognize?

monsters.create()

for monster in World.monsters:
    if monster.name == "Valley Wolf":
        Game.Log("Found the wolf!")
    else:
        Game.Log("Could not find the wolf!")

The above code results in "Could not find the wolf!"上面的代码导致“找不到狼!” printing, but when I change it to the following:打印,但是当我将其更改为以下内容时:

monsters.create()

for monster in World.monsters:
    Game.Log(monster.name)

it prints "Valley Wolf".....I'm very confused why the value seems to be "Valley Wolf", and yet the if statement is returning False and running the else....它打印“Valley Wolf”.....我很困惑为什么值似乎是“Valley Wolf”,但 if 语句返回 False 并运行 else ....

It could be because of extra characters, so try:可能是因为额外的字符,所以尝试:

for monster in World.monsters:
    if "Valley Wolf" in monster.name:
        Game.Log("Found the wolf!")
    else:
        Game.Log("Could not find the wolf!")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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