Answer is A.
The instruction object_1.Variable += 1 creates a new attribute to object_1 and it does not modify class variable 'Variable': object_1.__dict__ ==> {'value':0, 'variable':1}
Since class variable 'Variable' is still 0, object2.variable will be 0, then:
object_2.Variable (0) + object_1.value (1) = 0 + 1 = 1
AttributeError Traceback (most recent call last)
Cell In[15], line 10
8 object_1.Variable += 1
9 object_2 = Class()
---> 10 object_2.value += 1
12 print(object_2.Variable + object_1.value)
AttributeError: 'Class' object has no attribute 'value'
This is what i am getting
'Variable' is a class variable to begin with.
But then, obejct_1.Variable is created and assigned a value of 1. Obejct_2.Variable, which is also an instance variable, has had no value assigned to it.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
skullomania
1 year, 1 month agobrandonkim76
1 year, 3 months agoSaadThayab
1 year, 8 months agocufta05
1 year, 5 months agomoteruky
8 months, 2 weeks agosudhanshu1
1 year, 11 months agoMallie
1 year, 11 months agomacxsz
2 years, 6 months agoNoarmy315
2 years, 11 months ago