I believe you have more than one problem on that question.
One is that you are focusing on print
's behaviour, which is very likely irrelevant to your issue.
Can you even access lst[0]
, never mind printing it? Simply assigning it to another variable? By focusing on print
you have the first distraction, and since the question revolves around that behaviour for an unknown entity (lst
), it starts derailing the question.
Then you have func()
, which is yet another distraction. Asking about "what does this code that you can't see does?" is not a recipe for success.
Finally, it seems you are doing very little to inspect and analyse lst
on your own. My Python is very rusty at the moment, but I remember that setting up an interactive debugger was fairly easy, and that one had at the very least access to type()
to inspect a variable type to begin with.
If you removed all the distractions from the question it would boil to something similar to:
With what type would be possible to iterate it over as an array but not to access its elements directly?
I have a variable lst
which I can iterate over like this:
for i in range(len(lst)):
print(lst[i])
which outputs:
['ABC', 'PQR']
But I can't access its elements directly.
Doing:
print lst[0]
throws and IndexError
error.
Attempting to print lst
itself produces:
[['ABC', 'PQR']]
What type or types could lst
be to exhibit this behaviour?
The question still crucially misses more attempts to introspect the variable (type()
, dir()
, or .__doc__
come to memory, but again I haven't really touched Python in some time).
I don't know if this would be well received by the Pythonic people. I would bet that at the very best it would be a dupe, and the lack of debugging efforts on your part would probably not be received very warmly.
But at least it would remove the focus from the "code beyond sight" problem.