How does str(list) work?
问题 Why does str(list) returns how we see list on the console? How does str(list) work? (any reference to the CPython code for str(list) )? >>> x = ['abc', 'def', 'ghi'] >>> str(x) "['abc', 'def', 'ghi']" To get the original list back from the str(list) I have to: >>> from ast import literal_eval >>> x = ['abc', 'def', 'ghi'] >>> str(x) "['abc', 'def', 'ghi']" >>> list(str(x)) ['[', "'", 'a', 'b', 'c', "'", ',', ' ', "'", 'd', 'e', 'f', "'", ',', ' ', "'", 'g', 'h', 'i', "'", ']'] >>> literal