0
In python3, What does b = a [ : ] do?
a = [ 1, [ 2,3] ] b = a [ : ] What does a [ : ] do?
2 odpowiedzi
+ 3
a[:] produces a copy of the elements in a list.
+ 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]