+ 2

What does “:” mean here?

x = “abcde” y = x[-1:] #actually this “:” one print(len(y))

1st Sep 2020, 10:19 PM
Dmitry Filimonov
Dmitry Filimonov - avatar
3 RĂ©ponses
+ 3
That is symbol used in syntax for separation of 3 arguments there .. Actual syntax variable[ starting_index : ending_index : step_count] Ending_index, step_count is optional.. Ex: X[1:] slice 1 to last X[: 5] slice 0 to 4. X[: : 2] only even indexes logic
1st Sep 2020, 10:29 PM
Jayakrishna 🇼🇳
+ 2
Thank you so much! Now I understand! Good luckđŸ™đŸŒ
1st Sep 2020, 10:36 PM
Dmitry Filimonov
Dmitry Filimonov - avatar
+ 2
X[-1: :] is slicing from reverse with last index to first step count 1(default) X[-1 : -5 : 2] select x[-1], x[-3] only in reverse until index - 5 (4 elements in reverse) as step count 2, means - 1 - 2 = - 3, - 3-2 =-5 Edit: Dmitry Filimonov you're welcome..
1st Sep 2020, 10:37 PM
Jayakrishna 🇼🇳