PYTHON - 大写和小写 [英] PYTHON - Uppercase and Lowercase

查看:52
本文介绍了PYTHON - 大写和小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中是;

If 'Laia' in name:

但是,即使他们输入,我如何做到这一点;LaIa 或 laiA.无论大小写(大写或小写)都是一样的.

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.

推荐答案

我建议您使用 .lower() 函数,并将输入与小写字符串进行比较:'laia' 像这样

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

这篇关于PYTHON - 大写和小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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