擅长:python、mysql、java
<p>首先,您没有从函数返回任何内容,而且,您的函数应该使用一个变量来存储和,并在循环执行时不断增加它(而且您不需要将字符串转换为列表来对其进行迭代,字符串也是可iterable的):</p>
<pre><code>def count_vowels(string):
vowel = 'aeiou'
result = 0
for i in vowel:
if i in string:
result += string.count(i)
return result
</code></pre>
<p>但是,更好的方法是反转循环:</p>
<pre><code>def count_vowels(string):
vowel = 'aeiou'
result = 0
for i in string:
if i in vowel:
result += 1
return result
</code></pre>