<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">Hi,Harrison.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">
Your method is cool.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">But i doubt this, if bList and aList just are attached to the same List when i write bList=aList,but why the output of the following two code are different?</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">
code1:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><div>aList=[1,2,3,4,5,6,7,8,9,10]</div><div>bList=aList</div><div>bList=str(bList)</div><div>print aList</div>
<div>print aList[2]</div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">
code2:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><div>aList=[1,2,3,4,5,6,7,8,9,10]</div><div>aList=str(aList)</div><div>print aList</div><div>print aList[2]</div>
</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)"><br></div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)">i'm puzzled now.</span> <br>
<br><div class="gmail_quote">2012/7/4 Harrison Morgan <span dir="ltr"><<a href="mailto:harrison.morgan@gmail.com" target="_blank">harrison.morgan@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br><br><div class="gmail_quote">On Wed, Jul 4, 2012 at 12:38 AM, levi nie <span dir="ltr"><<a href="mailto:levinie001@gmail.com" target="_blank">levinie001@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
that's good,thanks.<div>new problem.</div><div>when i write</div><div>bList=aList</div><div>del bList[2]</div><div>bList and aList both change,how can i make aList not changed?</div><div><div>
<div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div><br></div>
</div></div></blockquote></div><br></div><div>Lists are mutable. That means that when you do bList = aList, you're just creating another reference to aList. They both point to the same list, just using different names. You should read up a bit on immutable vs. mutable objects. Here's something that I found that might explain it a bit better. <a href="http://henry.precheur.org/python/copy_list" target="_blank">http://henry.precheur.org/python/copy_list</a></div>
</blockquote></div><br>