title: Python how to exit main function
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/73663/terminating-a-python-script">Terminating a Python script</a><br>
    <a href="https://stackoverflow.com/questions/949504/terminating-a-python-program">Terminating a Python Program </a>  </p>
  </blockquote>
  
  
  
  <p>My question is how to exit out in Python main function? I have tried '<code>return</code>' but it gave the error <code>SyntaxError: 'return' outside function</code>. Can anyone help? Thanks.</p>
  
  <pre><code>if __name__ == '__main__':
    try:
      if condition:
      (I want to exit here) 
      do something
    finally:
      do something
  </code></pre>