#範例5-2:串列的四種查詢 b1 = ["john","tom","mike","jolin","marry"] #------------------------ #(1).練習:顯示串tom的編號index:a.index(元素) #練習:然後根據編號,刪除tom #------------------------------ #(2).計算串列(list)長度函數:len(tuple) #練習:查看目標群,還有幾人 #--------------------------- #(3).查詢jjohn是否在串列list內: #☎方法:if txt in a print() #----------------------------------- #比較,計數迴圈 vs 串列迴圈 #(1)計數迴圈:for i in range(1,11,1) print() #(2)串列for迴圈::for 元素 in 串列 print() ----------------------------------------------------- ----------------------------------------------------- #範例5-2:串列的四種查詢 b1 = ["john","tom","mike","jolin","marry"] #------------------------ #(1).練習:顯示串tom的編號index:a.index(元素) print(b1.index("tom")) print() #練習:然後根據編號,刪除tom b1.pop(b1.index("tom")) print(b1) print() #------------------------------ #(2).計算串列(list)長度函數:len(tuple) #練習:查看目標群,還有幾人 print("敵方人數=", len(b1)) print() #--------------------------- #(3).查詢jjohn是否在串列list內: #☎方法:if txt in a if "john" in b1: print("還存在") else: print("不存在") #----------------------------------- #比較,計數迴圈 vs 串列迴圈 #(1)計數迴圈:for i in range(1,11,1) print() for i in range(1,11,1): print("恭喜發財") #(2)串列for迴圈::for 元素 in 串列 print() for item in b1: print(item)