fork download
  1. import sys
  2.  
  3. print("Python Data Types and Memory Usage:")
  4.  
  5. x_int = 1
  6. x_float = 1.0
  7. x_str = "A"
  8. x_bool = True
  9. x_complex = 2 + 3j
  10.  
  11. print("int: size =", sys.getsizeof(x_int), "bytes")
  12. print("float: size =", sys.getsizeof(x_float), "bytes")
  13. print("str (1 char): size =", sys.getsizeof(x_str), "bytes")
  14. print("bool: size =", sys.getsizeof(x_bool), "bytes")
  15. print("complex: size =", sys.getsizeof(x_complex), "bytes")
  16.  
Success #stdin #stdout 0.03s 9128KB
stdin
Standard input is empty
stdout
Python Data Types and Memory Usage:
int: size = 28 bytes
float: size = 24 bytes
str (1 char): size = 50 bytes
bool: size = 28 bytes
complex: size = 32 bytes