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()

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章标题:python循环:for()、while()-创新互联
转载源于:http://pwwzsj.com/article/dgoidg.html