亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python中extend和append的區(qū)別講解

 更新時(shí)間:2019年01月24日 10:24:19   作者:youzhouliu  
今天小編就為大家分享一篇關(guān)于Python中extend和append的區(qū)別講解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧

append() 方法向列表的尾部添加一個(gè)新的元素。只接受一個(gè)參數(shù)。

>>> num = [1,2]
>>> num.append(3)
>>> num
[1, 2, 3]
>>> num.append('a')
>>> num
[1, 2, 3, 'a']
>>> num.append(6,7)
Traceback (most recent call last):
 File "<pyshell#8>", line 1, in <module>
  num.append(6,7)
TypeError: append() takes exactly one argument (2 given)
>>> num.append([6])
>>> num
[1, 2, 3, 'a', [6]]
>>> num.append({'a'})
>>> num
[1, 2, 3, 'a', [6], set(['a'])]

extend()方法只接受一個(gè)列表作為參數(shù),并將該參數(shù)的每個(gè)元素都添加到原有的列表中。也是只接受一個(gè)參數(shù)。

>>> num=[1,2]
>>> num.extend([5])
>>> num
[1, 2, 5]
>>> num.extend(['b'])
>>> num
[1, 2, 5, 'b']
>>> num.extend(6,7)
Traceback (most recent call last):
 File "<pyshell#29>", line 1, in <module>
  num.extend(6,7)
TypeError: extend() takes exactly one argument (2 given)

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

最新評(píng)論