I want to know how len() works.
Does it count from beginning to end of a list every time I call len(), or, since list is also an class, does len() just return a variable in the list object which record the list's length?
Also, I hope someone can tell me where I can find the source code of those built-in functions like 'len()', 'map()', etc.
Well, you can find the documentation of the built-in functions here.
The list
data-type keeps track of the number of elements it's holding, len(list)
is an O(1) operation.
For the source code, you can find the source code of Python at the download page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With