On this page
sys.getsizeof
Prev: sys.getrefcount | Up: sys | Next: sys.getswitchinterval
Rel: sys.activate_stack_trampoline, sys.addaudithook, sys.audit, sys.breakpointhook
Ref: docs.python.org — sys.getsizeof
Tags: #public #python3 #stdlib #sys
Import
import sys
from sys import getsizeof
Signature & Overview
sys.getsizeof(object [, default]) -> int
Return the size of object in bytes.
Usage
import sys
assert sys.getsizeof([]) > 0
assert sys.getsizeof([1, 2, 3]) > sys.getsizeof([])
Gotchas
- Shallow size only:
sys.getsizeof(my_list)measures the list pointer array, not the objects stored inside it.
REPL Inspect
from sys import getsizeof
help(getsizeof)
Linked from
Related notes
- tuts/python3/stdlib_module/sys/getrefcount Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/getswitchinterval Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sys/activate_stack_trampoline Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/addaudithook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/audit Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/breakpointhook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/call_tracing shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/deactivate_stack_trampoline shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/displayhook shared tags: #stdlib, #sys