标签:style blog io color sp for strong on div
if语法:
类型一:
if expression : if_suit else: else_suit
例如:
adic={"name":"paulwinflo","age":18,"sex":"man"} if "name" in adic: print "hello "+ adic["name"] else: print "no this key "
类型二:
if expression :#条件一 if_suit
elif expression1 :#条件二
elif_suit
elif expression2 :#条件三
elif_suit
..
..
else: #其他情况下
else_suit
例如:
num=input("please input a number:") if num > 0 : print str(num) + " is above zero" elif num < 0: print str(num) + " is ablow zero" else: print str(num) + " is eqel zero"
while语法: while语句会不停地执行下去直到条件false.
while expression: while_suit
例如:
num=input("please input a number:") while num > 8 and num <13 :##符合条件的数进入while循环 print str(num)+" is ok" num+=1
for语法: 主要功能还是遍历功能
for a in range(7): print a,
标签:style blog io color sp for strong on div
原文地址:http://www.cnblogs.com/paulwinflo/p/4169436.html