list(), tuple() should not place at "Built-in functions" in documentation

Chris Angelico rosuav at gmail.com
Fri Jul 15 08:24:07 CEST 2011


On Fri, Jul 15, 2011 at 11:32 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Inside wrote:
>
>> As telling in the subject,because "list" and "tuple" aren't functions,they
>> are types.Is that right?
>
> Yes they are types. But they can still be used as functions. Does it matter?

Python is duck-typed, even in its documentation. If Python describes
something as a function, it means it can be used in place of func in
here:

result = func(arg1, arg2, arg3)

It might be something created with def (a "classic" function). It
might be something created with lambda. It might be an object with a
__call__ method. It might be a type.

>>> class foo:
	def __call__(self):
		return lambda: print("asdf")

>>> bar=foo()
>>> quux=bar()
>>> quux()
asdf

How many functions are defined here?

Chris Angelico



More information about the Python-list mailing list