a = [1, 2, 3]
b = [1, 2, 3,]
没看懂,这两个数组有什么区别?在django中有非常多的以“逗号”结束的数组。求指教
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)
俩者结果没有任何区别,但是在函数传参的时候,加上,Python会做不同的处理
比如(12)和(12,),但是列表传参没有发现不同,运行结果如下
[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
2 回答5.1k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
4 回答1k 阅读✓ 已解决
3 回答1.1k 阅读✓ 已解决
3 回答1.2k 阅读✓ 已解决
1 回答1.7k 阅读✓ 已解决
1 回答1.2k 阅读✓ 已解决
有这样的吗?我知道tuple当只有一个元素时是需要加的,list加不加都一样。