PYTHON - Uppercase and Lowercase

♀尐吖头ヾ 提交于 2019-12-02 23:52:54

问题


In my code it is;

If 'Laia' in name:

But how do I make it so even if they input; LaIa or laiA. No matter what case(upper or lower) it reads as the same thing.


回答1:


I would suggest you convert all input to lowercase using the .lower() function, and compare the input with a lowercase string: 'laia' like so

name = raw_input('What is the name? ').lower()
if name == 'laia':
    # do stuff


来源:https://stackoverflow.com/questions/24150936/python-uppercase-and-lowercase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!