list1=
['a'
,'d'
,'c'
,'b'
(sorted
(list1,reverse=
true))
#['d', 'c', 'b', 'a']
(sorted
(list1,reverse=
false))
#['a', 'b', 'c', 'd']
# del list[index] 刪除指定索引位置元素
# remove(』a『) 刪除列表中第乙個出現的元素a,返回值是none,如果沒有找到要刪除元素則報異常
# pop() 彈棧,刪除列表中的最後乙個元素,返回值是刪除的那個元素,但是也可以指定index的元素
# clear() 清空列表元素
# reverse() 改變列表的元素位置結構,反轉順序,[::-1]只是取資料按反轉順序
list1.remove(
'c')
(list1)
#['a', 'd', 'b']
list1.pop(1)
(list1)
#['a', 'b']
list2=
['a'
,'d'
,'c'
,'b'
]list2.reverse(
(list2)
#['b', 'c', 'd', 'a']
list3=
['a'
,'d'
,'c'
,'b'
(list3[::
-1])
#['b', 'c', 'd', 'a']
python列表筆記
1.列表可以包含任意字元 結構 型別的資料 例 shuaige 帥 有錢 高 95599,true,等等 print shuaige print shuaige 輸出顯示如下 帥 有錢 高 95599,true,等等 帥 有錢 高 95599,true,等等 牛鼻 檢測 解藥 是否在inventor...
python 列表(筆記)
a 1,2,3 b a b只是貼在a 上的標籤,b變a也變 c a 用切片實現 這才是真正的複製,給 c 也分了記憶體 a.extent element1,element2,a.insert indx,element a.remove element a.pop index del a 0 del ...
Python列表筆記
使用for迴圈生成列表元素,可以迴圈巢狀。舉例 urls a.get href for a in title.find all a 0 for title in title python中符合序列的有序序列都支援切片 slice 例如列表,字串,元組。格式 start end step start ...