python append和extend_python中append和extend区别

append    #全列表

extend     #列表内容

Python 3.7.0a4 (v3.7.0a4:07c9d85, Jan  9 2018, 07:07:02) [MSC v.1900 64 bit (AMD64)] on win32

Type "copyright", "credits" or "license()" for more information.

cast = ['Nice day']

a = [2018]

b = 1 * 2

c = [3]

cast.extend(a)

cast.append(b)

cast.extend(c)

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

movies list

Python 3.7.0a4 (v3.7.0a4:07c9d85, Jan 9 2018, 07:07:02) [MSC v.1900 64 bit (AMD64)] on win32Type "copyright", "credits" or"license()" for more information.

input:

>>> movies = ['Cleese', 'Plan', 'Jone', 'Idle']

>>> print (len(movies))

4

>>> print (movies[3])

Idle

>>> movies.append('Gilliam')

>>> movies.pop()'Gilliam'

>>> movies.extend(['Gilliam', 'Chapman'])

>>> movies.remove('Chapman')

>>> movies.insert(0, 'chapman')

>>> print (movies)

output:

['chapman', 'Cleese', 'Plan', 'Jone', 'Idle', 'Gilliam']

你可能感兴趣的:(python,append和extend)