def check_syntax(code):
 try:
  return compile(code, u'<string>', u'exec')
 except (SyntaxError, TypeError, UnicodeDecodeError):
  return False

def check_syntax ( code ) : try : return compile ( code , u'<string>' , u'exec' ) except ( SyntaxError , TypeError , UnicodeDecodeError ) : return False
return true if syntax is okay .