+ 2

How many bytes are used for numeric variables in Python?

For example, in this code: https://code.sololearn.com/cAusnEKMKgaK/?ref=app

16th Feb 2020, 10:09 PM
Sonic
Sonic - avatar
1 Resposta
+ 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__())
17th Feb 2020, 5:48 AM
Seb TheS
Seb TheS - avatar