Sort String Characters
Sort the characters of a string in ascending order.
BeginnerTopic: String Programs
Python Sort String Characters Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# 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
Understanding Sort String Characters
We use the built-in sorted() which returns a list of sorted characters, then join them back to a string.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.