一、变量

python是动态类型语言,不需要声明变量的类型,变量的值和类型在赋值的那一刻被初始化。  

二、数字###

python支持5种基本数字类型
有符号整型、长整型、布尔值、浮点值、复数

三、字符串###

pystr = ‘python’
iscool = ‘is cool’
prstr[0] #第一个字符的索引是0
‘p’
prstr[2:5] #切片
‘tho’
iscool[:2]
‘is’ iscool[3:]
‘cool’
pystr + iscool
‘pythonis cool’
pystr * 2 #重复
‘pythonpython’

四、列表和元组###

aList = [1,2,3,4]
aList
[1,2,3,4]
aTuple = (‘robots’,77,93,’try’)
aTuple
(‘robots’,77,93,’try’)
元组不可修改,只可读

五、字典###

由键值对构成

aDict = {‘host’:’earth’}
aDict[‘port’]=80
aDict
{‘host’:’earth’,’port’:80}

转载于:https://my.oschina.net/likeai34/blog/690055