Hello everyone, welcome to nkcoderz.com. In this article we will going to discuss about Reverse A String In Python.
To reverse a string in Python, you can use the following code:
def reverse(s): return s[::-1]
This function takes a string as input and returns a new string with the characters in reverse order.
Reverse A String In Python
Here’s an example of how you could use this function:
string = "hello" print(reverse(string))
This code would output the reversed string “olleh”.
Alternatively, you could use the built-in
reversed function, which returns an iterator that produces the items of the input in reverse order:
string = "hello" print("".join(reversed(string)))
If you liked this post, then please share this with your friends and make sure to bookmark this website for more awesome content.