--- tags: Python學習 --- <style> .topic{ color:#fa7f20; font-weight:bold; } </style> # Python學習日記 List基礎 >參考資料 - Python王者歸來 洪錦魁著 ## <span class="topic">list 宣告</span> ```python= numList = [1, 10, 20] a, b, *c = 1, 2, 3, 4, 5 >> a = 1 >> b = 2 >> c = [3, 4, 5] ``` ## <span class="topic">list 讀取</span> ```python= numList[1] ``` ### <span class="topic">list Slices</span> 從第一個元素讀取到倒數第二個元素 ```python= numList[start:end] numList[:end] ``` ### <span class="topic">list Slices</span> 從第一個元素讀取到第 n - 1 個元素 ```python= numList[:-n] ``` ### <span class="topic">list Slices</span> 從第n個元素讀取到最後一個元素 ```python= numList[-n:] ``` ### <span class="topic">list Slices</span> 從第一個元素讀取到最後一個元素 ```python= numList[start:] numList{:} ``` ## <span class="topic">最大值、最小值、總和</span> ```python= max(numList) min(numList) sum(numList) ``` ## <span class="topic">取得 list 的長度</span> ```python= len(numList) ``` ## <span class="topic">修改 list 的元素</span> ```python= numList[2] = 10 ``` ## <span class="topic">合併/刪除 list 的元素</span> ```python= numList += numList2 del numList[2] ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up