Inner Class to Access Outer Class Variables Python - 1 || Inner Class || Python
In this we are going to see a basic example of inner class to access outer class variables - 2 in Python Programming Language.



class Outer:
    def __init__(self):
        self._var1 = 221
        self._string1 = "This is the Outer Class"

    def show(self):
        self.i1 = self.Inner()
        self.i1.show()

    def function(self):
        print("Hello from the function() of Outer Class")
        print("str : ", self._string1)

    class Inner:
        def __init__(self):
            self.__inside_str= "This is the Inner Class"
            self.outer = Outer()

        def show(self):
            print("value of __inside_str : ", self.__inside_str)
            print("Inside show function of the Inner Class")
            print("value of _var1: ", self.outer._var1)
            print("value of _string1: ", self.outer._string1)
            self.outer.function()
            
obj = Outer()
obj.show()

# Coded By Dhiraj Shelke


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post