+ 2
How many bytes are used for numeric variables in Python?
For example, in this code: https://code.sololearn.com/cAusnEKMKgaK/?ref=app
1 Respuesta
+ 3
You can use sizeof operator to find it out.
You can either import getsizeof method from the sys module:
from sys import getsizeof
print(getsizeof(20))
#Prints the sizeof the integer 20.
Objects should also have a magicmethod, might be discouraged from using, but works:
print((20).__sizeof__())
Remember that you would sometimes need parentheses, for example 20.__sizeof__() would result in errors, with variables this doesn't cause problems:
a = 20
print(a.__sizeof__())