Learn Python 012: for loop
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Learn Python 012: for loop相关的知识,希望对你有一定的参考价值。
# 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的主要内容,如果未能解决你的问题,请参考以下文章
如何在 scikit-learn 中执行随机森林模型的交叉验证?