本篇文章主要介紹 python 程式語言的基本語法
- 變數
- 陣列
- 運算符號
- if condition
- for loop
- for each
- function
- dictionary
變數
1 2 3 4 5
| a = 0 b = 0.01 c = "message" d = True e = none
|
陣列
運算符號
1 2 3 4 5 6 7 8 9
| a == b a != b a > b a >= b a < b a <= b not a a and b a or b
|
if condition
1 2 3 4 5 6
| if a > b: ... elif a < b: ... else: ...
|
for loop
1 2
| for i in range(10): ...
|
for each
1 2 3 4 5
| for element in array: ...
for index, element in enumerate(array): ...
|
function
1 2 3 4 5 6 7 8 9
| def Calculate(): ...
def Calculate(a): ...
def Calculate(a): ... return 0
|
dictionary
宣告
1 2
| valueByKey = {} valueByKey = { "Id": 0 }
|
檢查存在
1 2 3
| valueByKey = { "Id": 0 } key = "Id" isExisted = key in valueByKey
|
賦值
1 2 3 4
| valueByKey = {} key = "Id" value = 0 valueByKey[key] = value
|
取值
1 2 3
| valueByKey = { "Id": 0 } key = "Id" value = valueByKey[key]
|