This might seem like a trivial question, but it seemed non-intuitive to me that list(range(5))
would print the contents of the list: [0,1,2,3,4]
. I was thinking that range(5)
would suffice. Is there a reason for this?
Is this merely because the function definition of list()
prints out the contents while converting any non-list arguments (such as a range)?
P.S. As my intent is to print contents of a list I'm aware there are other methods. Having to use list()
was just a bit of a surprise so I thought to ask.