In python3, What does b = a [ : ] do? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

In python3, What does b = a [ : ] do?

a = [ 1, [ 2,3] ] b = a [ : ] What does a [ : ] do?

6th Jun 2019, 9:31 AM
Ticonderoga
Ticonderoga - avatar
2 Answers
+ 3
a[:] produces a copy of the elements in a list.
6th Jun 2019, 9:46 AM
HonFu
HonFu - avatar
+ 2
if there is a empty space before colon means , the output contains from the very 1st element in the list to the mentioned element example= a=[1,3,4,6] print(a[ :2] output=[1,3] If there is a empty space after the colon , it means they're output contains from the mentioned element to the very last element Ex= a=[1,3,4,5] print(a[2: ]) output= [4,5] So if both the spaces r empty , output contains the whole list, from the 1st to last element Ex= a=[1,4,6,8] print(a[ : ]) Output: [1,4,6,8]
6th Jun 2019, 6:35 PM
RALPH RYDER
RALPH RYDER - avatar