对Python来说是完全陌生的。无法理解下面写的一行代码

对Python来说是完全陌生的。无法理解下面写的一行代码,python,Python,我很难理解下面几行Python代码。编写代码是为了查找单词“milliways”中包含的元音 有人能帮我理解上面的代码吗。因此,在代码的前3行中,我们首先创建一个要搜索的字母(元音)列表,定义一个词来搜索元音,并创建一个空数组来存储找到的元音 接下来,我们遍历所选单词的每个字母,并检查该字母是否为元音,是否已在列表中找到元音,如果符合这些条件,我们将元音添加到“已找到”列表中 在最后两行代码中,我们只需循环查看找到的元音列表,并将它们打印出来,以查看我们在单词中找到的元音。我已在代码中添加了注释

我很难理解下面几行Python代码。编写代码是为了查找单词“milliways”中包含的元音


有人能帮我理解上面的代码吗。

因此,在代码的前3行中,我们首先创建一个要搜索的字母(元音)列表,定义一个词来搜索元音,并创建一个空数组来存储找到的元音

接下来,我们遍历所选单词的每个字母,并检查该字母是否为元音,是否已在列表中找到元音,如果符合这些条件,我们将元音添加到“已找到”列表中


在最后两行代码中,我们只需循环查看找到的元音列表,并将它们打印出来,以查看我们在单词中找到的元音。

我已在代码中添加了注释,以便您可以看到发生了什么

vowels = ['a' , 'e' , 'i' , 'o' , 'u'] # this declares a list of vowels
word = "milliways" # declares an input word
found = [] # used to store list of vowels in word

for letter in word: # iterates through every character in word
    if letter in vowels: # checks if character is in the vowels list
        if letter not in found: 
            found.append(letter) # if the character is a vowel, and not in found list it adds it

for vowel in found: # prints list of vowels in word
    print(vowel)

请重新格式化您的代码,使其正常工作。(缩进)编程学校也不是这样。大多数台词都非常简单,即使是初学者也应该能够理解。你能不能把你不明白的说得更清楚一点?投票结果太笼统了。本网站不是教程服务。我们必须假设您对该语言的理解程度最低。如果您不理解
word=“milliways”
的功能,您需要学习Python教程并学习基础知识。感谢大家的反馈…非常感谢Patrick和Usernamenotfound的解释。谢谢您的回答
vowels = ['a' , 'e' , 'i' , 'o' , 'u'] # this declares a list of vowels
word = "milliways" # declares an input word
found = [] # used to store list of vowels in word

for letter in word: # iterates through every character in word
    if letter in vowels: # checks if character is in the vowels list
        if letter not in found: 
            found.append(letter) # if the character is a vowel, and not in found list it adds it

for vowel in found: # prints list of vowels in word
    print(vowel)