CBSE Class 11 Computer Science
Question 54 of 104
List Manipulation — Question 7
Back to all questions 7
Question Question 7
How are the statements lst += "xy" and lst = lst + "xy" different, where lst is a list? Explain.
Answer
The statement lst = lst + "xy" 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 string. The statement lst += "xy" will add 'x' and 'y' 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.