0
>>> a=['k','l']
>>> b=a
>>> b[0]='M'
>>> b
['M', 'l']
>>> a
['M', 'l']

Can any one please explain why index value 0 in a getting changed and also how to avoid this ?

steveJ
  • 2,171
  • 3
  • 11
  • 16
  • 1
    Thanks for help. But wonder why people use down vote to questions. Sometimes it happens that we miss already answered question. It can be always marked as duplicate without giving down vote. – steveJ Jun 02 '18 at 09:04
  • I did not downvote, but I think the reason others did is that this is such a common question on this site. Also, this is explained in the official Python documentation. – Rory Daulton Jun 02 '18 at 09:16
  • For the record, I didn't downvote the question. However, hovering over the downvote button displays the following message: `This question does not show any research effort; it is unclear or not useful`. By that definition a downvote is appropriate for duplicate questions. – rst-2cv Jun 02 '18 at 09:19
  • In any case, on the topic of the question you asked @steveJ, this is a good resource about mutation: http://book.pythontips.com/en/latest/mutation.html – rst-2cv Jun 02 '18 at 09:21
  • @RoryDaulton It was just a thought not any blame :) – steveJ Jun 02 '18 at 09:40
  • @ResetACK Got it. – steveJ Jun 02 '18 at 09:41

0 Answers0