标签:oss ext opera 没有 nbsp bin method you image
格式:for 变量 in 列表:
while 表达式:
一、for循环
#!/usr/bin/python
#for [0..5]
sum = 0; #当我没有初始化sum时,会提示TypeError: unsupported operand type(s) for +: 'builtin_function_or_method' and 'int'
for x in [0, 1, 2, 3, 4, 5]:
sum = sum + x;
print x, sum;
print sum;
#for [0..5]
sum = 0;
for x in range(6):
sum += x;
print x, sum;
print sum;
#for list/tuple
list = ['a', 'b', 'c', 'you'];
for list in list:
print list;
二、while循环
#!/usr/bin/python
n = 9
while n > 0:
print n;
n -= 1; #python不支持 ++/--操作
标签:oss ext opera 没有 nbsp bin method you image
原文地址:http://blog.51cto.com/13502993/2142584