Difference between revisions of "Code Snippet: Print String Backwards"

From Coder Merlin
Line 10: Line 10:


== Python ==
== Python ==
<syntaxhighlight lang="python">
string = "That Which Survives"
# Short & Fast
print(string[::-1])
# More readable
print(''.join(reversed(string)))
</syntaxhighlight>
[https://stackoverflow.com/questions/931092/reverse-a-string-in-python Source]

Revision as of 17:39, 24 December 2018

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Print String Backwards[edit]

Swift[edit]

let string = "That Which Survives"
for character in string.reversed() {
    print(character)
}

Python[edit]

string = "That Which Survives"
# Short & Fast
print(string[::-1])
# More readable
print(''.join(reversed(string)))

Source