überprüfen Kommentar in Code zur Erläuterung zur Verfügung gestellt:
class A:
#Constructor to Class A, args contain list of formal arguments and kwargs contains object (dict) of keyward arguments
#(4,5,None, test = "Hello", new = True) so args have [4,5,None] and kwargs have {"test":"Hello", "new" : True}
def __init__(self, *args, **kwargs):
self.l=[]
#self.b=self.l.append
def foo(self):
return 3
a=[]
#a is list and mutable data structure
b=A(a.append)
#a.append - append is method to list a to put values in list a like a.append(5), a.append(6) so list a is [5,6]. Here a.append provides info to memory location.
#b is a variable contains reference to object A at mem location X
c=A()
#c is a variable contains reference to object A at mem location Y
#b and c difference, Ideally both are reference to object A but located at diff locations and contains their own set of values/data.
b.foo()
print (b, c)
print (len(a))
Was? 'A .__ init__' tut nichts mit seinen Argumenten, also macht das Übergeben von' a.append' nichts. A wirft es einfach weg. – BrenBarn
es ist nicht einmal gut eingerückt, so Klasse A hat keine Init –