In python, what does len(list) do?

后端 未结 4 1206
耶瑟儿~
耶瑟儿~ 2021-02-19 23:51

Does len(list) calculate the length of the list every time it is called, or does it return the value of the built-in counter?
I have a context where I need to c

4条回答
  •  不知归路
    2021-02-20 00:51

    len(list) returns the length of the list. Everytime you call it, it will return the length of the list as it currently is. You could set up a counter by taking the len of list initially and then adding 1 to the variable each time something is appended to the list.

提交回复
热议问题