title: Returning tuple with a single item from a function
body: <p>Just came across this little bit of weirdness in Python and thought I'd <strike>document it</strike> <em>write it as a question here in case anyone else is  trying to find an answer with the same fruitless search terms I was</em>   </p>
  
  <p>Looks like tuple unpacking makes it so you can't return a tuple of length 1 if you're expecting to iterate over the return value. <em>Although it seems that looks are deceiving. See the answers.</em></p>
  
  <pre><code>&gt;&gt;&gt; def returns_list_of_one(a):
  ...     return [a]
  ...
  &gt;&gt;&gt; def returns_tuple_of_one(a):
  ...     return (a)
  ...
  &gt;&gt;&gt; def returns_tuple_of_two(a):
  ...     return (a, a)
  ...
  &gt;&gt;&gt; for n in returns_list_of_one(10):
  ...    print n
  ...
  10
  &gt;&gt;&gt; for n in returns_tuple_of_two(10):
  ...     print n
  ...
  10
  10
  &gt;&gt;&gt; for n in returns_tuple_of_one(10):
  ...     print n
  ...
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  TypeError: 'int' object is not iterable
  &gt;&gt;&gt;
  </code></pre>