Emojis are too heavy !!

Do you like emojis..yes you do and the same goes for everyone !

Every day we sent almost 10 billion emojis while chatting !

Come, lets peep inside python’s brain and find how it deals with emojis and other basic data!

World’s most popular emoji is 😂 and lets find its size

We may need some weapons like sys.getsizeof() to make this journey much easier

help(sys.getsizeof)

Now as our weapons are ready, lets find the size of 😂

import sys 

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 sys

Here one emoji takes 80 bytes and with every new emoji the size gets added up by 4 bytes!

One emoji needs 80 Bytes and 3 emojis need 88 Bytes !

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

A. Integer data type

import sys

Here we see python integer’s Default value is 0 and its Base Size is 24 bytes

As we saw in emoji here also we can save memory by increasing the number of digits

import sys

In Integer with every 10th digit 4 bytes are added to the base size.

B. Float data type

import sys

Here we see python float’s Default value is 0.0 and its Size is 24 bytes.

And 0.0 is equal to 0 thats why we have both the int and float default value sizes same.

import sys

5 points about Float value memory usage

  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

C. Complex data type

import sys 

2 points about Complex value memory usage

  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.

🤔In normal maths we used to denote complex numbers like 0 + 7i but here we are using j! Why ? (Find it!)

D. String data type

import sys

3 points about String value memory usage

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

Thats all !
Hope you liked the journey inside Python Brain !!
😃

Happy Learning !

--

--

Adventures-of-a-Programmer

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