Boston Python Workshop 6/Data types: Difference between revisions
Content added Content deleted
imported>Jesstess No edit summary |
imported>Jesstess No edit summary |
||
Line 214: | Line 214: | ||
>>> her_list[:] |
>>> her_list[:] |
||
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] |
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] |
||
</pre> |
|||
====Sharing versus copying==== |
|||
<b>Sharing</b><br /> |
|||
<pre> |
|||
>>> my_list |
|||
['Alice'] |
|||
>>> your_list = my_list |
|||
>>> your_list |
|||
['Alice'] |
|||
>>> my_list[0] = "Bob" |
|||
>>> my_list |
|||
['Bob'] |
|||
>>> your_list |
|||
['Bob'] |
|||
</pre> |
|||
<b>Copying</b><br /> |
|||
<pre> |
|||
>>> my_list |
|||
['Alice'] |
|||
>>> your_list = my_list[:] |
|||
>>> my_list[0] = "Bob" |
|||
>>> my_list |
|||
['Bob'] |
|||
>>> your_list |
|||
['Alice'] |
|||
</pre> |
</pre> |
||