Moving around in a string
Troels Therkelsen
t_therkelsen at hotmail.com
Sat Dec 6 04:13:53 EST 2003
In article <pan.2003.12.06.08.41.52.268170 at earthlink.net>, Ryan Spencer wrote:
[snip]
> Well, I've gotten to an exercises where it wants me to write a translation
> program that takes input from the user and translates it into either pig
> Latin or something called "ubby dubby". It describes the basic rules and
> all, and I somewhat understand in my mind on how to go about doing it, but...
>
> It requires me to, for the pig Latin part, remove the first letter and
> move it to the end of a string (and then add ay to the end.)
>
> How should I go about "moving" to the end of the string?
>
> Just for clarification I want to do something like...
>
> Please enter a word: Orange
>
> rangeOay
>
> (taking the O and bringing it to end and then adding 'ay' to the end)
This sounds suspiciously like homework, but...
>>> foo = "Orange"
>>> bar = foo[1:] + foo[0] + 'ay'
>>> bar
'rangeOay'
In other words, you can index strings the same way as any other sequence,
[0] is the first element of the sequence, [1] the second, [-1] is the last,
and so forth.
See also the standard documentation on sequences:
http://www.python.org/doc/current/lib/typesseq.html
Regards,
Troels Therkelsen
More information about the Python-list
mailing list