1. 程式人生 > >python 不熟的語法4

python 不熟的語法4

1. 一個好的變數名:用while遍歷list時,max_index = len(lists) - 1

2. 重用程式碼。Don't repeat yourself.

3. 實參(argument),形參(parameter)

def add(x, y): # x, y為形參
    return x + y

a = add(2, 3) # 2, 3為實參

4. 註釋(comment)

5. 在python中,函式名是對函式的一個引用,可以賦值給其他變數:

def add(x, y):
    return x + y

a = 5
b = 3
plus = add
print(plus(a, b)) # 輸出8
print(add(a, b)) # 輸出8