What does append mean in python?

silencement
Release: 2019-06-20 11:56:07
Original
64826 people have browsed it

What does append mean in python?

There are many explanations on the difference between these two functions on the Internet, but I feel that they are not very clear and my memory is not deep. This explains clearly and is easy to remember.

list.append(object) Add an object object to the list
list.extend(sequence) Add the contents of a sequence seq to the list

music_media = ['compact disc', '8-track tape', 'long playing record']
new_media = ['DVD Audio disc', 'Super Audio CD']
music_media.append(new_media)
print music_media
>>>['compact disc', '8-track tape', 'long playing record', ['DVD Audio disc', 'Super Audio CD']]
Copy after login

As above, use append At this time, new_media is regarded as an object, and the entire package is added to the music_media object.

music_media = ['compact disc', '8-track tape', 'long playing record']
new_media = ['DVD Audio disc', 'Super Audio CD']
music_media.extend(new_media)
print music_media
>>>['compact disc', '8-track tape', 'long playing record', 'DVD Audio disc', 'Super Audio CD']
Copy after login

As above, when using extend, new_media is regarded as a sequence, this sequence is merged with the music_media sequence, and placed behind it.

The above is the detailed content of What does append mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!