Python如何查看变量占用空间大小,python变量占用空间,在c语言中提供了size
Python如何查看变量占用空间大小,python变量占用空间,在c语言中提供了size
在c语言中提供了sizeof可以用来查看一个变量占用的空间大小,在python中可以使用sys模块下的getsizeof
方法来判断变量占用的空间大小。
其文档解释如下:
sys.getsizeof(object[, default]):
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.
The default argument allows to define a value which will be returned if the object type does not provide means to retrieve the size and would cause a TypeError.
getsizeof calls the object’s sizeof method and adds an additional garbage collector overhead if the object is managed by the garbage collector.
使用示例:
import sysv = 1print sys.getsizeof(v)s = 'abc'print sys.getsizeof(s)
相关内容
- error: 2006 MySQL server has gone away 解决方法,mysqlgone,今天在
- python使用正则表达式验证Email地址,pythonemail,下面的代
- 使用socket模块验证ip地址,socket模块验证ip,如下代码:
- python验证IP地址方法,python验证ip,可以使用socket模块
- python mutiprocessing 入门示例,,multiprocess
- Python 的多进程 fork,python进程fork,using_fork.p
- Python 多进程实现分析,python进程实现,Python Stand
- Python连接使用redis,python连接redis,需要下载 redis-p
- 使用python获得网站的alexa排名,pythonalexa,如下脚本,使
- python获得Google PageRank(PR)的脚本,pythonpagerank,如下p
评论关闭