(1)for迴圈里的else (2)列表append的註意點 ...
(1)for迴圈里的else
In [1]: nums = [11,22,33,44] In [2]: for temp in nums: ...: print(temp) ...: else: #else表示當迴圈列印完才會列印else里的內容 ...: print("========") ...: 11 22 33 44 ========
(2)列表append的註意點
In [3]: a = [11,22,33] In [4]: b = [44,55] In [5]: a.append(b) In [6]: a Out[6]: [11, 22, 33, [44, 55]] #append相當於把b列表這個整體都放在a列表
In [1]: a = [11,22,33] In [2]: b = [44,55] In [3]: a.append(b) In [4]: a Out[4]: [11, 22, 33, [44, 55]] In [5]: a = a.append(b) #當執行a.append(b)時,代表已經把b添加到a裡面去了,結果已經發生了變化,但是a.append(b)並沒有結果輸入,則會返回空 In [6]: a