How variables are saved in Python and Rust. Side by Side 2: int / long

Series article to show how variables work in Python and Rust. Give us a better understanding of both languages. This is the 2nd article about int/long.

Marshal SHI
Geek Culture

--

Image by Author

Background

In this series of articles, I will show how variables work in Python and Rust side by side such that we could have a better understanding of both. In this article, we will check how int works in both.

In addition, I am not comparing which language is better. They all have their pros and cons. Also, please comment if there is anything that my understanding is wrong.

Environment

Python: version 3.9.7

Rust: 1.56.1

OS: 64bits Linux 5.12.19–1-MANJARO

Use CPython as the Interpreter of Python

`int` data type in Python

First, let’s do the same quick check to see the size of 1 value.

>>> x = 1
>>> sys.getsizeof(x)
28

Okay!!! The size is larger than float, which is 24 for 1.0, but the integer should be smaller than or equal to float?! (int32 is 4 bytes; long is 8

--

--

Marshal SHI
Geek Culture

Robots make our life easier | Robotics, Reinforcement Learning, Web, Python, Rust & Life Hacking. At MotivEdge.io