Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
Adding an example on how negative start/end are computed betters this answer.
Source Link
Arsen Khachaturyan

I personally think about it like a for loop:

a[start:end:step]
# for(i = start; i < end; i += step)

Also, note that negative values for start and end are relative to the end of the list and computed in the example above by given_index + a.shape[0].

I personally think about it like a for loop:

a[start:end:step]
# for(i = start; i < end; i += step)

Also note that negative values for start and end are relative to the end of the list and computed in the example above by given_index + a.shape[0].

I personally think about it like a for loop:

a[start:end:step]
# for(i = start; i < end; i += step)

Also, note that negative values for start and end are relative to the end of the list and computed in the example above by given_index + a.shape[0].

Adding an example on how negative start/end are computed betters this answer.
Source Link
NucS

I personally think about it like a for loop:

a[start:end:step]
# for(i = start; i < end; i += step)

Also note that negative values for start and end are relative to the end of the list and computed in the example above by given_index + a.shape[0].

I personally think about it like a for loop:

a[start:end:step]
# for(i = start; i < end; i += step)

Also note that negative values for start and end are relative to the end of the list.

I personally think about it like a for loop:

a[start:end:step]
# for(i = start; i < end; i += step)

Also note that negative values for start and end are relative to the end of the list and computed in the example above by given_index + a.shape[0].

Active reading.
Source Link
Peter Mortensen

I personally think about it like a forfor loop:

a[start:end:step]    
# for(i = start; i < end; i += step)

Also note that negative values for start and end are relative to the end of the list.

I personally think about it like a for loop

a[start:end:step]    
# for(i = start; i < end; i += step)

Also note that negative values for start and end are relative to the end of the list.

I personally think about it like a for loop:

a[start:end:step]
# for(i = start; i < end; i += step)

Also note that negative values for start and end are relative to the end of the list.

Source Link
Raman
Loading
lang-py