Consider a list: list1 = [6,7,8,9]
What is the difference between the following operations on list1:
a. list1 * 2
b. list1 *= 2
c. list1 = list1 * 2
Open in App
Solution
The statement will print the elements of the list twice, i.e [6, 7, 8, 9, 6, 7, 8, 9]. However, list1 will not be altered.
This statement will change the list1 and assign the list with repeated elements i.e [6, 7, 8, 9, 6, 7, 8, 9] to list1.
This statement will also have same result as the statement 'list1 *= 2'. The list with repeated elements i.e [6, 7, 8, 9, 6, 7, 8, 9] will be assigned to list1.