docs/school/ict/d2-02python-%E7%B6%9C%E5%90%88%E8%A7%A3%E9%9B%A3/ #11
Replies: 1 comment
-
|
😭😭🙏🙏🥀🥀 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
docs/school/ict/d2-02python-%E7%B6%9C%E5%90%88%E8%A7%A3%E9%9B%A3/
建立列表 只需直接賦值便可建立列表。 建立列表的例子: list1 = ["David", "Lily", "Ben"] ## 索引對應:list1[0]="David", list1[1]="Lily", list1[2]="Ben" list2 = [34, 23, 90, 56, 100] ## 索引對應:list2[0]=34, list2[1]=23, list2[2]=90, list2[3]=56, list2[4]=100 初始化的例子:
建立一個擁有 10 個項目的列表,並將所有項目賦值為「0」。 list3 = [0] * 10 ## 建立一個包含 10 個 0 的列表,索引由 list3[0] 至 list3[9] 更新列表中的項目 列表的索引是由 0 開始。 建立列表後,才能使用列表名稱加索引來存取指定的項目。 將「28」放入列表項目 list2[0]: list2[0] = 28 ## list2 的第一個元素由 34 被更新為 28 先讀取列表項目 list2[2] 的值,將此值減去 5 後,再將運算結果放入列表項目 list2[1]: list2[1] = list2[2] - 5 ## 讀取 list2[2] 的值 (90),減去 5 得到 85,寫入 list2[1](原本是 23) 輸出列表 程式碼:
https://notes.spexva.com/docs/school/ict/d2-02python-%E7%B6%9C%E5%90%88%E8%A7%A3%E9%9B%A3/
Beta Was this translation helpful? Give feedback.
All reactions