python len() 与 __sizeof__()区别

 len():容器中项目数量

Return the length (the number of items) of an object. The argument may be a sequence (string, tuple or list) or a mapping (dictionary).

 

__sizeof__():返回对象的内存大小。 比len()多了一个垃圾收集器开销

 Return the size of an object in bytes. The object can be any type of object. All built-in objects will return correct results, but this does not have to hold true for third-party extensions as it is implementation specific.

 getsizeof() calls the object’s __sizeof__ method and adds an additional garbage collector overhead if the object is managed by the garbage collector.

 

posted @ 2021-05-26 15:03  小毛编  阅读(1421)  评论(0编辑  收藏  举报