Python-如何检查一个单词是否有小写和大写

标签 python

我正在做一个学校项目。 我对如何使 ( if ) 语句检测大写和小写字符感到困惑。 我尝试在 if 语句中使用“and”,但它太长了。 我当前的输入是:

a=input('Line: ')
if 'robot' in a:
 print('There is a small robot in the line.')
elif ('robot'.upper()) in a:
 print('There is a big robot in the line.')
elif b in a:
 print('There is a medium robot in the line.')
else:
 print('No robots here.')

不要介意(b)我只是在想一些我不知道如何解释的事情。 我正在寻找的输出示例如下:

There is a "robot" in the line
then it would print
'There is a robot in the line'

程序将检查大写和小写字符。 如果输入全部大写,它将打印出来 队伍里有一个大机器人 如果输入只有小写字母,那么它只会打印 队伍里有一个小机器人。 如果输入同时包含小写和大写,则会打印: 队列中有一个中型机器人。

最佳答案

您可以先将输入小写,然后再检查小写的 robot 是否在输入字符串中:

更改:

elif b in a:

至:

elif 'robot' in a.lower():

关于Python-如何检查一个单词是否有小写和大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51887864/

相关文章:

Python;计算向量的元素

python - 按 A 列删除重复项,保留 B 列中具有最高值的行

python - 两个不同的 Python 类与同一底层对象共享属性

Python3 dbus导入错误: undefined symbol: _Py_ZeroStruct

c++ - 如何确定请求了哪个编译器

c++ - Boost python,暴露迈耶斯单例

python - python中的列表形成

python - 在 App Engine (Python) 上将文本转换为 PNG

python - 在 Jupyter Notebook 中调试 Flask 服务器

python - 如何避免路径遍历安全漏洞