Q. What is the difference between following two expressions, if Ist is given as [1, 3, 5]
(i) lst * 3
(ii) lst *= 3
Answer =
In first case value of given list ‘lst’ will not change while in second case value of given list ‘lst’ will change.
(i) Give output [ 1,3,5,1,3,5,1,3,5]
(ii) lst *= 3 will change value of lst
Now lst become
lst = [ 1,3,5,1,3,5,1,3,5]
part of qn is missing?
ReplyDeleteWhich part.
Deletenot an understanding answer
ReplyDelete(i) Give output [ 1,3,5,1,3,5,1,3,5]
Delete(ii) lst *= 3 will change value of lst
Now lst become
lst = [ 1,3,5,1,3,5,1,3,5]
lst*3
ReplyDeleteit will repeat the list elements 3 time like [1,3,5,1,3,5,1,3,5]
(i) Give output [ 1,3,5,1,3,5,1,3,5]
Delete(ii) lst *= 3 will change value of lst
Now lst become
lst = [ 1,3,5,1,3,5,1,3,5]
Is question ka (ii) part nahi hai .....
ReplyDeletePlease check it again.
DeletePlease tell whole question.
ReplyDeletediff b/w 1st+3 and 1st+=[3] is the second part of the question
ReplyDeletelst + 3 will cause an error as both operands of + operator should be of same type but here one operand is list and the other integer.
Deletelst += [3] will add 3 to the end of lst so lst becomes [1, 3, 5, 3].
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )