码迷,mamicode.com
首页 > 编程语言 > 详细

python学习笔记

时间:2014-06-28 11:35:24      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   art   

1.if语句(python中没有switch语句,可用if……elif……else代替)

格式:

  if 表达式:

    #语句

  else:

    #语句

eg:

bubuko.com,布布扣
number = 23
guess = int(raw_input(Enter an integer:))

if guess == number:
    printCongratulations
    printbut you do not win any prizes!
elif guess < number:
    printNo,it is higher
else:
    printNO,it is lower
printDone
View Code

2.while语句

格式:

while <test>:

  #语句

else:#可跟else从句

eg:

bubuko.com,布布扣
 1 number = 23
 2 running = True
 3 
 4 while running:
 5     guess = int(raw_input(Enter an integer:))
 6     if guess == number:
 7         printCongratulations
 8         running = False
 9     elif guess < number:
10         printit is higher
11     if guess > number:
12         printit is lower
13 else:
14     printThe while loop is over.
15 
16 printDone
View Code

 

3.for语句格式:

for <var> in range(<begin>,<end>):

  #语句

bubuko.com,布布扣
1 for i in range(1,5):
2     print i
3 else:
4     print "The for loop is over"
View Code

 

 

 

 

python学习笔记,布布扣,bubuko.com

python学习笔记

标签:style   blog   http   color   os   art   

原文地址:http://www.cnblogs.com/shijianupc/p/3798912.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!