[Tutor] Beginner Question

Daniel McQuay simplebob at gmail.com
Mon Jun 19 00:39:03 CEST 2006


On 6/18/06, Josh F <jj_frap at hotmail.com> wrote:
>
> re. Beginner Question
>
> I'm still in the fairly early stages of learning Python, but I have an
> intermediate level of HTML, CSS, and VB6 knowledge along with the
> fundamentals of C and C++ and a very little bit of PERL..
>
> But enough about me...Here's the solution.
>
> message = raw_input("Enter your message:")
> print message[-1::-1]


just another noob here.
but wouldn't his way work like this:

>>>message = "foobar"
>>>for i in range(len(message)-1,-1,-1):
...     print message[i],
...
r a b o o f

i guess there's lots of ways to do it.
that's my 2 cents.

Slicing a string takes three arguments, all of which are optional: The first
> character to be sliced, the last character to be sliced, and tio slice
> every
> nth character.
>
> In Python strings, -1 refers to the last character in the string and thus
> becomes the first argument.
>
> You don't specify the second argument because you're printing the string
> from end to beginning.
>
> Finallly, the -1 in the 3rd argument indicates that you want the string to
> be printed in reverse order (i.e. iterate backwards by one character).
>
>
>
>
>
>
>
> >Message: 1
> >Date: Sun, 18 Jun 2006 05:58:38 -0500
> >From: "Bill Tatum" <btatum at cddn.com>
> >Subject: [Tutor] Beginner question(s)
> >To: <tutor at python.org>
> >Message-ID: <20060618105838.0DB326318 at mem01.ecsis.net>
> >Content-Type: text/plain; charset="us-ascii"
> >
> >Hi,
> >
> >
> >
> >I'm working through Python Programming for the Absolute Beginner.  One of
> >the challenges at the end of chapter 4 is to get a message from the user
> >and
> >then print it out backwards. I have.
> >
> >
> >
> >message = raw_input("Enter your message:")
> >
> >count = len(message)
> >
> >print count
> >
> >
> >
> >which gives me the number of characters in the message.  I tried to use a
> >for loop:
> >
> >
> >
> >for i in range(len(message)-1,-1, -1):
> >
> >     print i,
> >
> >
> >
> >but I just get the numeric values of the string.  Can anyone help?
> >
> >
> >
> >Also, does anyone know of a PDA that would run python?
> >
> >
> >
> >TIA
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Daniel McQuay
simplebob at gmail.com
boxster.homelinux.org
H: 814.825.0847
M: 814-341-6233
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060618/6d6486a1/attachment.htm 


More information about the Tutor mailing list