I recently read code snippets on how to change the sequence
>> l = [1,2,3,4,5,6] >> print l[::-1]
>> [6,5,4,3,2,1]
How to explain the first colon in parenthesis?
Colons without predefined values ββresort to default values. The default values ββfor the index start when the step is negative len(l), and the end index -len(l)-1. Thus, back slicing can be written as
len(l)
-len(l)-1
l[len(l):-len(l)-1:-1]
which has the form.
l[start:end:step]
By extracting the default values, we can use it in a shorter notation like l[::-1].
l[::-1]
It might be useful to consider this issue in the Python Snippet Designation .
some_list[start:end:step]
- , . , : start - , 0, , end - , ( , ), , step - .
, , : " ".
EDIT: ,
[1,2,3,4,5,6][5:-7:-1]
,
[1,2,3,4,5,6][::-1]
Python3. - ? , ( ).
Source: https://habr.com/ru/post/1534128/More articles:Google Play Game Services Login - androidStop Eclipse-Kepler from showing live html page views - eclipseHow to convert gradle project to android project - androidUsing "if in" with a dictionary - pythonZurb Foundation 5 and Windows Phone 8: the site is not always full screen - zurb-foundationHow to play a sound file? - c #Maximum stroke in R - rHow to configure Monit with Amazon SAS - ruby-on-railsArray of arrays of different sizes - cEnable disable controls in a row of a table - jqueryAll Articles