---
title: Python
description: View the slide with "Slide Mode".
---
# Python
https://reurl.cc/NArM1m
----

----
## why python
----
## Pros
- 保持更新
- 可以用很多插件
- 多種編譯環境
----
## Cons
- 速度比C++慢
- 肥大
---
## 編譯器?
----
### python file and run
----
### Interpreter

^D to exit
----
### jupyter notebook

[COLAB](https://colab.research.google.com/notebooks/intro.ipynb#recent=true)
---
## 排版?
---
# Variable
----
```python=
x = 123
x = "123"
x = 12.12
```
---
# I/O
----
## input
```python
x = input()
```
----
## print
```python=
x = 123
print(x)
print("x")
```
----
## split
```python=
x.split()
```
----
### 字串輸出
```python=
x = 123
print(f"{123}")
```
----
### 行尾
```python=
print("hi", end=",")
print("Henry")
## ----- ##
print("hi")
print("Henry")
```
---
# operator
----
## + - * / %
```python=
x, y = 2, 4
print(x+y)
```
----
## **
```python=
print(2**3)
```
----
## and or
```python=
print(True and True)
print(True and False)
print(True or False)
```
----
## True False
True == 0
False == 1
----
## 小東西
----
## 註解
### C++
```cpp=
// cout << "hi" << endl;
```
### python
```python=
# print("hi")
```
----
## type
```python=
print(type(x))
```


---
# DS
----
## LIST
```python=
x = [1, 2, 3]
print(x)
print(type(x))
```
----
### range
```python=
x = range(4)
print(x)
x = range(2, 4)
print(x)
```
----
# 練習時間
輸出
----
## SET
----
## DICT
----
## Tuple
---
# LOOP
----
## for
```python=
x = [1, 4, 6]
for i in x:
print(x)
```
```python=
x = [1, 4, 5]
for idx, val in enumerate(x):
print(idx, val)
```
```python=
for i in range(5):
print(i)
```
----
# Build-in
```python=
lst = [2*i for i in range(4)]
print(lst)
```
----
## while
```python=
while cond:
# do something
```
---
# IF
----
## if
```python=
x = 10
if x == 10:
print("yeah")
print("nice")
```
```python=
x = 10
if x == 10:
print("yeah")
print("nice")
```
----
```python=
x = 10
if x == 10: print(x)
```
----
## if else
```python=
if ??? :
# do something
else :
# do something
```
----
## if elif
```python=
if ??? :
# do something
elif ??? :
# do something
else:
# do something
```
----
## 練習
input x 數字
print max
---
# math
----
# Numpy
----
# Matplotplib
----
# Opencv2