slicing Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

slicing Python

Someone can explain me why the answer is "l"?: s="Welcome" print(s[2::-4]) Output: l

30th Jan 2020, 12:45 AM
Gustave A C/D C ☢️ 🛸♨️🛸🛸
1 Answer
+ 6
The first number says where you start. That's index 2 - 'l'. The second number says where you stop; if there's no value, it means 'till nothing is left'. The third value says how big the steps are, and in which direction. Minus means 'backwards'. So our next letter after l would be 4 steps to the left. Unfortunately there isn't anything there - string's already over. Read this as well: https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2453/?ref=app
30th Jan 2020, 12:51 AM
HonFu
HonFu - avatar