Python list 基本方法

01三種刪除方法

例子代碼List
zllist = ['zhou','Python','IOS','zhou','xcode','pycharm','IPython']

01 remove

delete01 = zllist.remove('zhou')
print(zllist)

02 del 刪除 list

del zllist[1]
print(zllist)

03 有返回值刪除

delete03 = zllist.pop(1)
print(delete03)
print(zllist)

02 List切片 [1:2] 語法 拷貝 List 獲得新的List 【起始位置(未設(shè)置從0開始):結(jié)束位置(未設(shè)置默認(rèn)到尾部)】

print('[ : ]語法應(yīng)用')
zllist = ['zhou','Python','IOS','zhou','xcode','pycharm','IPython']
a = zllist[1:2]
print(a)
b = zllist[1:]
print(b)
c = zllist[:1]
print(c)

[ : ]語法應(yīng)用
['Python']
['Python', 'IOS', 'zhou', 'xcode', 'pycharm', 'IPython']
['zhou']

03 查找該類的所有方法

print(dir(zllist))

04 List 原序列 翻轉(zhuǎn) 返回新序列

zllist02 = [1,2,3,4,5,9,80,7,68]
zllist02.reverse()
print(zllist02)

05sort 方法

正序

zllist02.sort()
print(zllist02)

倒序

zllist02.sort(reverse=True)
print(zllist02)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容