CBSE Class 11 Computer Science
Question 53 of 104
List Manipulation — Question 6
Back to all questions 6
Question Question 6
How are the statements lst = lst + 3 and lst += [3] different, where lst is a list? Explain.
Answer
The statement lst = lst + 3 will give error as + operator in Python requires that both its operands should be of the same type but here one operand is list and other is integer. The statement lst += [3] will add 3 at the end of the lst as += when used with lists requires the operand on the right side to be an iterable and it will add each element of the iterable to the end of the list.