Python重修之Day1-變數型別
阿新 • • 發佈:2020-08-03
重修第一天:資料型別。
變數型別
Python的變數型別有:Int(Numbers)、Str(String)、Dict(Dictionary)、List、Tuple、布林(True&False)、空(None&‘’)等。
1、數字型別又分為:Int、Float、Complex等三種類型,但只有前兩種屬於常用型別。
1 >>> a=10 #整數 2 >>> b=10.11 #小數 3 >>> c=10.1j #複數 4 >>> a 5 10 6 >>> bView Code7 10.11 8 >>> c 9 10.1j
2、字串
>>> s='life is shot' >>> s1="life is shot" >>> s2='''life is shot,you need python''' >>> s3="""life is shot,you need python"""
3、字典
>>> d={'a':1,"b":2}
4、列表
>>> l=[1,2,3,4,5]
5、元組
>>> t=(1,2,3,4)
6、布林
>>> a=True >>> b=False
7、空
>>> a=None >>> b=''
變數賦值
1、單變數
>>> a=1 >>> b=2 >>> c=3
2、多變數
>>> a=b=c=1 >>> a,b,c=1,2,3
型別轉換
int(變數),將變數的值轉為整型
float(變數),將變數的值轉為實數
str(變數),將變數的值轉為字串
tuple(變數),將變數的值轉為元組
list(變數),將變數的值轉為列表
dict(變數),建立字典
eval(變數),將字串轉為字典
repr(變數),將字典轉為字串