Sep-22-2020, 11:51 PM
Literal does not have to do with the type of thing, it has to do with the representation of the thing. This is a literal list:
[1, 2, 3, 4]If I type:
x = [1, 2, 3, 4]I have a list which is stored in x, but that list is not the literal [1, 2, 3, 4]. Instead it is a list that was constructed from the literal list. I don't think the literal list exists at all. The literal list is only code that tells Python to create a list. If there was such a thing as a "literal list" python object, the list in x should be the same as [1, 2, 3, 4], but you can see by looking at the Python object ID that they are not.
x = [1, 2, 3, 4] print(x, id(x)) print([1, 2, 3, 4], id([1, 2, 3, 4]))
Output:[1, 2, 3, 4] 1635969131264
[1, 2, 3, 4] 1635938109504
Notice that the list referenced by "x" is not the same list that is created by the literal list. It is quite possible (likely) that the two literal lists in the second print command created two different Python objects.