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
20
Given list:
list1 = [6, 7, 8, 9]
Let's first see what output is shown from the following operations.
a. list1*2
This statement would render the following output:
- [6, 7, 8, 9, 6, 7, 8, 9]
b. list1*=2
This statement would store the value of list1*2 into list1, i.e., list1 will now be:
- [6, 7, 8, 9, 6, 7, 8, 9]
c. list1 = list1*2
This statement is the same as the statement above, i.e., list1 is:
- [6, 7, 8, 9, 6, 7, 8, 9]
Coming to the differences, (b) and (c) have no difference, they're the same. They store the value of list1*2 into list1.
Statement (a), however, is not a statement that stores a value, it simply prints the value of list1*2, i.e., the value of list1 will still be [6, 7, 8, 9].
Similar questions
Math,
5 months ago
Hindi,
5 months ago
Computer Science,
10 months ago
Computer Science,
10 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago