close

#list 資料 用法

movies = ["the hole word","the allen omg","the power"]   #  名字 = ["資料內容"]

`
print(len(movies))    #len 指令告訴 movies 有多少項   

#>>>3   #答案  


movies = ["the hole word","the allen omg","the power"] 

 

movies.append("joseph")   # 使用 append 新增 一筆資料為 joseph 


print(movies)   # 顯示出 list 的 movies 所以資料

 

#>>> ['the hole word', 'the alleno mg', 'the power', 'joseph']   #答案  


movies = ["the hole word","the allen omg","the power"]

 
movies.append("the pop") # 新增一筆資料會附加最後尾端


print(movies)

 

#>>>['the hole word', 'the allen omg', 'the power',, 'the pop'] #答案  


movies = ["the hole word","the allen omg","the power"]


movies.pop() # 使用 pop  刪除最尾端資料  最尾端的資料為 "the power"

 
print(movies)  

 

#>>>['the hole word', 'the allen omg'] #答案  


movies = ["the hole word","the allen omg","the power"]


movies.extend(["the pop","the floew"])   # 使用 extend 新增兩筆資料 "the pop","the floew" 到 最尾端
print(movies)

 

#>>>['the hole word', 'the allen omg', 'the power', "the pop","the floew"] #答案  


movies = ["the hole word","the allen omg","the power"]

movies.remove("the hole word")  # 指定移除 目前指定為"the hole word"


print(movies)

#>>>['the allen omg', 'the power'] #答案  


movies = ["the hole word","the allen omg","the power"]

#                   "the hole word"  為0   以此類推

movies.insert(1, "55688")  #指定新增位置  "55668"  會到"1"的位置,所以說會在"the hole word"後面

print(movies)

#>>>['the hole word', '55688' 'the allen omg', 'the power']#答案  



#for 用法

fav_movies = ["the hole word","the allen omg","the power"]#list
#print(fav_movies[0])
#print(fav_movies[1])
#print(fav_movies[2])

 

for x in fav_movies:   #for X(是自己定義的) in(哪一個清單) fav_movies(我所要指定的清單)

print(x)  #  print (帶入剛剛設定的X)   這樣就會每一筆單獨顯示在螢幕上

arrow
arrow
    全站熱搜

    喬瑟夫的電腦事 發表在 痞客邦 留言(0) 人氣()