In Python, we have same pool for similar values, even if they share different variables. This has many advantages, that it saves a lot of memory arranging different spaces for similar values. This is provided for small integers. But there are ways in which we can have same and different pool values. Lets discuss certain cases of the same.
Case #1 : Same pool ( Using + operator )
In this, when we create a String using “+” operator, we create a space that will point to similar space in memory.
The original string is : gfg Are values pointing to same pool ? : True
Case #2 : Different Pool ( Using
join() + ord() )
This is way in which we need to initialize string pointing to different value space in memory. This can be achieved using join() for joining ASCII values extracted using ord().
The original string is : abc Are values pointing to same pool ? : False
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.