Sort String Characters in Python
Sort the characters of a string in ascending order.
BeginnerString ProgramsExample 13 of 25
sort-string-characters.py
Run in browser1# Program to sort characters of a string23s = input("Enter a string: ")45sorted_s = "".join(sorted(s))67print("Sorted string:", sorted_s)
Output
Enter a string: dbca Sorted string: abcd
What's going on
We use the built-in sorted() which returns a list of sorted characters, then join them back to a string.