1. 程式人生 > 遊戲 >日本一SRPG《魔物飯大冒險》新更新1.20確定3月上線

日本一SRPG《魔物飯大冒險》新更新1.20確定3月上線

列表 list

在列表中存放多個數據 列表用中括號表示 []

建立一個列表  [],中間的每一項,用 ,(英文的逗號) 分隔開
a = []        # 建立了一個空的列表
print(type(a))

b = ['張三',28,100.86]
print(type(b))

增加一個元素 函式:append

c = ['hello','python','linux','mysql','git']

c.append('你好')    # 向列表c中增加一個元素 你好
print(c)

修改列表中某一個元素

c = ['hello','python','linux','mysql','git']

c[2] = 'centos' # 將列表中的第二個元素,修改為centos print(c)

刪除列表中某一個元素 函式:del

c = ['hello','python','linux','mysql','git']

del c[3] # 刪除列表中的第三個元素 print(c)

讀取列表的某個元素,通過列表的下標 Index (從0開始)讀取  

c = ['hello','python','linux','mysql','git']

print( c[2] ) #讀取第2個下標

統計出列表的長度(列表有多少個元素) 函式:len()

c = ['hello','python','linux','mysql','git']

print( len(c) )