Doraemon
Doraemon

Reputation: 41

Reverse String slicing with first letter as it is

I am bit confused about reverse string slicing. I mean we have string stored in c variable , so writing it in reverse order is like c[::-1] will reverse the string. But i want to know how do i do it if i want first letter of entered string to be as it is.

Upvotes: 0

Views: 189

Answers (1)

ferhatelmas
ferhatelmas

Reputation: 3978

a[start:end:step] # start through not past end, by step

a[:1] # take first character
a[-1:0:-1] # start from end and take until first character in reverse

a[:1] + a[-1:0:-1] # what you want

Upvotes: 1

Related Questions