[TriLUG] OT-ish: Python array slicing question

Brian via TriLUG trilug at trilug.org
Mon Dec 12 11:17:57 EST 2022


Hi Gang,

I figure there's probably someone in the group that can answer a 
question for me.

I'm maintaining some Python code written by people no longer with the 
company.  I'm also a Python newbie myself, so now and then I come across 
something that doesn't make sense and eludes my Google-fu.

Given an array:
a = [1, 2, 3, 4, 5]

Is there any difference whatsoever in these two conventions:

b = a[:]
b = a

A simple experiment in an interactive session doesn't seem to show any 
difference, and my understanding of array slicing says there shouldn't 
be any difference, so why would anyone write the former instead of the 
latter?

Thanks,
-Brian


More information about the TriLUG mailing list