Given a string str. The task is to check whether it is a binary string or not.
Input: str = "01010101010" Output: Yes Input: str = "geeks101" Output: No
Approach 1: Using Set
- Insert the given string in a set
- Check if the set characters consist of 1 and/or 0 only.
Approach 2: Simple Iteration
- Iterate for every character and check if the character is 0 or 1.
- If it is not then set a counter and break.
- After iteration check whether the counter is set or not.
- String slicing in Python to check if a string can become empty by recursive deletion
- Check divisibility of binary string by 2^k
- Check if a binary string contains consecutive same or not
- Check if a binary string contains all permutations of length k
- Check if a binary string has two consecutive occurrences of one everywhere
- Check if a binary string has a 0 between 1s or not | Set 1 (General approach)
- Check if it is possible to rearrange a binary string with alternate 0s and 1s
- Check if an encoding represents a unique binary string
- Check if a binary string has a 0 between 1s or not | Set 2 (Regular Expression Approach)
- Check whether a binary string can be formed by concatenating given N numbers sequentially
- Python | Check for URL in a String
- Python set to check if string is panagram
- Python Set | Check whether a given string is Heterogram or not
- Python | Check if substring present in string
- Python | Check if frequencies of all characters of a string are different
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.