PHP前端开发

python中for是什么

百变鹏仔 1个月前 (01-23) #Python
文章标签 python

python for循环可以遍历任何序列的项目,如一个列表或者一个字符串。

语法:(推荐学习:Python视频教程)

for循环的语法格式如下:

for iterating_var in sequence:   statements(s)

流程图:

立即学习“Python免费学习笔记(深入)”;

实例:

#!/usr/bin/python# -*- coding: UTF-8 -*- for letter in 'Python':     # 第一个实例   print '当前字母 :', letter fruits = ['banana', 'apple',  'mango']for fruit in fruits:        # 第二个实例   print '当前水果 :', fruit print "Good bye!"

以上实例输出结果:

 当前字母 : P当前字母 : y当前字母 : t当前字母 : h当前字母 : o当前字母 : n当前水果 : banana当前水果 : apple当前水果 : mangoGood bye!

更多Python相关技术文章,请访问Python教程栏目进行学习!