首页 > 代码库 > python基础

python基础

#coding=utf-8print "你好,世界"print 2**10var =1print var##x=input("x:")##y=input("y:")##print x*yprint 12+int(1)print str(12)+"1"seq="0123456789"print seq[0]print seq[-1]print seq[0:5]print seq[5:]print seq[-3:-1]print seq[-3:]print seq[:]print seq[::2]print seq[::-2]print seq[9:1:-1]print [1,2,3]+[4,5,6]print [1,2,3]*2print [None]*10print 1 in [1,2]data=[0,1,2,3,4,5,6,7,8,9]data[0]="a"print datadel data[0]print datadata[6:]=[8,9,10]print data#字符串格式化print "% 10s" % "------"print {"title":"title","body":"body"}print dict(title="title",body="body")print a,b#三元运算符print "10>1" if 10>1 else "unhappened"for x in range(1,10):    print xfor x in range(1,10,2):    print xfor key in {"title":"title","body":"body"}:    print key#带索引的遍历for index,x in enumerate(range(1,10)):    print index,x#zip 方法##    for x,y in zip(range(1,10),range(1,10)):##        print x,y    if(11==11):        pass    exec(print(x),{"x":"abc"})    print (eval(x*2,{"x":5}))    print range(len([4,2]))

 

python基础