Python list initialization

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

I don"t understand. What"s the difference between the two arrays? There are a lot of arrays in django that end with a comma. Ask for advice

Mar.10,2021

is there such a thing? I know that tuple needs to be added when there is only one element, and whether list is added or not is the same.


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)

there is no difference between the two results, but when passing parameters to the function, Python will do different processing
such as (12) and (12,), but there is no difference in passing parameters in the list. The running result is as follows

.
[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
Menu