The below code works fine where I'm creating objects for Outer and inner classes individually and passing the arguments
class Student:
def __init__(self,name,rollno):
self.name = name
self.rollno = rollno
def show(self):
print(self.name,self.rollno)
#self.lap.show()
class Laptop: #inner class
def __init__(self,brand,cpu'):
self.brand = brand
self.cpu = cpu
def show(self):
print(self.brand,self.cpu)
s1 = Student('Ram',21)
lap1 =s1.Laptop('Dell','i3')
lap1.show()
In the second code, I have created the inner class(Laptop) object inside the Outer(Student) class. In that case, how can we pass the arguments to the inner class?
class Student:
def __init__(self,name,rollno):
self.name = name
self.rollno = rollno
self.lap = self.Laptop() #lap is the obj of a inner class
def show(self):
print(self.name,self.rollno)
self.lap.show()
I tried with self.lap = self.Laptop(brand,cpu), assigning parameters and passing the arguments in differnet ways, but none worked for me. Is there any way where I can pass the arguments?