0

Most of the time, a comma won't follow the last item in a list.What is meant?

25th Jul 2020, 6:52 PM
Apoorv Bansal
3 Respuestas
+ 6
I suppose you are talking about Python. A comma after the last item in a list, tuple or dictionary is no problem (in fact, most languages are okay with it). Moreover, a comma in the end is used to indicate a tuple if there is only 1 item in the tuple. For example type((1)) will return int type((1,)) will return tuple
25th Jul 2020, 7:00 PM
XXX
XXX - avatar
+ 5
It can be convenient to have a comma in the end, if you expect to extend your list later. data = [ item1, item2, item3, ] Leaving the comma, you prevent forgetting it later, when you add item4 (getting strange errors).
25th Jul 2020, 8:00 PM
HonFu
HonFu - avatar