Sort String Characters

Sort the characters of a string in ascending order.

BeginnerTopic: String Programs
Back

Python Sort String Characters Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# 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.

Table of Contents