Count Vowels
class PracticeYln(): def __init__(self, text): self.text = text # 不能写 = None, 注释必须举例语句一个空格以上,并且井号后面也有空格! def countvowels(self, text): aa = list(self.text) count = 0 # 不能写 count==0 for i in iter(aa): # 这里不能用0:len(aa) if i in ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']: # 为了严谨,大小写都要写上 count = count + 1 # python没有count++,也没有count+=1的写法! print(count) # 调用: tt = PracticeYln('bbb') tt.countvowels('bbb') tt = PracticeYln('GBKKUDFHKJWS') tt.countvowels('GBKKUDFHKJWS') # 结果: 0 1
May we all proceed with wisdom and grace.
https://www.cnblogs.com/YlnChen/