owned this note
owned this note
Published
Linked with GitHub
# Python#2
[TOC]
## Week 2
### 上課簡報
<iframe src="https://drive.google.com/file/d/1YzPrXZoXDHs7QJYsBoXMHm7hN7J88jAm/preview" width="640" height="480">
</iframe>
---
<iframe src="https://drive.google.com/file/d/1E2Wn8GcFR0-wlbiFjZA6dIlvdJrdJSQy/preview" width="640" height="480">
</iframe>
---
<iframe src="https://drive.google.com/file/d/1VCPRiNwzBlvMIw3HRMq6sH35tguPMahT/preview" width="640" height="480">
</iframe>
---
<iframe src="https://drive.google.com/file/d/1hSCatNGeUDRHkgaGMcy7iqGjE5pPGCiu/preview" width="640" height="480">
</iframe>
---
<iframe src="https://drive.google.com/file/d/1q8GeqbbAMkYW_56JrjYX37Ku-zImYtHd/preview" width="640" height="480">
</iframe>
---
<iframe src="https://drive.google.com/file/d/1_Kq6JMuV_sziZ9qywYqTJi9ZXLM-fsHO/preview" width="640" height="480">
</iframe>
## coding
### Hello World
```python
print('hello world')
```
### 註解
```python
#吳書賢是帥哥
#冠豪老濕教我Python
print('hello world')
#或者多行框起來ctrl+/
```
- time=Mon, Mar 16, 2020 10:09 AM
- [name=Neroal] :+1:
- [name=guanchu] :a:
### 換行
不需要斷行符號
### 縮排
把程式依照結構做處理
```python
score=8787
if score=60:
print("尛")
print("我好帥")
```
:::warning
python的括號只能用縮排處理
- [name=guanchu]
:::
:::warning
程式區塊要加<b>:</b>不然編譯器會<b>氣pupu</b> :exclamation:
:::
### 變數
- python使用變數不必指定資料型態
- 第一個名稱必須視大小寫字母、_、中文
- 開頭不可是數字
- **盡量不要將int、float...<span style="color:red">保留字</span>當作變數名稱**

- 英文大小寫視為不同變數名稱
>[color=red] <b>python</b>
```python
score=666
```
>[color=lightblue]<b>C++</b>
```cpp
int score = 92;
```
#### 範例
```python
a = 'I Fuck You'
b = 15
c =3.14159265358979323846264338327950288419716939937510
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
# 執行結果
# I Fuck You
# 15
# 3.141592653589793
# <class 'str'>
# <class 'int'>
# <class 'float'>
```
#### 範例2
```python
matrix = [a,b,c]
for a in matrix:
print(a)
print(type(a))
# 執行結果
# I Fuck You
# 15
# 3.141592653589793
# <class 'str'>
# <class 'int'>
# <class 'float'>
```
#### 範例3
```python
d = e = 777
print(d)
print(e)
age , name = 18 , 'Handsome'# han你阿公
test = '歐齁"齁"齁齁'
people = [18, 'Handsome']
print(age)
print(name)
print(people)
print(test)
# 執行結果
# 777
# 777
# 18
# Handsome
# [18, 'Handsome']
# 歐齁"齁"齁齁
```
### 範例4(中文變數測試)
```python=
吳書賢 = "大蟒蛇"#小妳阿罵
print(吳書賢)
# 執行結果
# 大蟒蛇
```
:::warning
<b>float</b>只能印到小數點第16位 :exclamation: :exclamation: :exclamation:
:::
### 布林boolean
- <font size=4>Ture,False</font>
### 單引號 雙引號
```python=
str1='胡適說過:"要怎麼收穫先那麼栽"'
str2="胡適說過:'要怎麼收穫先那麼栽'"
str3 = '兒兒\'123123\'213'
print(str1)
print(str2)
#結果
#胡適說過:"要怎麼收穫先那麼栽"
#胡適說過:'要怎麼收穫先那麼栽'
#兒兒'123123'213
```
:::warning
<b>``\'``</b> 這個是要將<b>`'`</b>印出 :mega:
:::

### 換行
```python=
str1='冠豪給錢\n'
str2='好啊'
print(str1)
print(str2)
#結果
#冠豪給錢
#好啊
#安安你好
#你好喔
```
### 輸出輸入
- print是**輸出資料**,input是**輸入資料**,讓使用者由標準輸入輸入資料
- ==輸入的數值會視為字串==
```python
length_dick = input("輸入你的長度")
print(length_dick)
print(type(length_dick)) #可以知道length_dick的型態
# 這邊很重要(下方有說明)
if int(length_dick) < 30 :
print("錢寧" + " Small_dick")
else :
print("賴冠豪" + "still_small")
# 輸出結果
# 輸入你的長度10
# 10
# <class 'str'>
# 錢寧 Small_dick
```
:::warning
input出來的值是string,要轉型才能做比較 :mega:
:::
- concatenation 字串連接
### 強制轉型
```python
score = '1234'
score_float='78.87'
print(int(score))
print(float(score_float))
#輸出結果
#1234
#78.87
#硬要改ㄟ
```
### 資料型態轉換

### Print的使用方式
```python=
num = 8000
print("neroal",num,"cm")
print("neroal"+str(num)+"cm")
#輸出
#neroal 8000 cm
```
:::warning
`,`可以不管資料型態印出,但`+`的時候資料型態要一致
:::
:::info
**print換行機制**
<br>
```python=
num = 8000
#後面的end可以將預設的'/n'去掉,讓這兩行印出時不會換行
print("neroal",num,"cm", end = '')
print("neroal"+str(num)+"cm")
#用sep指令,可以將原先的space改成後面的string
print("neroal",num,"cm",sep=',')
# 輸出結果
# neroal 8000 cmneroal8000cm
# neroal,8000,cm
```
:::
#### 輸出到螢幕
- `%s` 字串
- `%d` 整數
- `%f` 浮點數
- `%h` 十六進位
- `print(項目 %(參數列))`
- `8.3f` 8個字元 小數點後3位
| 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
| -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| 空 | 空 | 9 | 4 | . | 4 | 3 | 0 |
```python
name = '狗登' # 字串
score = 95 # 整數
score_float = 95.43
print("{} 狗狗".format(name))
print("%s的成績為%d" %(name,score))
# 8.3f為8個字元(含小數點)小數點後3位
print("%s的成績為%8.3f" %(name,score_float))
# 輸出結果
# 狗登的成績為95
# 狗登的成績為 95.430
```
## 簽到區
:::danger
下周簽到表不可以先簽
:::
> 說明
> 先在上面打 `- []`,就可以打時間
- [time=Mon, Mar 16, 2020 11:29 AM]
| 姓名 |Week 3簽到 |Week 4簽到|
| :--------: | :-------: | :-------: |
| 顏于傑 |✔ | |
| 吳書賢 | :santa: | |
| 賴冠豪 | :+1: | |
| 陳 煜 |✔ | |
| 錢 寧 | ✔ | :man: |
###### tags: `python` `TQC`