title: Python Return error from function
body: <p>I am writing a python function which uses two arrays of equal size [n,1].   Before performing any calculations, I'd like to check to ensure the lengths are the same, and if not, return an error.   What is the best practice?  </p>
  
  <pre><code>def do_some_stuff(array1, array2): 
  # Before doing stuff, check to ensure both arrays have the same length
  
  if len(array1) != len(array2):
  #  Break and return with error
  </code></pre>
  
  <p>I'm confused, because I want to break and return an error code (say -1).   Seems that break will return without any value, and return will continue to execute the function?   Or does Return break out of any remaining code? </p>