# Python 基礎語法
:::success
### Content
[TOC]
:::
### 資料結構
#### int
- 整數
- e.g. 1, 2, 3, 4, 5, 6, 7, 8, 9, 1000, 99999 ...etc
#### string
- 字串
- 以`''`或`""`括起來
- e.g. 'Hello World', 'cool', '1' ...etc
#### float
- 浮點數
- e.g. 3.1415926, 1.41421 ...etc
#### list
- 列表(類似array)
- 可儲存不同資料型態
- e.g.
```python=
a=[1,'b',3]
b=[1,2,3]
c=['a','b','c']
```
#### dictionary
- 字典(類似map、json格式)
- 可做對照功能
- e.g.
```python=
a={
1:'dog',
2:'cat'
}
```
### 變數
- 類似C++ auto, JavaScript 變數
- 可依照資料形式進行改變
- 命名可自定義
### loop
#### for-in loop
- format:
```python=
# sequence with int:
sequence=[1, 2, 3, 4, 5, 6, 7]
for x in sequence:
print(x)
"""
result:
1
2
3
4
5
6
7
"""
#sequence with string:
sequence=['a', 'b', 'c', 'd', 'e', 'f', 'g']
for x in sequence:
print(x)
"""
result:
a
b
c
d
e
f
g
"""
#sequence with 0 to 10 , tol:2
for x in range(0,10,2):
print(x)
"""
result:
0
2
4
6
8
"""
```
#### while loop
- format:
```python=
while True:
print('Condition is established !')
while False:
print('Condition err0r.')
```
#### 輔助工具(break/continue)
- 執行 [while loop的範例程式](https://hackmd.io/xkvHaIAqToKvU0Dizb-5xw?both#while-loop) 時,會發現程式一直輸出`Condition is established !`,因此我們需要一些"終結者"(杜芬舒斯博士粉)來終結這個東西,於是就到輔助工具出廠的時候了!
- format:
```python=
while True:
print('Condition is established !')
break
"""
result:
Condition is established !
"""
for x in range(0,10):
if x == 5:
continue
print(x)
"""
result:
0
1
2
3
4
6
7
8
9
"""
```