| | |
Spell a String in reverse
Thread Solved |
This works:
[php]
s = "banana"
s_reversed = s[::-1]
[/php]
It might be helpful to encapsulate it:
[php]
def s_reverse(s):
return s[::-1]
s = "banana"
s_reversed = s_reverse(s)
print s_reversed # ananab
x = "hello"
x_r = s_reverse(x)
print x_r # olleh
[/php]
[php]
s = "banana"
s_reversed = s[::-1]
[/php]
It might be helpful to encapsulate it:
[php]
def s_reverse(s):
return s[::-1]
s = "banana"
s_reversed = s_reverse(s)
print s_reversed # ananab
x = "hello"
x_r = s_reverse(x)
print x_r # olleh
[/php]
Last edited by LaMouche; Oct 28th, 2006 at 5:41 pm.
![]() |
Similar Threads
- Starting Python (Python)
- Factorial of any length (C++)
- hex string, reverse and move 4 LSB ??? (Python)
- I Need Help!! (Java)
- Conver int Array into a String (Java)
Other Threads in the Python Forum
- Previous Thread: traceback error?
- Next Thread: tribute project for daniweb
| Thread Tools | Search this Thread |
address aliased anydbm bash beginner bits calling casino changecolor class clear conversion convert corners count cturtle cursor curves definedlines dictionary digital dynamic dynamically events examples excel external file float format frange function gui handling hints homework i/o iframe import info input java line linux list lists loan loop matching mouse multiple number numbers output parsing path port prime programming projects py py2exe pygame python random rational raw_input recursion recursive scrolledtext searchingfile shebang signal singleton string strings subprocess table tails terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode urllib urllib2 valueerror variable web-scrape whileloop word wxpython






