How to access the variables of the outer class in the Inner Class?
Asked
Active
Viewed 40 times
0
-
Does this answer your question? [How to access outer class from an inner class?](https://stackoverflow.com/questions/2024566/how-to-access-outer-class-from-an-inner-class) – DYZ Sep 04 '21 at 05:13
-
Please provide enough code so others can better understand or reproduce the problem. – Community Sep 08 '21 at 12:23
1 Answers
-1
class Student:
def __init__(self,Name,rollNumber):
self.Name=Name
self.rollNumber=rollNumber
self.lap=self.Laptop()
def Show(self):
print(self.Name)
print(self.lap.show())
class Laptop:
def __init__(self):
self.brand = "Mac"
self.cpu = "i9"
self.ram = 16
def show(self):
return self.brand
@staticmethod
def Show():
return s1.Name
s1=Student("Teja",2)
print(s1.Name,s1.rollNumber)
s1.Show()
print(s1.lap.brand)
system=s1.lap
print(system.brand)
print(system.cpu)
print(system.show())
print(system.Show())

Teja Ambati
- 1
- 1
- 1
-
The original poster wants to know how to access the outer class variables from *within* the inner class. What you've posted is how to access the *inner* class variables via the outer class. – Lance Kind Sep 04 '21 at 10:13
-
Please provide additional details in your answer. As it's currently written, it's hard to understand your solution. – Community Sep 04 '21 at 10:13