--- tags: Python學習 --- <style> .topic{ color:#fa7f20; font-weight:bold; } </style> # Python學習日記 List的操作 ## <span class="topic">index()</span> #### 取得陣列元素的索引值 ```python= numList = [1, 2, 3] numList.index(2) >> 1 ``` ## <span class="topic">count()</span> #### 取得陣列元素出現的次數,若不存在於陣列中則回傳 0 ```python= numList = [1, 2, 3] numList.index(2) >> 1 ``` ## <span class="topic">append()</span> #### 將元素放入陣列中 ```python= numList = [1, 2, 3] numList2 = [4, 5, 6] numList.append(numList2) numList >> [1, 2, 3, [4, 5, 6]] ``` ## <span class="topic">extend()</span> #### 將陣列連接陣列 ```python= numList = [1, 2, 3] numList2 = [4, 5, 6] numList.extend(numList2) numList >> [1, 2, 3, 4, 5, 6] ```