如何在Python 3中简化IF语句

乔·黄

我的IF语句如下:

...
if word.endswith('a') or word.endswith('e') or word.endswith('i') or word.endswith('o') or word.endswith('u'):
...

在这里,我不得不使用4个OR来覆盖所有情况。无论如何,我可以简化一下吗?我正在使用Python 3.4。

哈菲斯·卡洪基尔(Hafees Kazhunkil)

尝试

if word[-1] in ['a','e','i','o','u']:

其中word [-1]是最后一个字母

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章