当前位置:Gxlcms > Python > python入门之语句(if语句、while语句、for语句)

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

时间:2021-07-01 10:21:17 帮助过:39人阅读

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

  1. //if语句例子
  2. name = 'peirong';
  3. if name == 'peirong':
  4. print 'this is peirong';
  5. elif name== 'maojun':
  6. print 'this is maojun';
  7. else:
  8. print 'others';
  9. //while语句
  10. i = 0;
  11. a = range(10);
  12. while i < a.__len__():
  13. print i;
  14. i = i+1;
  15. //for语句
  16. a = range(1,10);
  17. for i in a:
  18. print i;
  19. else:
  20. print 'The for loop is over!'
  21. //continue 语句
  22. a = range(1000)
  23. for i in a:
  24. if i % 3 == 0:
  25. print 'chuyi 3 yu 0 ';
  26. elif i % 3 == 1:
  27. print 'chuyi 3 yu 1 ';
  28. else:
  29. continue

人气教程排行