标签:
#for循环格式(类似Java中的foreach):for 标识符 in 列表名称 :
>>> movies = ["movie1","movie2","movie3"]
>>> for item in movies :
print(item)
movie1
movie2
movie3
#while循环格式:while 循环条件 :
>>> while count < len(movies) :
print(movies[count])
count = count + 1
movie1
movie2
movie3
if 满足某个条件 :
执行某些语句
else :
执行某些语句
>>> new_movies = ["movie1","movie2","movie3",["movie4_1","movie4_2",["movie_4_3_1","movie_4_3_2"]],"movie5"]
>>> def listItems(items) :
for item in items :
if isinstance(item,list) :
listItems(item)
else :
print(item)
>>> listItems(new_movies)
movie1
movie2
movie3
movie4_1
movie4_2
movie_4_3_1
movie_4_3_2
movie5
标签:
原文地址:http://www.cnblogs.com/fange666/p/4676580.html