Python while和for循环
更多资料下载,冲击月薪过万,一线经验工程师录制,
干货满满的嵌入式视频教程,请点击淘宝店:wanglitao.taobao.com
While循环使用举例
# -*-coding:utf-8 -*-
__author__ = 'zhaixue.cc'
i = 0
s = 0
while i < 9:
s =s + i
i = i + 1
print s
运行结果:
C:\Python27\python.exe F:/python/python_proj/base.py
36
Process finished with exit code 0
For循环使用举例
# -*-coding:utf-8 -*-
__author__ = 'zhaixue.cc'
for i in range(1,5):
print i
fruit = ['apple','orange','peach']
for i in fruit:
print i
fruit = ('apple','orange','peach')
for i in fruit:
print i
telbook ={'lilei':13745877854, 'jim':13654877854, 'kate':13425411254}
for i in telbook:
print i,'\t',telbook[i]
运行结果如下:
C:\Python27\python.exe F:/python/python_proj/base.py
1
2
3
4
apple
orange
peach
apple
orange
peach
lilei 13745877854
jim 13654877854
kate 13425411254
Process finished with exit code 0
《Linux三剑客》视频教程,从零开始快速掌握Linux开发常用的工具:Git、Makefile、vim、autotools、debug,免费赠送C语言视频教程,C语言项目实战:学生成绩管理系统。详情请点击淘宝链接:Linux三剑客