def check_utf8(string):
 if (not string):
  return False
 try:
  if isinstance(string, unicode):
   string.encode('utf-8')
  else:
   string.decode('UTF-8')
  return ('\x00' not in string)
 except UnicodeError:
  return False

def check_utf8 ( string ) : if ( not string ) : return False try : if isinstance ( string , unicode ) : string . encode ( 'utf-8' ) else : string . decode ( 'UTF-8' ) return ( '\x00' not in string ) except UnicodeError : return False
validate if a string is valid utf-8 str or unicode and that it does not contain any null character .