class student : def __init__(self,name,rno) : self.name=name self.rno=rno self.Lap=self.Laptop def show(self) : print(self.name,self.rno) self.Lap.show() class Laptop: #inner class def __init__(self) : self.brand="hp" self.cpu="i5" self.ram=8 def show(self): print(self.brand,self.cpu,self.ram) s1=student("ravi",2) s2=student("kumar",3) s1.show()
ravi 2 Warning\Error Traceback (most recent call last): File "file.py", line 18, in <module> s1.show() File "file.py", line 8, in show self.Lap.show() #inner print TypeError: show() missing 1 required positional argument: 'self'
Laptop
class student : def __init__(self,name,rno) : self.name=name self.rno=rno self.Lap=self.Laptop() # <- note trailing parentheses
self
this
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)