I am trying to establish the difference between these two methods of creating variables in a class and which method is correct?
class example():
var = 12
class example2():
def __init__(self):
self.var = 34
ob1 = example()
ob2 = example2()
print (ob1.var)
print (ob2.var)
This returns the contents of the variables as expected:
12
34
>>>
I have searched stackoverflow to see if there is anything on this and couldn't find anything that compared the two, I find its always easier to search when you know the answer.
Thank you