1

I'm new to this site (please forgive if this is long), and I did try to search for an answer to this issue but I didn't find one that addressed it (or at least in a way that I understood).

I'm using the eBook Learning Python (which is very good), and the book suggested to try something (without revealing the answer - pg 75). What I've tried ALMOST works but something weird is happening, and I'd like to understand it better.

So, say string

s = 'This is a sentence.'.
len(s) = 19 

(no prob, got this).

But then it asks to produce this in reverse order. I followed the slicing example it gave, but since I'm reversing, I tried this:

print(s[len(s):0:-1])

I also tried:

print(s[len(s)+1:0:-1])      #also tried using -1 as my 'stop' argument.

What happens is that it prints in reverse but leaves off the first character:

.ecnetnes a si sih

The only way I could get the initial 'T' to show is by putting a leading space at the beginning (which works but seems kind of shoddy). This also seems to 'indicate' what the issue may be but I'm just not getting it - I've tried quite a number of variations, but nothing seems to work. Hope this question wasn't too long, but I wanted to be clear what the issue was.

BTW, if I use 0 as the first arg (start) and len(s)+1 as 'stop', it does nothing.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 2
    Try replacing `0` with `None` or simply leaving it blank, see what happens (just a hint) – Ofer Sadan Jun 16 '18 at 20:12
  • Thank you Ofer. Both None and leaving it blank both worked, I didn't initially glean that from the previous posts I looked at but perhaps I didn't go through enough of them - or whatev. I'll try to be more thorough in future. – Larry Apuzzo Jun 16 '18 at 22:54

0 Answers0