Introducing the "for" loop
On Fri, 6 Oct 2017 11:44 pm, ROGER GRAYDON CHRISTMAN wrote:
> Despite the documentation, I would still be tempted to say that range is a
> Taking duck-typing to the meta-level, every time I use range, I use its name
> by a pair of parentheses enclosing one to three parameters, and I get back
> immutable sequence object. It sure looks like a function to me.
I agree -- range() is a function in the (almost) mathematical sense, something
which takes arguments and returns a value. It's also a type (class), in the
The term "function" is ambiguous but normally clear from context. Often, the
differences make no difference, but when they are important, we can discuss
- range is a callable (a callable object);
- it is also a type/class, and calling it returns an instance;
- it looks like, and behaves like, a function;
- and is, conceptually, a function;
- but it is *not* an instance of FunctionType:
py> from types import FunctionType
py> def function():
py> isinstance(function, FunctionType)
py> isinstance(range, FunctionType)
It is this last sense (an instance of FunctionType) which people are thinking
of when they state that range is not a function.
?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure
enough, things got worse.