python - 找出单词之间的差异

标签 python python-3.x

我试图让我的代码区分八个以不同字母开头的单词,我所能得到的只是一个 if-else 语句,如果没有八个输入,我就无法让 if-elif 语句工作弹出。我知道这是一个简单的问题,但我是 python 的新手。

我的代码:

if input().lower().startswith('z'):
    print('yes')
elif input().lower().startswith('x'):
    print('no')

最佳答案

将输入存储在一个变量中,然后测试该变量

text = input().lower()

if text.startswith("z"):
     # etc

关于python - 找出单词之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24898721/

相关文章:

python - 有没有办法将相同的值传递给函数的所有参数?

python - 我如何将此代码放入函数中

Python:需要捕获 open() 异常吗?

python Pandas : Generate a new column that calculates the subtotal of all the cells above that row in a specific column

python - 将数据从 redis 哈希转储到 postgresql 表的更快方法

python - 将子对象的方法放置在我的类中

regex - 用于检查捕获组之间的子字的正则表达式

python-3.x - 在添加Python代码作为Kibana插件方面需要帮助

python - 基于字符串匹配打印列表的二维矩阵

python - 将用户输入运算符分配给变量