第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在Python中,“。append()”和“+ = []”之間有什么區(qū)別?

在Python中,“。append()”和“+ = []”之間有什么區(qū)別?

紅顏莎娜 2019-08-26 11:09:35
在Python中,“。append()”和“+ = []”之間有什么區(qū)別?有什么區(qū)別:some_list1 = [] some_list1.append("something")和some_list2 = [] some_list2 += ["something"]
查看完整描述

3 回答

?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗 獲得超12個贊

append()方法將單個項添加到現(xiàn)有列表中。它不會返回新列表,而是修改原始列表。

some_list1 = []some_list1.append("something")

所以這里some_list1將被修改。

而使用+來組合列表元素會返回一個新列表。

some_list2 = []some_list2 += ["something"]

所以這里some_list2和[“something”]是兩個合并的列表,并返回一個新的列表,分配給some_list2


查看完整回答
反對 回復(fù) 2019-08-26
?
holdtom

TA貢獻(xiàn)1805條經(jīng)驗 獲得超10個贊

讓我們先舉個例子


list1=[1,2,3,4]

list2=list1     (that means they points to same object)


if we do 

list1=list1+[5]    it will create a new object of list

print(list1)       output [1,2,3,4,5] 

print(list2)       output [1,2,3,4]


but if we append  then 

list1.append(5)     no new object of list created

print(list1)       output [1,2,3,4,5] 

print(list2)       output [1,2,3,4,5]


extend(list) also do the same work as append it just append a list instead of a 

single variable 


查看完整回答
反對 回復(fù) 2019-08-26
  • 3 回答
  • 0 關(guān)注
  • 2562 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號