RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
python循环:for()、while()

格式:

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名与空间、虚拟空间、营销软件、网站建设、武汉网站维护、网站推广。

    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;

python 循环:for()、while()

#for [0..5]
sum = 0;
for x in range(6):
    sum += x;
    print x, sum;
print sum;

python 循环:for()、while()

python 循环:for()、while()

#for list/tuple
list = ['a', 'b', 'c', 'you'];
for list in list:
     print list;

python 循环:for()、while()

二、while循环

#!/usr/bin/python

n = 9
while n > 0:
    print n;
    n -= 1;  #python不支持 ++/--操作

python 循环:for()、while()


分享名称:python循环:for()、while()
本文路径:http://sczitong.cn/article/jjghdd.html