How we do indexing our string using backword position | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

How we do indexing our string using backword position

x=('apple') we want to print only last two letter of string x using backward positions. we know in backward direction in apple 'e' has -1 position then what we can use this for print last two letter of 'apple' print(x[-1:-1])

19th Feb 2018, 5:16 PM
Maninder $ingh
Maninder $ingh - avatar
2 Answers
+ 3
no that will print an empty set. you need to do x[-2:]
19th Feb 2018, 5:27 PM
Obbu
Obbu - avatar
19th Feb 2018, 5:32 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar