[Tutor] Questions regarding strings

Daniel asmosis.asterix at gmail.com
Sun Aug 8 19:04:19 CEST 2010


Hello everyone! I would like to ask you two questions regarding strings
which I do not know. Excuse me in advance if the questions may seem a bit
dumb. I'm a beginner. So let's get back to the point, this is my string:

msg= 'Hello world'
If I do, msg[:3] I get the following output, 'Hel'
If I do, msg[6:] I get the following output, 'World'
Ok, so I understand why this is happening. What I do not understand is why I
get the following output in this cases.


1) msg[:-1] which has the output 'Hello Worl'
2) msg[0:6:2]  'Hlo'
3) msg[::-1] 'dlroW olleH'

Can someone please explain this to me? Thank you so much and I wish everyone
a great day!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100808/97ae46ae/attachment.html>


More information about the Tutor mailing list