def countNonPrintableChars(string):
 counter = 0
 for i in range(len(string)):
  if ((ord(string[i]) <= 31) or (ord(string[i]) > 127)):
   counter += 1
 return counter

def countNonPrintableChars ( string ) : counter = 0 for i in range ( len ( string ) ) : if ( ( ord ( string [ i ] ) <= 31 ) or ( ord ( string [ i ] ) > 127 ) ) : counter += 1 return counter
simple method to return the non printable characters found in an string .