這有區別么
L = ['Adam', 'Lisa', 'Bart']
L.insert(2, 'Paul')
print L
L = ['Adam', 'Lisa', 'Bart']
L.insert(-1, 'Paul')
print L
L = ['Adam', 'Lisa', 'Bart']
L.insert(2, 'Paul')
print L
L = ['Adam', 'Lisa', 'Bart']
L.insert(-1, 'Paul')
print L
2018-09-07
舉報
2018-10-26
應該是倒數第二,-2.倒數第一那不就是Bart之后嗎!
2018-09-09
we need to stress the difference between two ways,the first way is in order of from first data to last data while the second way is in contrast.
2018-09-07
在這個例子里輸出結果是一樣的,如果元素數量變化的話,輸出就會不同了
2018-09-07
如果要效果相同的話第二個應該改成L.insert(-2, 'Paul')
2018-09-07
L.insert(2, 'Paul') 插在正數第三位,L.insert(-1, 'Paul')插在倒數第一位
2018-09-07
初學者,感覺沒什么問題。