Guide to String Interning in Python

python_tutorials

Introduction

One of the first things you encounter while learning the basics of programming is the concept of strings. Similar to various programming languages, Python strings are arrays of bytes representing Unicode characters – an array or sequence of characters. Python, unlike many programming languages, doesn’t have a distinct character datatype, and characters are considered strings of length 1.

You can define a string using single or double quotation marks, for example, a = "Hello World" or a = 'Hello World'. To access a specific element of a string, you would use square brackets ([]) with the index of the character you wish to access (indexing starts at 0). Calling a[0], for example, would return H.

That being said, let’s take a look at this code example:

a = 'Hello World'
b = 'Hello World'
c = 'Hello Worl'

print(a is b)
print(a == b)
print(a is

To finish reading, please visit source site