Sitemap
Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Follow publication

Member-only story

How variables are saved in Python and Rust. Side by Side 4: str/string

8 min readNov 15, 2021

--

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 str/string 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

`str` data type in Python

Because of the history of Python, it wasn’t designed to use Unicode to represent the string. Instead, Python uses bytes. It works well if we only process the ASCII chars. But later, bytes couldn’t represent all strings, Python needed to add Unicode support. That’s why we could see str data…

--

--

Marshal SHI
Marshal SHI

Written by Marshal SHI

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