
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
A unique string in Python
Suppose we have a string s, we have to check whether it has all unique characters or not.
So, if the input is like "world", then the output will be True
To solve this, we will follow these steps −
set_var := a new set from all characters of s
return true when size of set_var is same as size of s, otherwise false
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, s): set_var = set(s) return len(set_var) == len(s) ob = Solution() print(ob.solve('hello')) print(ob.solve('world'))
Input
hello world
Output
False True
- Related Articles
- First Unique Character in a String in Python
- Check if an encoding represents a unique binary string in Python
- Python program to check if a string contains all unique characters
- Python program to check if a string contains any unique character
- Find the longest substring with k unique characters in a given string in Python
- Program to find length of concatenated string of unique characters in Python?
- Program to find split a string into the max number of unique substrings in Python
- Unique Paths in Python
- Number of non-unique characters in a string in JavaScript
- Unique Substrings in Wraparound String in C++
- Unique substrings in circular string in JavaScript
- Program to find minimum required chances to form a string with K unique characters in Python
- How to find a unique character in a string using java?
- Creating all possible unique permutations of a string in JavaScript
- How to find unique characters of a string in JavaScript?

Advertisements