3 ms·
Missed python's slicing: >>> 'abcdefghijklmnopqrstuvwxyz'[1:20:4] 'bfjnr' It's start/end/skip, with default values of 0, length, 1; each can be omitted so
by Izkata 2y ago
Missed python's slicing:
>>> 'abcdefghijklmnopqrstuvwxyz'[1:20:4]
'bfjnr'
It's start/end/skip, with default values of 0, length, 1; each can be omitted so it's rare to see the third one unless someone is showing off how to reverse a string:
>>> 'abcdefghijklmnopqrstuvwxyz'[::-1]
'zyxwvutsrqponmlkjihgfedcba'
Though really these are slice objects, it's just the syntax only works inside array access:
>>> slice
<class 'slice'>
>>> z = slice(1, 20, 4)
>>> 'abcdefghijklmnopqrstuvwxyz'[z]
'bfjnr'
- JadeNB 2y agoI think this may fall (conceptually) under the range operators.