Python Sort String Tutorial |
This tutorial will teach you how to sort strings in Python.
Table of Contents
Sort String in Python
To sort a string in Python, you can use the `sorted()` function or the `sort()` method.
Example
def sort_string(s):
return ''.join(sorted(s))
string = "hello"
sorted_string = sort_string(string)
print(sorted_string) # Output: ehllo
YouTip