# 第六堂課
****課堂筆記****
# 串列的應用-畫圖
:::success
畫圖
1.串列是為了帶一批資料給函數運算
2.視覺化-把資料轉換成眼睛易吸收的模式
3.畫圖套件:matplotlib.pyplot
:::
* 題目練習
:::warning
1.
#使用畫圖套件 matplotlib.pyplot
import matplotlib.pyplot as plt
a=[1,2,3,4,5]
b=[1,2,3,4,5]
plt.scatter(x=a,y=b,s=5)
plt.axis('square')
plt.xlim(0,10)
plt.ylim(0,10)
print(f'我的圖形')
plt.show()

:::
# 常用資料結構–字典(dictionary)

:::info
透過鍵(key)來查找值(value)
dic={'WaterMelon':100, 'Apple':40}
print( dic['WaterMelon'] )
100
:::
# 字典操作
* Python Dictionaries
```python=
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
```
* Example
Create and print a dictionary:
```python=
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
A:{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
```
* Dictionary Items
Dictionary items are ordered, changeable, and does not allow duplicates.
Dictionary items are presented in key:value pairs, and can be referred to by using the key name.
* Example
Print the "brand" value of the dictionary:
```python=
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict["brand"])
A:Ford
```
* Changeable
Dictionaries are changeable, meaning that we can change, add or remove items after the dictionary has been created.
* Duplicates Not Allowed
Dictionaries cannot have two items with the same key:
* Example
Duplicate values will overwrite existing values:
```python=
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964,
"year": 2020
}
print(thisdict)
A:{'brand': 'Ford', 'model': 'Mustang', 'year': 2020}
```
* Duplicates Not Allowed
Dictionaries cannot have two items with the same key:
* Example
Duplicate values will overwrite existing values:
```python=
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964,
"year": 2020
}
print(thisdict)
A:{'brand': 'Ford', 'model': 'Mustang', 'year': 2020}
```
* Dictionary Length
To determine how many items a dictionary has, use the len() function:
* Example
Print the number of items in the dictionary:
```python=
print(len(thisdict))
A:3
```
* Dictionary Items - Data Types
The values in dictionary items can be of any data type:
* Example
String, int, boolean, and list data types:
```python=
thisdict = {
"brand": "Ford",
"electric": False,
"year": 1964,
"colors": ["red", "white", "blue"]
}
```
* type()
From Python's perspective, dictionaries are defined as objects with the data type 'dict':
<class 'dict'>
* Example
Print the data type of a dictionary:
```python=
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(type(thisdict))
A:<class 'dict'>
```
# 課堂練習
:::info
印出字典裡所有的值
dict = {
“109213504”:“麥禮仁”,
“110211049”:“稅正祺”,
“110211003”:“林志宬”,
“110251009”:“王博賢”,
“110211026”:“洪權佑”,
“110211012”:“黃玉柔”,
“110211028”:“陳宜樺”,
“110211016”:“林依嫻”,
“110251027”:“郭姉祐”,
“110251001”:“董哲安”,
“110251002”:“高證鎰”,
“110251049”:“陳昱慈”,
“110251016”:“王麗婷”,
“110251014”:“謝欣伶”,
“110251044”:“王之賢”,
“110211050”:“江柏逸”,
“110211005”:“陳禹侖”,
“110211018”:“楊凡寬”,
“110211027”:“林昌興”,
“110211047”:“趙梓豐”,
“110211008”:“周芃君”,
“110211004”:“鍾孝歆”,
“110211025”:“黃巧瓈”,
“110251008”:“陳韋蓁”,
“110251010”:“劉姸希”,
“110251050”:“鄭捷方”,
“106213050”:“朱昱丞”,
“110211040”:“陳亨毓”,
“110251039”:“黃凱葶”,
“110251035”:“溫嘉泓”,
“110211052”:“林世鎧”,
“110211034”:“洪橞䈶”,
“110251043”:“許家維”,
“110251040”:“陳柔云”,
“110211013”:“顏庭茂”,
“110251041”:“魏敏如”,
“110251037”:“蔣水晶”,
“110211046”:“何思雅”,
“110211002”:“王敏甄”,
“110251018”:“李佳臻”,
“110211058”:“鄭宜蓁”,
“110211030”:“劉昱岑”,
“110211060”:“吳宜軒”,
“110251030”:“溫瑩瑄”,
“110211009”:“李佳蓁”,
“110211037”:“粘伊萱”,
“110211041”:“戚佩琳”,
“110251029”:“廖韋茹”,
“110211062”:“王郁亨”,
“109211067”:“古宇立”,
“108251026”:“許詠翔”,
“110251020”:“王雅蓁”,
“110251017”:“韓育欣”,
“110251023”:“陳懷恩”,
“110211032”:“郭芝榛”,
“110211051”:“林秉楓”,
“110251021”:“潘妘昕”,
“110251019”:“林益任”,
“110251051”:“王方琦”,
“110251028”:“傅翊安”,
“110211014”:“陳柏勳”,
“110251003”:“陳千晴”,
“110251004”:“翟品荃”,
“110251013”:“江羽晴”,
“110251012”:“陳玟伃”,
“110251005”:“陳品蓉”,
“110251026”:“王愉盛”,
“110211031”:“江以薰”,
“110211022”:“吳姿儀”,
“110211007”:“譚厚誼”,
“110211053”:“廖振羽”,
“109251040”:“傅善鉑”,
“110211036”:“葉平超”,
“110211024”:“蕭逸韋”,
“110211029”:“張彥程”,
“110211061”:“陳柏揚”,
“110211023”:“薛皓均”,
“110211015”:“吳玗苀”,
“110251015”:“吳依蓁”,
“110251032”:“黃元泓”,
“110251045”:“劉冠伯”,
“110211011”:“黃翊喆”,
“110211055”:“吳耀登”,
“110251006”:“陳薏如”,
“110251038”:“周宗永”,
“110211063”:“陳玉珊”,
“110251011”:“趙奕媗”,
“110211033”:“蘇家陞”,
“110251024”:“邱亮云”,
“110251047”:“盧承徵”,
“109105031”:“簡志安”,
“109105030”:“陳柏揚”
}
print(dict.keys())
A:dict_keys([‘109213504’, ‘110211049’, ‘110211003’, ‘110251009’, ‘110211026’, ‘110211012’, ‘110211028’, ‘110211016’, ‘110251027’, ‘110251001’, ‘110251002’, ‘110251049’, ‘110251016’, ‘110251014’, ‘110251044’, ‘110211050’, ‘110211005’, ‘110211018’, ‘110211027’, ‘110211047’, ‘110211008’, ‘110211004’, ‘110211025’, ‘110251008’, ‘110251010’, ‘110251050’, ‘106213050’, ‘110211040’, ‘110251039’, ‘110251035’, ‘110211052’, ‘110211034’, ‘110251043’, ‘110251040’, ‘110211013’, ‘110251041’, ‘110251037’, ‘110211046’, ‘110211002’, ‘110251018’, ‘110211058’, ‘110211030’, ‘110211060’, ‘110251030’, ‘110211009’, ‘110211037’, ‘110211041’, ‘110251029’, ‘110211062’, ‘109211067’, ‘108251026’, ‘110251020’, ‘110251017’, ‘110251023’, ‘110211032’, ‘110211051’, ‘110251021’, ‘110251019’, ‘110251051’, ‘110251028’, ‘110211014’, ‘110251003’, ‘110251004’, ‘110251013’, ‘110251012’, ‘110251005’, ‘110251026’, ‘110211031’, ‘110211022’, ‘110211007’, ‘110211053’, ‘109251040’, ‘110211036’, ‘110211024’, ‘110211029’, ‘110211061’, ‘110211023’, ‘110211015’, ‘110251015’, ‘110251032’, ‘110251045’, ‘110211011’, ‘110211055’, ‘110251006’, ‘110251038’, ‘110211063’, ‘110251011’, ‘110211033’, ‘110251024’, ‘110251047’, ‘109105031’, ‘109105030’])
:::
:::warning
設字典x為所有值,印出x
dict = {
“109213504”:“麥禮仁”,
“110211049”:“稅正祺”,
“110211003”:“林志宬”,
“110251009”:“王博賢”,
“110211026”:“洪權佑”,
“110211012”:“黃玉柔”,
“110211028”:“陳宜樺”,
“110211016”:“林依嫻”,
“110251027”:“郭姉祐”,
“110251001”:“董哲安”,
“110251002”:“高證鎰”,
“110251049”:“陳昱慈”,
“110251016”:“王麗婷”,
“110251014”:“謝欣伶”,
“110251044”:“王之賢”,
“110211050”:“江柏逸”,
“110211005”:“陳禹侖”,
“110211018”:“楊凡寬”,
“110211027”:“林昌興”,
“110211047”:“趙梓豐”,
“110211008”:“周芃君”,
“110211004”:“鍾孝歆”,
“110211025”:“黃巧瓈”,
“110251008”:“陳韋蓁”,
“110251010”:“劉姸希”,
“110251050”:“鄭捷方”,
“106213050”:“朱昱丞”,
“110211040”:“陳亨毓”,
“110251039”:“黃凱葶”,
“110251035”:“溫嘉泓”,
“110211052”:“林世鎧”,
“110211034”:“洪橞䈶”,
“110251043”:“許家維”,
“110251040”:“陳柔云”,
“110211013”:“顏庭茂”,
“110251041”:“魏敏如”,
“110251037”:“蔣水晶”,
“110211046”:“何思雅”,
“110211002”:“王敏甄”,
“110251018”:“李佳臻”,
“110211058”:“鄭宜蓁”,
“110211030”:“劉昱岑”,
“110211060”:“吳宜軒”,
“110251030”:“溫瑩瑄”,
“110211009”:“李佳蓁”,
“110211037”:“粘伊萱”,
“110211041”:“戚佩琳”,
“110251029”:“廖韋茹”,
“110211062”:“王郁亨”,
“109211067”:“古宇立”,
“108251026”:“許詠翔”,
“110251020”:“王雅蓁”,
“110251017”:“韓育欣”,
“110251023”:“陳懷恩”,
“110211032”:“郭芝榛”,
“110211051”:“林秉楓”,
“110251021”:“潘妘昕”,
“110251019”:“林益任”,
“110251051”:“王方琦”,
“110251028”:“傅翊安”,
“110211014”:“陳柏勳”,
“110251003”:“陳千晴”,
“110251004”:“翟品荃”,
“110251013”:“江羽晴”,
“110251012”:“陳玟伃”,
“110251005”:“陳品蓉”,
“110251026”:“王愉盛”,
“110211031”:“江以薰”,
“110211022”:“吳姿儀”,
“110211007”:“譚厚誼”,
“110211053”:“廖振羽”,
“109251040”:“傅善鉑”,
“110211036”:“葉平超”,
“110211024”:“蕭逸韋”,
“110211029”:“張彥程”,
“110211061”:“陳柏揚”,
“110211023”:“薛皓均”,
“110211015”:“吳玗苀”,
“110251015”:“吳依蓁”,
“110251032”:“黃元泓”,
“110251045”:“劉冠伯”,
“110211011”:“黃翊喆”,
“110211055”:“吳耀登”,
“110251006”:“陳薏如”,
“110251038”:“周宗永”,
“110211063”:“陳玉珊”,
“110251011”:“趙奕媗”,
“110211033”:“蘇家陞”,
“110251024”:“邱亮云”,
“110251047”:“盧承徵”,
“109105031”:“簡志安”,
“109105030”:“陳柏揚”
}
for x in dict.values():
print(x)
A:麥禮仁
稅正祺
林志宬
王博賢
洪權佑
黃玉柔
陳宜樺
林依嫻
郭姉祐
董哲安
高證鎰
陳昱慈
王麗婷
謝欣伶
王之賢
江柏逸
陳禹侖
楊凡寬
林昌興
趙梓豐
周芃君
鍾孝歆
黃巧瓈
陳韋蓁
劉姸希
鄭捷方
朱昱丞
陳亨毓
黃凱葶
溫嘉泓
林世鎧
洪橞䈶
許家維
陳柔云
顏庭茂
魏敏如
蔣水晶
何思雅
王敏甄
李佳臻
鄭宜蓁
劉昱岑
吳宜軒
溫瑩瑄
李佳蓁
粘伊萱
戚佩琳
廖韋茹
王郁亨
古宇立
許詠翔
王雅蓁
韓育欣
陳懷恩
郭芝榛
林秉楓
潘妘昕
林益任
王方琦
傅翊安
陳柏勳
陳千晴
翟品荃
江羽晴
陳玟伃
陳品蓉
王愉盛
江以薰
吳姿儀
譚厚誼
廖振羽
傅善鉑
葉平超
蕭逸韋
張彥程
陳柏揚
薛皓均
吳玗苀
吳依蓁
黃元泓
劉冠伯
黃翊喆
吳耀登
陳薏如
周宗永
陳玉珊
趙奕媗
蘇家陞
邱亮云
盧承徵
簡志安
陳柏揚
:::
# 字串
* 題目練習
:::warning
txt=`今天天氣很不好,下雨,又很冷` # 使用某字串切片
print(txt[0:4]) # 印出0到4的字數
print(txt[:])
print(len(txt)) # 印出txt的長度
A:今天天氣
今天天氣很不好,下雨,又很冷
14
6
:::
# Sets
* 集合為小括號,裡面是不同元素
Example
:::warning
第二次加orange沒法加入集合內,因為集合已經有了
thisset = {"apple", "banana", "cherry"}
thisset.add("orange")
thisset.add("orange")
print(thisset)
A:(‘apple’,‘banana’,‘cherry’,‘orange’)
:::
:::info
印兩次列兩列
thisset = {"apple", "banana", "cherry"}
thisset.add("orange")
print(thisset)
thisset.add("orange")
print(thisset)
A:{‘apple’,‘banana’,‘cherry’,‘orange’}
{‘apple’,‘banana’,‘cherry’,‘orange’}
:::
# 小組作業
:::success
題目
dict = {
“109213504”:“麥禮仁”,
“110211049”:“稅正祺”,
“110211003”:“林志宬”,
“110251009”:“王博賢”,
“110211026”:“洪權佑”,
“110211012”:“黃玉柔”,
“110211028”:“陳宜樺”,
“110211016”:“林依嫻”,
“110251027”:“郭姉祐”,
“110251001”:“董哲安”,
“110251002”:“高證鎰”,
“110251049”:“陳昱慈”,
“110251016”:“王麗婷”,
“110251014”:“謝欣伶”,
“110251044”:“王之賢”,
“110211050”:“江柏逸”,
“110211005”:“陳禹侖”,
“110211018”:“楊凡寬”,
“110211027”:“林昌興”,
“110211047”:“趙梓豐”,
“110211008”:“周芃君”,
“110211004”:“鍾孝歆”,
“110211025”:“黃巧瓈”,
“110251008”:“陳韋蓁”,
“110251010”:“劉姸希”,
“110251050”:“鄭捷方”,
“106213050”:“朱昱丞”,
“110211040”:“陳亨毓”,
“110251039”:“黃凱葶”,
“110251035”:“溫嘉泓”,
“110211052”:“林世鎧”,
“110211034”:“洪橞䈶”,
“110251043”:“許家維”,
“110251040”:“陳柔云”,
“110211013”:“顏庭茂”,
“110251041”:“魏敏如”,
“110251037”:“蔣水晶”,
“110211046”:“何思雅”,
“110211002”:“王敏甄”,
“110251018”:“李佳臻”,
“110211058”:“鄭宜蓁”,
“110211030”:“劉昱岑”,
“110211060”:“吳宜軒”,
“110251030”:“溫瑩瑄”,
“110211009”:“李佳蓁”,
“110211037”:“粘伊萱”,
“110211041”:“戚佩琳”,
“110251029”:“廖韋茹”,
“110211062”:“王郁亨”,
“109211067”:“古宇立”,
“108251026”:“許詠翔”,
“110251020”:“王雅蓁”,
“110251017”:“韓育欣”,
“110251023”:“陳懷恩”,
“110211032”:“郭芝榛”,
“110211051”:“林秉楓”,
“110251021”:“潘妘昕”,
“110251019”:“林益任”,
“110251051”:“王方琦”,
“110251028”:“傅翊安”,
“110211014”:“陳柏勳”,
“110251003”:“陳千晴”,
“110251004”:“翟品荃”,
“110251013”:“江羽晴”,
“110251012”:“陳玟伃”,
“110251005”:“陳品蓉”,
“110251026”:“王愉盛”,
“110211031”:“江以薰”,
“110211022”:“吳姿儀”,
“110211007”:“譚厚誼”,
“110211053”:“廖振羽”,
“109251040”:“傅善鉑”,
“110211036”:“葉平超”,
“110211024”:“蕭逸韋”,
“110211029”:“張彥程”,
“110211061”:“陳柏揚”,
“110211023”:“薛皓均”,
“110211015”:“吳玗苀”,
“110251015”:“吳依蓁”,
“110251032”:“黃元泓”,
“110251045”:“劉冠伯”,
“110211011”:“黃翊喆”,
“110211055”:“吳耀登”,
“110251006”:“陳薏如”,
“110251038”:“周宗永”,
“110211063”:“陳玉珊”,
“110251011”:“趙奕媗”,
“110211033”:“蘇家陞”,
“110251024”:“邱亮云”,
“110251047”:“盧承徵”,
“109105031”:“簡志安”,
“109105030”:“陳柏揚”
}
:::
:::warning
1.找出'麥禮仁'的學號
* 解答
for x , y in dict.items():
if y == "麥禮仁":
print(x,y)
:::
:::info
2.找出姓氏「陳」的學號與姓名
* 解答:
for x , y in dict.items():
if "陳" in y :
print(x,y)
:::
:::warning
3."歡迎某某某同學參加我們的營隊活動"
* 解答
D = '歡迎'
E = '同學參加我們的營隊活動'
for x , y in dict.items():
print(D,y[0:],E)
:::
:::info
4.找出所有的姓氏,可以用set
* 解答
for x , y in dict.items():
print(y[0:1])
:::
# 會議記錄
----------------------
* 3/29
