Use repr
. It returns a string containing a printable representation of an object. (similar to Object#inspect
in Ruby)
>>> repr([1,"string", ':symbol', ['l', 'i', 's', 't']])
"[1, 'string', ':symbol', ['l', 'i', 's', 't']]"
BTW, there's no symbol literal (:symbol
) or single character string literal (?x
) in Python; replaced them with string literals in the above example.