Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
避免python中的区分大小写_Python_Case Sensitive - Fatal编程技术网

避免python中的区分大小写

避免python中的区分大小写,python,case-sensitive,Python,Case Sensitive,我需要使下面的代码忽略任何大小写敏感性 代码如下: sentence=str(input("Enter sentence") words=sentence.split() uword=input("enter word from sentence") if uword in words: print("Word is in sentence") else: print("Word isn't in sentence") 例如,如果我输入句子“Hello World”作为句子变量

我需要使下面的代码忽略任何大小写敏感性 代码如下:

sentence=str(input("Enter sentence")
words=sentence.split()
uword=input("enter word from sentence")
if uword in words:
    print("Word is in sentence")
else:
    print("Word isn't in sentence")

例如,如果我输入句子“Hello World”作为句子变量,然后输入“Hello”作为uword变量,代码应该识别Hello和Hello是相同的,并打印(“你的单词在句子中”)

这感觉有点像显而易见的答案:

将两个字符串转换为小写或大写:

words = sentence.lower().split()
…
if uword.lower() in words:

input
已返回一个
str
;设置
句子的调用是多余的。非常感谢,如果将句子变量输入为“Hello World”,将uword变量输入为“Hello”,则您的建议有效,但您能否告诉我如何使其工作,以便将句子变量输入小写,将uword变量输入小写?谢谢,againIt在这种情况下也能工作。很抱歉,我无法让它以这种方式工作,如果句子变量输入为全小写,而uword变量输入为大写字母,则不工作。uword通过
uword.lower()
转换为小写。这个代码没有问题。