Emojis are too heavy !!

help(sys.getsizeof)OUTPUTHelp on built-in function getsizeof in module sys:getsizeof(…) getsizeof(object, default) -> int Return the size of object in bytes.
import sys sys.getsizeof(😂)OUTPUT80

One emoji is of 80 bytes !!!

Dont worry, We have a solution to decrease the memory usage and increase the benefit 😃

import sysa = '😂'
b = '😂🤔'
c = '😂🤔😶'
print(sys.getsizeof(a),sys.getsizeof(b),sys.getsizeof(c))OUTPUT80 84 88

🚶Come, Lets find how our python brain feels about the basic data types !! 🚶

import sysa=int()print(a, ’needs’ ,sys.getsizeof(a), ’bytes’)OUTPUT0 needs 24 bytes
import sysa=1
# 10 digits
print(a,'needs' ,sys.getsizeof(a),'bytes')
print(b,'needs' ,sys.getsizeof(b),'bytes')
print(c,'needs' ,sys.getsizeof(c),'bytes')
print(d,'needs' ,sys.getsizeof(d),'bytes')
OUTPUT1 needs 28 bytes
1234 needs 28 bytes
123456789 needs 28 bytes
1234567890 needs 32 bytes
import sysa = float()
b = int()
print(a, ’needs’ ,sys.getsizeof(a), ’bytes’)
print(b, ’needs’ ,sys.getsizeof(b), ’bytes’)
OUTPUT0.0 needs 24 bytes
0 needs 24 bytes
import sys# Whole number: 18 digits, Fractional number : 4 digits
a = 123456789123456789.1234
print(a, ’needs’ ,sys.getsizeof(a), ’bytes’)
# Whole number: 16 digits, Fractional number : 3 digits
b = 1234567891234567.234
print(b, ’needs’ ,sys.getsizeof(b), ’bytes’)

c = float(12345678912345678)
print(c, ’needs’ ,sys.getsizeof(c), ’bytes’)
OUTPUT1.2345678912345678e+17 needs 24 bytes
1234567891234567.2 needs 24 bytes
1.2345678912345678e+16 needs 24 bytes
  1. Maximum number digits printed including Whole and Fractional part will be 17
  2. Maximum number of digits printed individually for Whole or Fractional part will be 16
  3. First 17 digits starting from whole number part are chosen to be printed.
  4. There are some approximation rules applied which mostly affects the 16th digit in the fractional part.
  5. Float has 24 bytes and it dont change
import sys a = complex()
a = 123456789123456789+0j
a = 1+123456789123456789j
OUTPUT0j needs 32 bytes
(1.2345678912345678e+17+0j) needs 32 bytes (1+1.2345678912345678e+17j) needs 32 bytes
  1. Complex default value is 0+0j and its permanent size is 32 bytes
  2. Complex number will follow the same 17 digit float value rule if there are enough digits.
import sysa=str()
print(a, ‘needs’ ,sys.getsizeof(a), ‘bytes’)
print(a, ‘needs’ ,sys.getsizeof(a), ‘bytes’)
print(a, ‘needs’ ,sys.getsizeof(a), ‘bytes’)
OUTPUTneeds 53 bytes
1234 needs 53 bytes aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa needs 137 bytes
  1. String default value is Empty String and its size is 53 bytes
  2. Size of any one String object ‘a’ is 50 bytes. Its 3 bytes less than the Empty String space!
  3. With every new character 1 byte is added and in this way Empty String space equals to memory size of 4 character strings !!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store