On 6/18/06, Josh F <[EMAIL PROTECTED]> 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" <[EMAIL PROTECTED]>
>Subject: [Tutor] Beginner question(s)
>To: <tutor@python.org>
>Message-ID: < [EMAIL PROTECTED]>
>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@python.org
http://mail.python.org/mailman/listinfo/tutor



--
Daniel McQuay
[EMAIL PROTECTED]
boxster.homelinux.org
H: 814.825.0847
M: 814-341-6233
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to