python中的for
来源:互联网 发布:淘宝怎么投诉客服 编辑:程序博客网 时间:2024/06/12 00:26
Python for循环可以遍历任何序列的项目,如一个列表或者一个字符串。(与c语言不同)
程序:
for letter in 'Python': print '当前字母 :', letter fruits = ['banana', 'apple', 'mango']for fruit in fruits: print '当前字母 :', fruit
结果:
当前字母 : P
当前字母 : y
当前字母 : t
当前字母 : h
当前字母 : o
当前字母 : n
当前字母 : banana
当前字母 : apple
当前字母 : mango
Python for循环可以遍历任何序列的项目,如一个列表或者一个字符串。
for letter in 'Python':
print '当前字母 :', letter
fruits = ['banana', 'apple', 'mango']
for fruit in fruits:
print '当前字母 :', fruit
当前字母 : P
当前字母 : y
当前字母 : t
当前字母 : h
当前字母 : o
当前字母 : n
当前字母 : banana
当前字母 : apple
当前字母 : mango
for letter in 'Python':
print '当前字母 :', letter
fruits = ['banana', 'apple', 'mango']
for fruit in fruits:
print '当前字母 :', fruit
当前字母 : P
当前字母 : y
当前字母 : t
当前字母 : h
当前字母 : o
当前字母 : n
当前字母 : banana
当前字母 : apple
当前字母 : mango
0 0
- python中的for循环
- python for 中的range
- python中的for...else...
- python中的for循环
- python中的for循环
- Python中的for语句
- Python中的for
- python中的for
- python中的for语句
- python 中的 for 迭代
- python中的for循环问题
- Python 中的for-else用法
- python中的if、while、for
- python中的for...else的使用方法
- python 中的迭代 for zip 字典
- 关于Python中的for循环控制语句
- 关于Python中的for循环控制语句
- 关于Python中的for循环控制语句
- Spring的开发步骤(7条)
- tar 命令 解压缩
- Spring第一次创建对象,小案例(4条)
- Spring创建对象小案例,单例singleton,多例prototype(7条)
- 76、Singleton和prototype分别在什么时候创建对象?(9条)
- python中的for
- C++ PRIMER PLUS 第六版编程答案(一)
- C++ PRIMER PLUS 第六版编程答案(二)
- MyBatis(1):MyBatis入门
- JAVA重写(覆盖)与重载
- 77——是否延迟创建?lazy-init(9条)
- 【codeforces 550A】Two Substrings
- 学习tbshedule遇见问题一:javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initializ
- 78——创建对象之,初始化(init-method)和销毁(destroy-method)(6条)