In python, what does len(list) do?

后端 未结 4 1209
耶瑟儿~
耶瑟儿~ 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

    Help on built-in function len in module __builtin__:
    
    len(...)
        len(object) -> integer
    
        Return the number of items of a sequence or mapping.
    

    so yes, len(list) returns how many items in the list. You might want to describe in more details, providing necessary input files/output to help better understand what you want to do.

提交回复
热议问题