I’ve noticed that when I’m using python, I’ll occasionally make a typographical error and have a definition that looks something like
L = [1,2,3,]
My question is, why doesn’t this cause an error?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It doesn’t cause an error because it is an intentional feature that trailing commas are allowed for lists and tuples.
This is especially important for tuples, because otherwise it would be difficult to define a single element tuple:
It can also make it easier to reorder or add elements to long lists.