字典
dic={'name':'milo','age':25,'gender':'male'}
dic['name']
del(dic['age'])
dic.clear()
del(dic)
dic.get(2) dic.get(5,'error')
help(dict.keys)
dic.keys()
dic.values()
for k in dic:
print k
print dic[k]
if expression:
statement(s) 使用4个空格代替缩进
if expression:
statement(s)
else:
statement(s)
if expression:
satement(s)
elseif expression2:
statement(s)
elseif expression3:
statement(s)
else:
statement(s)
x=int(raw_input("please input:"))
if x>=90:
print "A"
elseif x>=80:
print "B"
else:
print "C"
逻辑运算符 or and not
for iteratin_var in sequence:
statements(s)
for x in [0,1,2,3,4]:
print x,"hello world"
for x in range[100]: 从0到99增长
fox in in range[1,11,2]:从1到10增长,步进值2
for遍历数据
s="hellow"
for k in s:
print kfor k in range(len(s)):
print s[k]
dic={1:111,2:222,3:333}
for x in dic:
print x 输出key值
print dic[x] 输出value值
print dic.items() 输出全部值
for x,y in dic.items():
print x,y 输出全部值
time.sleep(1)延时1秒
for x in range(1,11):
print x
if x==3:
pass 占位
if x==2:
print "hello 2"
continue
if x==5:
exit() 跳出整个循环
if x==6:
break
print "#"*5
else:
print "ending"