PHP前端开发

python中有for函数吗

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

python中有for函数,一般用于三种情况下,下面会具体给大家介绍:

Python for循环语句

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

语法:

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

for循环的语法格式如下:

for iterating_var in sequence:   statements(s)

实例

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

以上实例输出结果:

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

通过序列索引迭代