1、 將元組 (1,2,3) 和集合 {4,5,6} 合并成一個串列,
#將元組 (1,2,3) 和集合 {4,5,6} 合并成一個串列 tuple = (1,2,3) set = {4, 5, 6} list = list(tuple) + list(set) print(list)View Code
2、 在串列 [1,2,3,4,5,6] 首尾分別添加整型元素 7 和 0,
#在串列 [1,2,3,4,5,6] 首尾分別添加整型元素 7 和 0 list = [1, 2, 3, 4, 5, 6] list.insert(0, 7) list.append(0) print(list)View Code
3、 反轉串列 [0,1,2,3,4,5,6,7] ,
#反轉串列 [0,1,2,3,4,5,6,7] list = [0,1,2,3,4,5,6,7] list.reverse() print(list)View Code
4、 反轉串列 [0,1,2,3,4,5,6,7] 后給出中元素 5 的索引號,
#反轉串列 [0,1,2,3,4,5,6,7] 后給出中元素 5 的索引號 list = [0,1,2,3,4,5,6,7] list.reverse() print(list[::-1].index(5))View Code
5、 分別統計串列 [True,False,0,1,2] 中 True,False,0,1,2的元素個數,發現了什么?
#分別統計串列 [True,False,0,1,2] 中 True,False,0,1,2的元素個數,發現了什么 list = [True, False, 0, 1, 2] a = (list.count(True), list.count(False), list.count(0), list.count(1), list.count(2)) print(a)View Code
6、 從串列 [True,1,0,‘x’,None,‘x’,False,2,True] 中洗掉元素‘x’,
#從串列 [True,1,0,‘x’,None,‘x’,False,2,True] 中洗掉元素‘x’, list = [True,1,0,'x',None,'x',False,2,True] a = list.count("x") for i in range(0, a): list.remove("x") print(list)View Code
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/13981.html
標籤:Python
上一篇:09_解決行程間通信執行緒間通信的資源競爭-同步互斥機制
下一篇:Django的簡單介紹及虛擬環境的搭建、創建專案,資料庫(Windows版超級詳細)--Python web應用程式開發(Python實戰)
