owned this note
owned this note
Published
Linked with GitHub
<!--introduction-->
# 10/25 第七堂社課
## 今日講師:R緯
#### (Python班)
---
# 今日課程主題:
----
# 複習-多變數的輸入
(map)
----
# 簡介陣列
(array)
----
# 列表 ∨ 串列
(list)
----
# 遍歷陣列
(array traversal)
----
# 歡樂題目time
```python
if 還有時間:
補充「重複」的4大類型
深入解釋map()
```
---
# 多變數的輸入
(map)
----
## map() 函式語法&參數:
```python
map(函式, 可迭代值, ...)
map(function, iterable, ...)
```
----
```python
a, b, c... = map(int, input().split())
```
input().split() 將輸入的內容 以split的括號內的內容做為sep 進行切割
split的括號內預設為" " (空格)
----
舉例#1
```python=
a, b, c = map(int, input().split())
print(a, b, c, sep=" ")
a, b, c = map(int, input().split(" "))
print(a, b, c, sep=" ")
a, b, c = map(int, input().split("hsnu"))
print(a, b, c, sep=" ")
m = "hello"
a, b, c = map(int, input().split(m))
print(a, b, c, sep=" ")
```
----
舉例#1 output

---
# 簡介陣列
(array)
----
## 一個陣列可以儲存很多資料
## 陣列最基本的目的:減少變數
----
## 陣列的種類:4種
* 列表 ∨ 串列(List)
* 元組(Tuple)
* 字典(Dictionary)
* 集合(Set)
[陣列類型簡介](https://www.pcschool.com.tw/blog/it/python-data-structures)
----
## 與上一屆相同,本課程著重在自由度最高的list
---
# 列表 ∨ 串列
(list)
----
* 同一個list裡面可以有不同型別
* list[位置] 位置由0開始
* len()可以得出該list的長度
----
最簡單的建立一個list,就是直接打出來
舉例#2
```python=
list1 = [1, 2, 3, "hello", 9.9]
print(list1)
for i in range(5):
print(list1[i])
print("len = ", len(list1))
```
----
舉例#2 output

----
## list好眼熟?
[9/13 第一堂社課 #3-10頁](https://hackmd.io/oN27EFsxRfeoNwYDfY1pTQ#/3/10)
----
## 字串是一種list
## 字串就是「字元的串列」
----
## append & pop
在一個list中增加、減少資料
* 增加 list.append(想增加的資料)
會增加在list最右邊
* 刪減 list.pop(**位置**)
會刪除該位置的資料
----
舉例#3
```python=
list1 = [1, 2, 3, "hello", 9.9]
print(list1)
list1.append("wow")
print(list1)
list1.pop(3)
print(list1)
```
----
舉例#3 output

----
## 一次性將多個資料做成list
## ,會用到list()函式
----
最常遇到range()、多變數輸入 做成list
舉例#4
```python=
list1 = list(map(int, input().split()))
print(list1)
list2 = list(range(2, 26, 2))
print(list2)
```
----
舉例#4 output

----
練習#1
已知國立臺灣師範大學附屬高級中學目前共有3個年級,假設高二高三皆有30班,高一有25班,請創造一個串列,使得裡面有從高三第一個班一直到高一最後一個班。
(假設高二的第一個班叫做1626)
---
# 遍歷陣列
(array traversal)
----
遍歷陣列是指訪問陣列所有元素的過程。
遍歷通常的目的是對集合中每個元素進行操作。
[10/4 第四堂社課 #2-1頁](https://hackmd.io/NMX-HZVuTdexQHN33WX3YQ#/2/1)
----
舉例#5
```python=
list1 = [152, 183, 84, "hello", 1.39]
for i in list1:
print(i)
```
```python=
list1 = [152, 183, 84, "hello", 1.39]
for i in range(len(list1)):
print(list1[i])
```
舉例#5 output

----
練習2
承練習1,運用遍歷陣列的方式,找出你的班級,並將該位置的值訂為字串My Class
---
# 歡樂題目time
----
## 練習3
## 矩陣的翻轉
----
```python=
row, column = map(int, input().split())
list1=[]
for i in range(row):
list2=list(map(int,input().split()))
list1.append(list2)
for i in range(column):
for j in range(row):
print(list1[j][i],end=" ")
print()
```
---
# END
[有興趣來看「重複結構」](https://hackmd.io/@ts-boring/BJF9VN_lkl)