在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ python list初始化

python list初始化

a = [1, 2, 3]
b = [1, 2, 3,]

沒看懂,這兩個(gè)數(shù)組有什么區(qū)別?在django中有非常多的以“逗號”結(jié)束的數(shù)組。求指教

回答
編輯回答
幼梔

有這樣的嗎?我知道tuple當(dāng)只有一個(gè)元素時(shí)是需要加的,list加不加都一樣。

2017年8月8日 16:41
編輯回答
夕顏
a=[1,2,3]
b=[1,2,3,]
print(a)
print(b)
print(a==b)
a.append(1)
b.append(1)
print(a)
print(b)
print(a==b)
def test(c):
    print(type(c))
test((1,))
test((1))
test(a)
test(b)

倆者結(jié)果沒有任何區(qū)別,但是在函數(shù)傳參的時(shí)候,加上,Python會(huì)做不同的處理
比如(12)和(12,),但是列表傳參沒有發(fā)現(xiàn)不同,運(yùn)行結(jié)果如下

[Running] python "e:\Rare\python\demo_1\demo_1.py"
[1, 2, 3]
[1, 2, 3]
True
[1, 2, 3, 1]
[1, 2, 3, 1]
True
<class 'tuple'>
<class 'int'>
<class 'list'>
<class 'list'>

[Done] exited with code=0 in 0.116 seconds
2018年6月1日 02:06