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 !!!

So Just imagine how much memory we spend every day!

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 !! 🚶

A. Integer data type

import sysa=int()print(a, ’needs’ ,sys.getsizeof(a), ’bytes’)OUTPUT0 needs 24 bytes
import sysa=1
b=1234
c=123456789
# 10 digits
d=1234567890
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 of digits printed individually for Whole or Fractional part will be 16
  2. First 17 digits starting from whole number part are chosen to be printed.
  3. There are some approximation rules applied which mostly affects the 16th digit in the fractional part.
  4. Float has 24 bytes and it dont change
import sys a = complex()
print(a,sys.getsizeof(a))
a = 123456789123456789+0j
print(a,sys.getsizeof(a))
a = 1+123456789123456789j
print(a,sys.getsizeof(a))
OUTPUT0j needs 32 bytes
(1.2345678912345678e+17+0j) needs 32 bytes (1+1.2345678912345678e+17j) needs 32 bytes
  1. 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’)
a=’1234'
print(a, ‘needs’ ,sys.getsizeof(a), ‘bytes’)
a=”aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”+”aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”
print(a, ‘needs’ ,sys.getsizeof(a), ‘bytes’)
OUTPUTneeds 53 bytes
1234 needs 53 bytes aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa needs 137 bytes
  1. Size of any one String object ‘a’ is 50 bytes. Its 3 bytes less than the Empty String space!
  2. 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