欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python入门之语句(if语句、while语句、for语句)

程序员文章站 2022-07-21 22:52:12
python入门之语句,包括if语句、while语句、for语句,供python初学者参考。 //if语句例子 name = 'peirong'; if...

python入门之语句,包括if语句、while语句、for语句,供python初学者参考。

//if语句例子
name = 'peirong';

if name == 'peirong':
 print 'this is peirong';
elif name== 'maojun':
 print 'this is maojun';
else:
 print 'others';

//while语句
i = 0;
a = range(10);
while i < a.__len__():
 print i;
 i = i+1;

//for语句
a = range(1,10);
for i in a:
 print i;
else:
 print 'the for loop is over!'

//continue 语句
a = range(1000)
for i in a:
  if i % 3 == 0:
    print 'chuyi 3 yu 0 ';
  elif i % 3 == 1:
    print 'chuyi 3 yu 1 ';
  else:
    continue