+ 2
What does “:” mean here?
x = “abcde” y = x[-1:] #actually this “:” one print(len(y))
3 Antworten
+ 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
+ 2
Thank you so much! Now I understand! Good luck🙏🏼
+ 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..