Hy vọng điều này là đủ rõ ràng: class myParent():
def __init__( self ):
self.parentNumber = 5
class Child( myParent ):
def __init__( self ):
self.childNumber = 4
def multiplyNumbers( self ):
print myParent.parentNumber * self.childNumber
p = Child()
p.multiplyNumbers()
Tôi muốn đặt ParentNumber riêng lẻ, và sau đó đạt được số đó thông qua lớp con và trong trường hợp này, hãy sử dụng nó để nhân. Tôi là người mới đến khu vực OOP nên bất kỳ gợi ý chung nào về thừa kế cũng được chào đón! Thông tin thêm: Tôi đang thiết kế một giải pháp quản lý dự án cho các dự án dựa trên VFX và đang chơi với các lớp học và kế thừa để xem họ có thể giúp tôi như thế nào. I'm designing a project management solution for vfx-based projects, and am playing with classes and inheritance to see how they can help me the most. Ngay bây giờ, tôi đã có một lớp hàng đầu, dự án và một lớp có nguồn gốc, bắn. Bắn có một biến tự.length với độ dài của ảnh chụp cụ thể. Nó cũng có một phương thức getLpminseconds () sử dụng self.length cùng với dự án.fps để xác định độ dài tính bằng giây. Project có một phương thức setFps () trong đó FPS được đặt sau một phiên bản của lớp được tạo. Tôi đã quen với các biến được đặt trước với bản thân. và đã không thử nghiệm nhiều với các lớp sử dụng các biến "toàn cầu" hơn mà không có bản thân. . Nếu tôi tạo ra mọi thứ toàn cầu, không có bản thân. Có lẽ có một cách tốt hơn, gọn gàng hơn,? Edit: Sau khi đọc, Super () có vẻ hơi nguy hiểm, và nhiều hơn tôi cần tôi nghĩ. Tôi chủ yếu có các lớp tự nhiên đơn và thậm chí không chắc chắn làm thế nào để sử dụng phân cấp kim cương .. Có cách nào an toàn hơn để truy cập các biến và phương thức siêu lớp không bao gồm Super () không? Edit: Được rồi, xem điều này có ý nghĩa hay nếu tôi nghĩ về nó sai. Tôi đang xem xét các lớp học và kế thừa như các nhóm và trẻ em. Một đứa trẻ biết đó là cha mẹ và tất cả các giá trị của nó. Một đứa trẻ với cha mẹ khác biết rằng cha mẹ coi trọng. Những gì tôi đang cố gắng thực hiện là có tất cả các bức ảnh được tạo ra là một phần của dự án. Và ngay bây giờ, tôi đang tạo các trường hợp shot () từ trong lớp Project (), thêm các phiên bản vào danh sách các bức ảnh được duy trì trong phiên bản dự án (). i.e. class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
Tôi có thể thấy các bước sai trong logic ở đây, nhưng không có cách nào thực sự xung quanh nó .. Có vẻ như mọi đứa trẻ đều nhận được một ví dụ mới của cha mẹ theo cách này, trong đó Parent_id luôn là một chuỗi trống. COE
COE
SHIVAM
SACHIN
3425
3624
COE
64class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
0 COE
COE
SHIVAM
SACHIN
3425
3624
COE
66Example: class Student:
stream ____10
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
1
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
4class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
6class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
9____10 COE
COE
SHIVAM
SACHIN
3425
3624
COE
1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5COE
COE
SHIVAM
SACHIN
3425
3624
COE
4____10 COE
COE
SHIVAM
SACHIN
3425
3624
COE
6COE
COE
SHIVAM
SACHIN
3425
3624
COE
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
0 COE
COE
SHIVAM
SACHIN
3425
3624
COE
9Rahul
886012
30000000
0Rahul
886012
30000000
1Rahul
886012
30000000
2Rahul
886012
30000000
3Rahul
886012
30000000
4class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
0 COE
COE
SHIVAM
SACHIN
3425
3624
COE
9Rahul
886012
30000000
7Rahul
886012
30000000
1Rahul
886012
30000000
9SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
0SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
2SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
4SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
6SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
8SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1This is in Outer class that is Vehicle
This is in Inner class that is Car
This is in multilevel InnerInner class that is Maruti
Just Print It!
0SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1This is in Outer class that is Vehicle
This is in Inner class that is Car
This is in multilevel InnerInner class that is Maruti
Just Print It!
2SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1This is in Outer class that is Vehicle
This is in Inner class that is Car
This is in multilevel InnerInner class that is Maruti
Just Print It!
4Output:
COE
COE
SHIVAM
SACHIN
3425
3624
COE
Lưu ý: Để biết thêm thông tin, hãy tham khảo các lớp và đối tượng Python. For more information, refer to Python Classes and Objects. Truy cập các chức năng của lớp chaKhi một lớp kế thừa từ một lớp khác, nó kế thừa các thuộc tính và phương thức của một lớp khác. Một lớp kế thừa từ một lớp khác được gọi là lớp con và lớp mà lớp con được thừa hưởng được gọi là lớp cha. Nhưng bạn đã bao giờ tự hỏi làm thế nào để truy cập các phương pháp lớp cha mẹ? Điều này thực sự đơn giản, bạn chỉ cần gọi hàm tạo của lớp cha trong hàm tạo của lớp con và sau đó đối tượng của lớp con có thể truy cập các phương thức và thuộc tính của lớp cha. Example: class
This is in Outer class that is Vehicle
This is in Inner class that is Car
This is in multilevel InnerInner class that is Maruti
Just Print It!
6This is in Outer class that is Vehicle
This is in Inner class that is Car
This is in multilevel InnerInner class that is Maruti
Just Print It!
7 This is in Outer class that is Vehicle
This is in Inner class that is Car
This is in multilevel InnerInner class that is Maruti
Just Print It!
8class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
4class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class 3class 4
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
9____10 COE
COE
SHIVAM
SACHIN
3425
3624
COE
1class 4
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5Student: 1____10 Student: 3class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 Student: 6class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5Student: 8class 4
SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1 1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5 3class 4
SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1 1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5 8class stream 0
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
4class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5stream 5class 4
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5stream 8____10 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
00class 4
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
02class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
04class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
07class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
09class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
10SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1 1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
14COE
COE
SHIVAM
SACHIN
3425
3624
COE
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
0 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
17class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
18Rahul
886012
30000000
1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
20Rahul
886012
30000000
1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
22223class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
24class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
25Output: Rahul
886012
30000000
Lưu ý: Để biết thêm thông tin, hãy tham khảo kế thừa trong Python. For more information, refer to Inheritance in Python. Truy cập phương thức lớp cha từ lớp bên trongMột lớp bên trong hoặc lớp lồng nhau là một lớp được xác định bên trong cơ thể của một lớp khác. Nếu một đối tượng được tạo bằng một lớp, đối tượng bên trong lớp gốc có thể được sử dụng. Một lớp có thể có một hoặc nhiều hơn một lớp bên trong. Các loại lớp bên trong: - Nhiều lớp bên trong
- Lớp nội địa đa cấp
Nhiều lớp bên trong: Một lớp chứa nhiều hơn một lớp bên trong. A class containing more than one inner class. Example: class
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
27
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
4class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
09class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1 1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
36SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
0class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
40class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
0class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
43class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
46class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
0class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
49 class
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
52class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
55class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
09class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
10SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1 1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
61SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
0 class
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
65class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
55class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
09class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
10SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1 1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
74SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
0 class
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
65class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
79class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
80Output: SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
76____10 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
78 In multilevel inner classes, the inner class contains another class which is inner classes to the previous one.
Example: Lớp bên trong đa cấp: Trong các lớp bên trong đa cấp, lớp bên trong chứa một lớp khác là các lớp bên trong của lớp trước.
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
4class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
09class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1 1class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
36SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
0 class
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
52class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
55class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
09class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1 1COE
COE
SHIVAM
SACHIN
3425
3624
COE
08SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
0 class
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
65class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
76____10 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
78Lớp bên trong đa cấp: Trong các lớp bên trong đa cấp, lớp bên trong chứa một lớp khác là các lớp bên trong của lớp trước. class
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
82class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
10SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1 1COE
COE
SHIVAM
SACHIN
3425
3624
COE
32SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
0class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
90____10 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
93class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
96____10 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
99
class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 COE
COE
SHIVAM
SACHIN
3425
3624
COE
02class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
09 class
COE
COE
SHIVAM
SACHIN
3425
3624
COE
12class 4
SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
1COE
COE
SHIVAM
SACHIN
3425
3624
COE
55class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
4class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
09COE
COE
SHIVAM
SACHIN
3425
3624
COE
59class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
10class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
96____10 class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5COE
COE
SHIVAM
SACHIN
3425
3624
COE
23COE
COE
SHIVAM
SACHIN
3425
3624
COE
63class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
7class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
3 COE
COE
SHIVAM
SACHIN
3425
3624
COE
02class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
5class myParent( object ):
def __init__( self ):
self.parent_id = ''
self.children = []
def createChild( self, name ):
self.children.append( myChild( name ) )
def getChildren( self ):
return self.children
def setParentId( self, id ):
self.parentId = id
class myChild( myParent ):
def __init__( self, id ):
super(myChild, self).__init__()
self.id = id
def getParentId( self ):
return self.parent_id
p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()
09COE
COE
SHIVAM
SACHIN
3425
3624
COE
67COE
COE
SHIVAM
SACHIN
3425
3624
COE
68SINGLA ELECTRONICS
DELL Inspiron 15
Redmi Note 5
0Output: This is in Outer class that is Vehicle
This is in Inner class that is Car
This is in multilevel InnerInner class that is Maruti
Just Print It!
__ cơ sở __ trong Python là gì?
Python cung cấp thuộc tính __base__ trên mỗi lớp có thể được sử dụng để có được danh sách các lớp mà lớp đã cho.Thuộc tính __base__ của lớp chứa một danh sách tất cả các lớp cơ sở mà lớp đã cho kế thừa.can be used to obtain a list of classes the given class inherits. The __bases__ property of the class contains a list of all the base classes that the given class inherits.
Super () hoạt động như thế nào trong Python?
Hàm Super () trong Python làm cho kế thừa lớp trở nên dễ quản lý và có thể mở rộng hơn.Hàm trả về một đối tượng tạm thời cho phép tham chiếu đến lớp cha bằng từ khóa Super.Hàm Super () có hai trường hợp sử dụng chính: để tránh việc sử dụng lớp siêu (cha mẹ) một cách rõ ràng.The function returns a temporary object that allows reference to a parent class by the keyword super. The super() function has two major use cases: To avoid the usage of the super (parent) class explicitly.
Một lớp cơ sở trong Python là gì?
Một lớp cơ sở trừu tượng là một lớp được sử dụng làm bản thiết kế cho các lớp khác.Các lớp cơ sở trừu tượng là một tính năng mạnh mẽ trong Python vì chúng giúp bạn xác định bản thiết kế cho các lớp khác có thể có điểm chung. |