不能从辅音确定元音 [英] Cannot determine vowels from consonants

查看:112
本文介绍了不能从辅音确定元音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码,无论输入的第一个字母是什么,它总是确定为元音:

With the code below, no matter what the first letter of the input is, it is always determined as a vowel:

original = raw_input("Please type in a word: ")
firstLetter = original[0]
print firstLetter

if firstLetter == "a" or "e" or "i" or "o" or "u":
    print "vowel"
else:
    print "consonant"

事实上,在if语句中布尔值无关紧要,如果是==或!=,它仍然返回vowel。为什么?

In fact, it doesn't matter what the boolean is in the if statement... if it is == or != , it is still return "vowel". Why?

推荐答案

Python不是英语。如果你有一堆表达式或或在它们之间,每一个必须有自己的意义。注意自己:

Python is not the English language. If you have a bunch of expressions with or or and between them, each one must make sense on its own. Note that on its own:

if "e":
    print("something")

将始终打印某些,即使字母不等于e

will always print something, even if letter doesn't equal "e".

这个:

if letter == "a" or letter == "e"  # (...)

或更简洁:

if letter in "aeiouy":

这篇关于不能从辅音确定元音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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