Sys.getsizeof ()
Import Sys
>>> sys.getsizeof ('3') ->>> sys.getsizeof (' +') the>>> sys.getsizeof ('325') +>>> sys.getsizeof (325) ->>> sys.getsizeof (1) ->>> sys.getsizeof (10000003250) ->>> sys.getsizeof (1000000000000000) ->>> sys.getsizeof (1000000000000000090) ->>> sys.getsizeof (10000000000000000900) $
You can see that the string is smaller than the shaping, and the shape takes up space within a certain range.
Contrast
import Timeitimport sysdef f (): A, B, C=3,2,1return sys.getsizeof (a* -+ b *Ten+c) def g (): A, B, C=3,2,1return sys.getsizeof (str (a)+ STR (b) +str (c)) def F2 (): A, B, C=3,2,1return a* -+ b *Ten+cdef G2 (): A, B, C=3,2,1return str (a)+ STR (b) +str (c) Print min (timeit.repeat (F2)) print min (timeit.repeat (G2)) print F () print g ()
Results
0.296730041504 0.70504784584 - +
It can be seen that f () is able to win the G () either from the speed or from the memory footprint
Python type size