title: Python, checking if string consists only of 1's and 0's
body: <p>I'm trying to write a function that checks if given string is binary or not. I'm using a while loop to browse characters in string one by one. If all of them are 0's or 1's it's going to return True, if anything is not  - break the loop and return False.
  I've just written this tiny part of code, but it doesn't run. Why?</p>
  
  <pre><code>def fnIsBin(string):
      count = 0
      while count &lt; len(string):
          character = string[count]
          if character == '0' or character == '1':
              print (count, character[count], "OK")
              count = count+1
              continue
          else:
              print (count, character[count], "ERROR")
              return False
              break
  </code></pre>
  
  <p>EDIT:<br>
  I also tried using 'set' to elude iterating with loop, but i don't quite get how does "set(string)" work. I got error that i cant consider it as a list. So how can I compare elements to 0 &amp; 1?</p>
  
  <pre><code>def fnIsBin(string):
  charactersList = set(string)
  if len(charactersList) &gt; 2:
      return False
  else:
      if (charactersList[0] == '0' or charactersList[0] == '1') and (charactersList[1] == '0' or charactersList[1] == '1'): #there i made error, how to deal with it?
          return True
      else:
          return False
  </code></pre>