# 'Introduction to Python Programming' Course - Question

**URL:** <https://forum.anaconda.com/t/introduction-to-python-programming-course-question/47790>\
**Category:** Technical Topics\
**Created:** [December 22, 2022, 3:24pm UTC](https://forum.anaconda.com/t/introduction-to-python-programming-course-question/47790 "2022-12-22T15:24:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![austin.averill96](https://avatars.discourse-cdn.com/v4/letter/a/80bc00/32.png) [@austin.averill96](https://forum.anaconda.com/u/austin.averill96)\
**Post date:** [December 22, 2022, 3:24pm UTC](https://forum.anaconda.com/t/introduction-to-python-programming-course-question/47790/1 "2022-12-22T15:24:03Z")

</div>

I am new to python, and coding in general. However, I ran into something that didn’t quite seem to make sense whenever going through the ‘Introduction to Python Programming’ course. Specifically in the section ‘Collections: Referencing, Methods, and extend’ when talking about issues referencing other lists, and the use of the .copy() function.

For reference without the video, the lists and problem are as follows:

list\_1 = [song\_1, song\_2, song\_3]  
list\_2 = list\_1  
list\_1  
return \> song\_1, song\_2, song\_3  
list\_2  
return \> song\_1, song\_2, song\_3

#the problem is posed that with the ‘list\_1 = list\_2’ reference, when list\_1 is altered - those changes also appear in list\_2.

list\_1 = [song\_1, song\_2, song\_3]  
list\_2 = list\_1  
list\_1 = list\_1 + [song\_4]  
list\_1  
return \> song\_1, song\_2, song\_3, song\_4  
list\_2  
return \> song\_1, song\_2, song\_3, song\_4

#instead, the instructor suggests that we reference list\_1 by using the .copy() function so that the lists are not locked in reference.

list\_1 = [song\_1, song\_2, song\_3]  
list\_2 = list\_1.copy()  
list\_1  
return \> song\_1, song\_2, song\_3  
list\_2  
return \> song\_1, song\_2, song\_3

#this all makes sense. However, the instructor then goes on to display the benefit of this by making changes to list\_2, instead of list\_1 (the reference).

list\_1 = [song\_1, song\_2, song\_3]  
list\_2 = list\_1.copy()  
list\_2 = list\_2 + [song\_4]  
list\_1  
return \> song 1, song\_2, song\_3  
list\_2  
return \> song\_1, song\_2, song\_3, song\_4

#my issue with this, or what I am not understanding is. That within the context of what the instructor executed, there is no functional purpose for the list copy. In code, the same goal could have been achieved with the following

list\_1 = [song\_1, song\_2, song\_3]  
list\_2 = list\_1 + [song\_4]  
list\_1  
return \> song\_1, song\_2, song\_3  
list\_2  
return \> song\_1, song\_2, song\_3, song\_4

#I believe what the instructor was instead trying to demonstrate is the following, where a copy of the reference list is made, then the reference list is modified without impacting list\_2. As follows:

list\_1 = [song\_1, song\_2, song\_3]  
list\_2 = list\_1.copy()  
list\_1 = list\_1 + [song\_4]  
list\_1  
return \> song\_1, song\_2, song\_3, song\_4  
list\_2  
return \> song\_1, song\_2, song\_3

My overall questions are as follows, was there any point in doing what the instructor did in the video over the code I provided for his final return? Is my final block of code what he really intended?

Thank you!
