3 ms·
Although I mostly agree with "Returning more than one variable type from function call," I do have some disagreement. On the restriction itself, I'm fine with
by a3n 12y ago
Although I mostly agree with "Returning more than one variable type from function call," I do have some disagreement.
On the restriction itself, I'm fine with returning, for example, any kind of iterable, whether it's a list, tuple, string or whatever. It depends on context, and python is very much an interface/context kind of language.
As for the anti-example given, that code would not fail in most print contexts:
In [1]: a = None
In [2]: print a
None
A better anti-example might have been:
In [3]: for i in a:
...: print i
...:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-6fc9adb94b0c> in <module>()
----> 1 for i in a:
2 print i
3
TypeError: 'NoneType' object is not iterable
- ThePhysicist 12y agogood point, will change this!