I am new to python.I have been learning class and object.Can you guys please explain me why the objects that are being created inside function have same ids and the objects created outside the function have different ids.
I have created an empty class Node. I have used 'check()' function to create object and to finds its ids.
class Node:
pass
def check():
obj = Node()
print(id(obj))
check()
check()
OUTPUT:
1983605942928
1983605942928
'Here the ids returned are same '
and in the below code i have created objects outside the class but have different ids.
class Node:
pass
obj1 = Node()
obj2 =Node()
print(id(obj1),id(obj2))
OUTPUT:
2059740686992
2059740898976