functions vs methods

Lele Gaifax lele at metapensiero.it
Sat Jul 21 17:05:35 EDT 2018


Sharan Basappa <sharan.basappa at gmail.com> writes:

> Refer to the following lines:
> 1) len(list) 
> 2) list.append()
>
> In the first case, len is a function that python provides to which list can be passed and in the second case, append is a method within list class?
>
> If my interpretation is correct, why not make len also as a part of list class itself?

Yes, that's correct. For the reason, see
https://docs.python.org/3/faq/design.html#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it  |                 -- Fortunato Depero, 1929.




More information about the Python-list mailing list