[Old Version]Variables Memory Allocation and Interning || Lesson 1 || Python || Learning Monkey ||

Published: 09 August 2020
on channel: Wisdomers - Computer Science and Engineering
6,896
151

Hello Wisdomers, this course is the old version. The teacher you trust has made a brand new, even better version for you. For Complete Playlist Click here to watch it.
   • Python For Beginners  
#learningmonkey#pythoncoding#placements#pythontutorials#pythoncourse#pythonforbeginners#pythonfordatascience#pythonfullcourse#pythonprogramming#pythonfreecourse
Variable: is a container for storing data.

Example: x=5

x is a variable holding the data value five.

y=2.8

z=”Mahesh”

First, understand how memory is allocated.

The image for memory is provided below.

From the image, each address line is considered a memory location.

Assume x taken a value of 10, and y is taken a value of 10.

First, we understand how memory is allocated to variables in c language and in java language.

In the c and java language x and y are both having the same value, ie value 10.

x is given a separate memory location let’s say memory location 2. means x is referencing memory location 2.

y is given a separate memory location let’s say memory location 5. means y is referencing memory location 5.

But this is not the case in python. Python uses the concept of interning.

The interning technique is applicable only to few data. ie from -5 to 256 in integers, and simple strings.

Let's take the above example and understand the concept of interning.

x=10 and y =10

Both having the same value so place value 10 in a memory location and both the variables refer to the same memory location.

Take one more example in strings. x = “hello” and y = “hello”

Here both the values are the same so why use a separate space. save hello in a memory location let’s say in the 10th location and both variables refer to the same location.

As this is our first class we are talking in terms of a memory location. But in reality, both variables refer to the same object.

In this situation, we don’t know what’s object is, so we are talking in terms of memory. we get clarity in our next classes where we discuss class and object.

Let’s understand one more example to have a deeper understanding of the interning concept.

x=10 and y = 10.

Both having the same value, so it is given the same memory. assume it is given location 2.

id(x) and id(y) give us the memory address of variables x and y. both giving the same location.

Let’s take x=x+1. Now the value of x changes to 11.

At this stage both having different values. They are given different locations.

Now take a variable z=10. We already had a value of y=10. so z is assigned to the same memory location y is referring to.

Next, take one more example x= 257 and y= 257. these values are above the limit mentioned above in interning.

The variables x and y are assigned a different memory location. ie only to those values in the above limit interning works.

Take the example in strings also. x = “hello world” and y =” hello world”.

These are not simple strings. so these variables are assigned with different locations.

We can forcefully apply the concept of interning by using the function called an intern.

x=sys.intern(“hello world”)

y=sys.intern(“hello world”)

In the above example, both the variables are assigned the same memory location.

Why they are using the interning concept in the above-mentioned limit. because these values are used frequently. In order to save memory and increase speed.

Example to understand the use of interns.

Take the amazon mobile data set. In this data set, we are having lots of sentences. suppose if someone asks you to identify the time the word mobile occurs in the entire data set?

What we do. we split the words and find how many times the word mobile occurs in the data set. if we save the word mobile in one location and give reference we are saving so much memory.

This is how interning is helping in improving memory usage and for fast execution.


Link For Installation Video:    • Installing Python and Anaconda in Windows ...  



Link for playlists:
   / @wisdomerscse  


Link for our website: https://learningmonkey.in

Follow us on Facebook @   / learningmonkey  

Follow us on Instagram @   / learningmonkey1  

Follow us on Twitter @   / _learningmonkey  

Mail us @ learningmonkey01@gmail.com


On this page of the site you can watch the video online [Old Version]Variables Memory Allocation and Interning || Lesson 1 || Python || Learning Monkey || with a duration of hours minute second in good quality, which was uploaded by the user Wisdomers - Computer Science and Engineering 09 August 2020, share the link with friends and acquaintances, this video has already been watched 6,896 times on youtube and it was liked by 151 viewers. Enjoy your viewing!