I am pasting my code below:-
class A: def __init__(self,i=100): self.i=100 class B(A): def __init__(self,j=0): self.j=j b=B() print(b.j) print(b.i)I have 2 class A and B . B is inheriting class A so according to the concept of inheritance base class acquires property of parent class so Instance variable i must be accessible to class B . But it is giving me an error that :
Error:Traceback (most recent call last):
File "D:/PYTHON/jljl.py", line 16, in <module>
print(b.i)
AttributeError: 'B' object has no attribute 'i'
Why this is giving error.
Larz60+ write Nov-12-2020, 01:42 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.