Is there any difference between these two way to define list
in Python?
lst1=[1,2]
lst2=[1,2,]
If there is no difference between then, Why Python define these two way?
Is there any difference between these two way to define list
in Python?
lst1=[1,2]
lst2=[1,2,]
If there is no difference between then, Why Python define these two way?
Mostly for convenience, especially when defining multi-line lists.
mylist = [
1,
2,
3,
]
The trailing comma makes it a little easier to add new items or reorder them. If you get in the habit of always leaving a trailing comma, then bugs due to forgetting to remove a comma go away.