显示用户输入
user = raw_input('输入名字:') //raw_input是内建的函数
====>输入名字:root
print 'name is :',user===>name is :root
//int()字符串转数字
num = raw_input('')
1024
print '%d' % (int(num)*2)
2048
#为注释
符号:+,-,*,/。基本符号
//浮点除法,%取余,**乘方
比较运算符 >,>=,<,<=,==,!=
逻辑运算:and or not
数字类型:int,long,bool,float,complex
字符串:pystr='Python'
iscool = 'is cool!'
pystr[0]===>'P' //取第一个字符
pystr[2:5]===>'tho' //取2--5的索引
iscool[:2]==>'is' //取从头到索引2
iscool[3:]==>'cool!'//取索引3到最后
iscool[-1]===>'!' //取最后一位
pystr+iscool===>'Pythonis cool!' //字符连接
pystr+' '+iscool==>'Python is cool!'
pystr*2===>'PythonPython' //输出2遍
'_'*20===>'____________________' //输出20个_
pystr='''python
... is cool'''
pystr===>'python/nis cool'
print pystr====>python
is cool
数组和元数据
aList =[1,2,3,4]
aList===>[1,2,3,4]
aList[0]===>1
aList[2:]===>[3,4]
aList[:3]===>[1,2,3]
aList[1]=5
aList===>[1,5,3,4]
元组不能被修改
aTuple =('robots',77,93,'try')
aTuple===>('robots',77,93,'try')
aTuple[:3]==>('robots',77,93)
aTuple[1]=5 //出错
字典 //类似map
aDict = {'host':'earch'}
aDict['port'] = 80
aDict===>{'host':'earch','port':80}
aDict.keys()==>['host','port']
aDict['host']===>'earch'