title: Proper way to assert type of variable in Python
body: <p>In using a function, I wish to ensure that the type of the variables are as expected. How to do it right?</p>
  
  <p>Here is an example fake function trying to do just this before going on with its role:</p>
  
  <pre><code>def my_print(begin, text, end):
      """Print 'text' in UPPER between 'begin' and 'end' in lower
  
      """
      for i in (begin, text, end):
          assert isinstance(i, str), "Input variables should be strings"
      out = begin.lower() + text.upper() + end.lower()
      print out
  
  def test():
      """Put your test cases here!
  
      """
      assert my_print("asdf", "fssfpoie", "fsodf")
      assert not my_print("fasdf", 33, "adfas")
      print "All tests passed"
  
  test()
  </code></pre>
  
  <p>Is assert the right approach? Should I use try/except instead?</p>
  
  <p>Also, my assert set of tests does not seem to work properly :S</p>
  
  <p>Thanks pythoneers</p>