Print Unique Characters of a String
To print unique characters of a string in Python, iterate over the characters of the string, prepare a list of unique characters, and print them.
In the following program, we take a string in
name variable, and print the unique characters in this string to console.
myString = 'banana' uniqueChars =  #get unique characters into a list for ch in myString : if ch not in uniqueChars : uniqueChars.append(ch) #print unique characters list for ch in uniqueChars : print(ch)Try Online
b a n
In the above program(s), we have used the following Python concepts. The links have been provided for reference.
- For Loop
- Create empty list in Python
- Add item to list
- Python not logical operator
- Python in – membership operator
- Python print() builtin function
In this Python Tutorial, we learned how to print unique characters of a given string in Python.