This question is rather "conceptual" than a specific programming one.
If you ask the type of this object in Python:
[4,3,2,1]
Python will tell you it is a list, as can be seen by doing:
type([4,2,3])
Out[12]: list
In general, the brackets seem to have this effect on a group of objects, whenever you surround them with brackets, they become a list.
Now consider a pandas dataframe. It is known that to get to know the names of the columns you should do, for instance:
list(iris)
Out[13]: ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']
Which will give you the columns names as a list.
Now if I try:
[iris]
Python returns the whole iris dataframe.
Why is that? Why sometimes the brackets behave as if creating a list out of a group of objects and sometimes not (as in the second case of this example)?
I tried searching Python foruns for this question but was unable to find an answer that I could either understand or be satisfied with.
Best regards,
Gustavo,