Computer Science, asked by kumarnirmal447, 5 months ago

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​

Answers

Answered by ArchBTW
0

Answer:

a) list1*2 can only be used for printing the value. So this will not change the actual value of list1, so if we print(list1*2), we will see the result as  [6, 7, 8, 9, 6, 7, 8, 9], but if we print(list1) then we will see [6, 7, 8, 9] only.

b) list1*=2 will actually change the value of list1 so running list1*=2 and the print(list1) will show [6, 7, 8, 9, 6, 7, 8, 9]. Note that = is an assignment operator

c) This will produce an syntax error which is SyntaxError: invalid decimal literal

Similar questions