码迷,mamicode.com
首页 > 编程语言 > 详细

Learn Python 012: for loop

时间:2017-07-16 18:24:43      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:super   oop   pre   nts   text   and   cal   python   doc   

# 1

vowels = 0
consonants = 0

for letter in ‘supercalifragilisticexpialidocious‘:
    if letter.lower() in ‘aeiou‘:
        vowels = vowels + 1
    elif letter == ‘ ‘:
        pass
    else:
        consonants = consonants + 1
print(‘There are {} vowels in the text.‘.format(vowels))
print(‘And there are {} consonants in the text.‘.format(consonants))

# 2

students = {
    ‘male‘: [‘Bob‘, ‘Clark‘, ‘Frank‘, ‘Graig‘],
    ‘female‘: [‘Alice‘, ‘Emma‘, ‘Helen‘]
}
for key in students.keys():
    for name in students[key]:
        if ‘a‘ in name:
            print(name)

 

Learn Python 012: for loop

标签:super   oop   pre   nts   text   and   cal   python   doc   

原文地址:http://www.cnblogs.com/mxyzptlk/p/7190998.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!