Python 2.6: Class inside a Class?

前端 未结 3 1748
小蘑菇
小蘑菇 2020-12-22 20:16

Hey everyone, my problem is that im trying to figure out how to get a class INSIDE another class.

What I am doing is I have a class for an Airplane with all its stat

3条回答
  •  独厮守ぢ
    2020-12-22 20:58

    class Second:
        def __init__(self, data):
            self.data = data
    
    class First:
        def SecondClass(self, data):
            return Second(data)
    
    FirstClass = First()
    SecondClass = FirstClass.SecondClass('now you see me')
    print SecondClass.data
    

提交回复
热议问题