Python的“中"操作员无法正常工作? [英] Python "in" operator not working correctly?

查看:84
本文介绍了Python的“中"操作员无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的python脚本中的in函数工作非常奇怪.我不知道它是要这样还是3.3中的错误. 这是我的脚本的一部分:

The in function in my python script is working very strange. I have no idea if it is meant to be like this or if this is a bug in 3.3 . Here's part of my script:

command = input("\ ")
if command in ['help', 'HELP', 'Help']:
        print (help)

我第一次尝试,在帮助"无效的情况下输入帮助或帮助"即可.

1st time I tried, inputting help or HELP works while Help does not work.

下次我尝试时,帮助"和帮助"会起作用,而帮助"却不会.

Next time I tried, Help and HELP works while help does not.

每次尝试时,接受和不接受的内容都是随机的.如果这是一个错误或脚本有问题,请有人帮助我.

Every time I try it, it will be random on what it accepts and what does not. Someone please help me if this is a bug or if something is wrong with the script.

推荐答案

help变量在哪里定义(或者您打算使用内置函数)?也许问题在于您要print(command)

Where is the variable help defined (or do you mean to use the builtin)? Perhaps the problem is that you meant to print(command)

您的in语法在我看来还不错.但是请考虑这是否同样有效

Your syntax of in looks fine to me. But consider whether this would work just as well

if command.lower() == 'help':

这篇关于Python的“中"操作员无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆