CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Follow publication

Member-only story

Go For Python Developers

Umangshrestha
CodeX
Published in
5 min readDec 2, 2021

--

We are continuing with check for Primitive data type in Python and Go. For other article in the series check the reference at the end of the article.

Integer

Integers are non-fractional numbers. They can be either signed or unsigned.

Size

In python, the byte size allocated to the integer is dynamic. Take the following example as a reference:

>>> import sys
>>> sys.getsizeof(0)
24
>>> sys.getsizeof(1)
28
>>> sys.getsizeof(1<<30))
32
>>> sys.getsizeof(1<<60)
36
>>>

In Python, int can hold integer of any size but it comes at a cost of memory. Python3 uses base 2 power 30. The size starts at 28 for non-zero values and increases by 4 bytes for an increase in base. Implementation is different for python2. Also, I took the values experimentally using python3 so take with a grain of salt.

python

Go follows the traditional approach. The user is the one deciding the size of the integer.

--

--

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Umangshrestha
Umangshrestha

Written by Umangshrestha

I like computer and programming. I am currently trying to learn how to write articles for sharing what I know.

No responses yet

Write a response