Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-03-2005, 09:14 PM   #1 (permalink)
slashdot
Registered User
 
Join Date: Dec 2004
Posts: 43
slashdot is on a distinguished road
How to write a whole string backwards.

Realy quike, how do I write a whole string backwards, letter to letter. I can get all the way to the last letter then it just doesn't go any further. It'll give out some random error after wards if I try to put in a number above how many I have. So the code is...

aStr = "This is a string"
print aStr[-14:what?]

I tried 1 and then 14 like it says in a newbie documentation I found at python.org. I don't realy know what else to say at the moment I need to sleep for school tomarow. Hopefully someone has an answer to it. Thanx in advance.
slashdot is offline   Reply With Quote
Old 03-04-2005, 06:56 AM   #2 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 287
technobard is on a distinguished road
A quick google search came up with this:

str = "Hello, world!"
revstr = str[::-1]
print revstr

Or (Python 2.4):

str = "Hello, world!"
print "".join(reversed(str))
__________________
It takes 2 points to draw a straight line, but at least 3 points to draw a conclusion.
technobard is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for another program Androto Standard C, C++ 54 10-15-2004 08:21 AM
sorting objects arrays by object properties sde Java 28 08-05-2004 06:51 AM
From C to Java HighterDK Java 11 07-13-2004 08:15 PM


All times are GMT -8. The time now is 01:36 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting