+ 2

In python Why is this :: symbol is used can anyone would like to explain me this

I have one program in which that symbol was used a=[5,10,15,20,25] del a[::2] print(a) And the output was [10, 20]

14th Aug 2019, 3:30 PM
Omkar Chavan
Omkar Chavan - avatar
5 Antworten
+ 9
These are two separate colons. a[start:stop:step] Take this & the next lessons again: https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2453/
14th Aug 2019, 4:17 PM
Janusz Bujak 🇵🇱 🇺🇦
Janusz Bujak 🇵🇱 🇺🇦 - avatar
+ 6
so in your sample the code means: a=[5,10,15,20,25] del a[::2] delete every 2nd element, starting from 1st element up to the last element. 5, 15 and 25 will be deleted. 20 and 20 remains.
14th Aug 2019, 4:55 PM
Lothar
Lothar - avatar
+ 4
can you show us the complete part / line of code. I estimate you mean this [::-1]?
14th Aug 2019, 3:48 PM
Lothar
Lothar - avatar
+ 2
[::2] is list slicing in that context it means removing every other element list slicing has many aplocations... 😄
14th Aug 2019, 4:16 PM
Anton Böhler
Anton Böhler - avatar
+ 2
Actually i did reached uptil the list slicing 😌😅 Then to but i know understood the concept properly 😎👍.I won't forget. thank guys for ur help
14th Aug 2019, 6:33 PM
Omkar Chavan
Omkar Chavan - avatar