In python Why is this :: symbol is used can anyone would like to explain me this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
+ 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