#-*- coding:UTF-8 -*- #for .... in 循环 names=['Michel','Bob','Tracy'] for name in names: print name #for x in ... 把每个元素代入变量 x sum =0 for x in [1,2,3,4,5,6]: sum=sum+x print sum #range()函数可以生成一个整数序列,range(5)生成0到4的整数序列 sum =0 for x in range(101): sum=sum+x print sum #while 循环,只要条件满足就不断循环,条件不满足时退出,计算100以内的所有奇数之和 sum=0 n=99 while n>0: sum=sum+n n=n-2 print sum