網上有很多對這兩個函式的區別講解,但我覺得都講的不是很清楚,記憶不深刻。這樣解釋清楚且容易記住。
1
2
3
4
5
music_media
=
[
'compact disc'
,
'8-track tape'
,
'long playing record'
]
new_media
=
[
'*** audio disc'
,
'super audio cd'
]
print
music_media
>>>[
'compact disc'
,
'8-track tape'
,
'long playing record'
, [
'*** audio disc'
,
'super audio cd'
]]
12
3
4
5
music_media
=
[
'compact disc'
,
'8-track tape'
,
'long playing record'
]
new_media
=
[
'*** audio disc'
,
'super audio cd'
]
music_media.extend(new_media)
print
music_media
>>>[
'compact disc'
,
'8-track tape'
,
'long playing record'
,
'*** audio disc'
,
'super audio cd'
]
使用extend的時候,是將new_media看作乙個序列,將這個序列和music_media序列合併,並放在其後面。
Python中append和extend的區別
網上有很多對這兩個函式的區別講解,但我覺得都講的不是很清楚,記憶不深刻。這樣解釋清楚且容易記住。1 2 3 4 5 music media compact disc 8 track tape long playing record new media audio disc super audio c...
Python中append和extend的區別
網上有很多對這兩個函式的區別講解,但我覺得都講的不是很清楚,記憶不深刻。這樣解釋清楚且容易記住。music media compact disc 8 track tape long playing record new media audio disc super audio cd print mu...
Python中的append和extend的區別
網上有很多對這兩個函式的區別講解,但我覺得都講的不是很清楚,記憶不深刻。這樣解釋清楚且容易記住。list.extend sequence 把乙個序列seq的內容新增到列表中 music media compact disc 8 track tape long playing record new m...