One can can implement the method __str__(self)
to return a string. Is there an __list__(self)
counterpart? (__list__
doesn't work!)
Is .toList() the way to go?
To list the methods for this class, one approach is to use the dir() function in Python. The dir() function will return all functions and properties of the class.
We can create list of object in Python by appending class instances to list. By this, every index in the list can point to instance attributes and methods of the class and can access them. If you observe it closely, a list of objects behaves like an array of structures in C.
Creating lists in Python can take place by just placing the sequence inside the square brackets[].
There is no direct counterpart, but list()
is implemented by iterating over the argument. So implement either the iterator protocol (__iter__()
) or bound indexing (__len__()
and __getitem__()
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With