What is Name in python?

1.0K    Asked by SakshiD’souza in Data Science , Asked on Dec 19, 2019
Answered by Nitin Solanki

Name is simply an identity given to objects, you can also call it as an identifier. In python, everything is an object and the name is using to identify that object or can say the name is a way to access the object.

For example, when we declare any variable a = 20, here 20 is an object stored in memory and a is the name associated with object ‘20’. This name has some address in RAM that we can get by using built-in-function, id( ). See below code

#Declare a variable

a = 20

id(20)

Out[3]: 140736574428576

id(a)

Out[4]: 140736574428576

Now see below example, a little bit twisted

#Declare a variable

a = 20

id(20)

Out[4]: 140736574428576

a = a+10

id(a)

Out[8]: 140736574428896

id(30)

Out[9]: 140736574428896

Now you can see id(a) is different than id (20), why? Because later in code we have assigned new object a+1 to a, which is changing identifier an id in RAM. Now if you assign a new identifier to object ‘20’ then see what its id will be.



Your Answer

Interviews

Parent Categories