1. 程式人生 > >坑,規避函式預設函式是可變資料型別

坑,規避函式預設函式是可變資料型別

def donot_use_mutable_default_param(idx=0, ids=None):
    if ids is None:
        ids = []
    ids.append(idx)
    print(idx)
    print(ids)
donot_use_mutable_default_param(idx=1)
donot_use_mutable_default_param(idx=2)