顯示使用者輸入
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'