What is the most efficient way to spell a string in reverse, for instance s = "banana".
sneekula
969
Nearly a Posting Maven
Recommended Answers
Jump to PostThis works:
s = "banana" s_reversed = s[::-1]
It might be helpful to encapsulate it:
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
All 3 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.