Sort String Characters

Sort the characters of a string in ascending order.

PythonBeginner
Python
# Program to sort characters of a string

s = input("Enter a string: ")

sorted_s = "".join(sorted(s))

print("Sorted string:", sorted_s)

Output

Enter a string: dbca
Sorted string: abcd

We use the built-in sorted() which returns a list of sorted characters, then join them back to a string.