Well, this is probably the weirdest behaviour I've come accross in Python. Consider the following code:
class wow:
var = 90
def __init__(self):
self.wow = 30
def great(self):
self.eme = 90
print('wow')
var = wow()
varss = wow()
varsss = wow()
print(id(var.great))
print(id(varss.great))
print(id(varsss.great))
print(var.great is varsss.great)
Output:
1861171310144
1861171310080
1861171310144
False
Why, everytime I create a new object from the same class, is there everytime a new function created , and why do the memory addresses of the first one and third one match, but not the second one (nor id(wow.great)
).
And why when I compare the two with the same memory addresses does it return false?
Also another question, a new object gets created from the wow class, do all the methods of the wow class actually get added to that object, or does the object kind of call the method from the class whenever its needed. I ask this question because I can't see the methods of the wow class when I do var.dict?
Also, when I create the three different instances, will each of those instances actually have its own functions, or will the functions be made availlable by the wow class and all instances can just access the same functions whenever they want so the functions don't need to be copied in memory 3 times?
Lastly, I'd like to know if this is actually the same case for C#, would each instance have its own functions (non static) or will there only be one of the functions that each instance can access?