To sort string in alphabetical order, you have to ask from user to enter any string to sort the entered string in alphabetical order and print the sorted string as output as shown in the program given below.
Following python program ask from the user to enter the string to sort it into alphabetical order to display the sorted string:
# Python Program - Sort String in Alphabetical Order print("Enter 'x' for exit."); string = input("Enter any string to sort in alphabetical order: ") if string == 'x': exit(); else: print("\nString after sorted in alphabetical order:"); print(''.join(sorted(string)));
Here is the sample run of the above python program to show how to sort string in alphabetical order:
Now enter any string say codescracker and press enter key to sort the entered string in alphabetical order, that is a comes first (if present) and z comes last (if present):
Same program on python shell:
Program Video with Compile and Run
You may also like to learn or practice the same program in other popular programming languages: