进阶篇6-函数周末习题

  • python append()和extend()用法
append()用法示例:

>>> mylist = [1,2,0,'abc']

>>> mylist

[1, 2, 0, 'abc']

>>> mylist.append(4)

>>> mylist

[1, 2, 0, 'abc', 4]

>>> mylist.append('haha')

>>> mylist

[1, 2, 0, 'abc', 4, 'haha']

extend()用法示例:

>>> mylist

[1, 2, 0, 'abc', 4, 'haha']

>>> mylist.extend(['lulu'])

>>> mylist

[1, 2, 0, 'abc', 4, 'haha', 'lulu']

>>> mylist.extend([aaa,'lalalala'])

Traceback (most recent call last):

  File "", line 1, in 

NameError: name 'aaa' is not defined

>>> mylist.extend(['123123','lalalala'])

>>> mylist

[1, 2, 0, 'abc', 4, 'haha', 'lulu', '123123', 'lalalala']

>>> mylist.extend([111111,222])

>>> mylist

[1, 2, 0, 'abc', 4, 'haha', 'lulu', '123123', 'lalalala', 111111, 222]

>>>

你可能感兴趣的:(进阶篇6-函数周末习题)