rank | ▲ | ✰ | vote | url |
---|---|---|---|---|
22 | 656 | 133 | 1124 | url |
Python中的appen和extend
append
和extend
有什么区别?
append:
x = [1, 2, 3]
x.append([4, 5])
print (x)
输出:[1, 2, 3, [4, 5]]
extend:
x = [1, 2, 3]
x.extend([4, 5])
print (x)
输出:[1, 2, 3, 4, 5]
原文: https://taizilongxu.gitbooks.io/stackoverflow-about-python/content/22/README.html