码迷,mamicode.com
首页 > 编程语言 > 详细

Python-for循环

时间:2015-04-12 17:22:17      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

循环语句 for语法结构:

for  target  in  sequences :

  • statement
  • statement
  • etc...

sequences的数据类型

  • list
  • tuple (元组)
  • strings
  • files 

 

 



 

循环for遍历 string 和 list

 

 

技术分享


 


 

循环体for遍历文件 和 元组

list 每个数据项可以修改,但是元组不可以修改

#元组
tup = (1,2,3,4,5)
for t in tup:
    print t
else:
    print out  tup

遍历文件

 技术分享

file.read 返回的是字符串

for n in open("a.txt" , "r").readline():

  print format(n , "2d")

 技术分享

Python-for循环

标签:

原文地址:http://www.cnblogs.com/Mokaffe/p/4419717.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!