I have seen some programs in python has [::] in the code. But I can't understand why to use and when to use this. Could you please provide some description in a simple language? Thanks in advance.
Asked
Active
Viewed 269 times
2
-
https://stackoverflow.com/questions/3453085/what-is-double-colon-in-python-when-subscripting-sequences; if you see literally `[::]`, it’s just a longer way of writing `[:]`. – Ry- Nov 19 '19 at 07:27
-
See also [this answer](https://stackoverflow.com/a/13005464/550094) in the suggested duplicate. – Thierry Lathuille Nov 19 '19 at 07:28
-
The [::] operator is for filtering Array/List by index number. For example x = [1,2,3,4,5,6,7,8] 1)print(x[::]) - will print the whole array which is equal to print(x[0:5:1] 2)print(x[0:6:2] - will print [1,3,5] 3) print(x[0:6:3] - will print [1,4] Therefore [x:y:z] x = first index number from where the output list will start y = last index number before which the output list will end z = the gap between the index/list items that will be printed. – Surja Nov 19 '19 at 07:31
-
that's should be an answer ! – αԋɱҽԃ αмєяιcαη Nov 19 '19 at 07:38