assign output of print to a variable in python

前端 未结 6 1457
心在旅途
心在旅途 2021-01-15 01:41

i want to know how to assign the output of print to a variable.

so if

mystring = \"a=\\\'12\\\'\"

then

print mys         


        
6条回答
  •  长发绾君心
    2021-01-15 02:15

    You can call __str__ and __repr__ on python objects to get their string representations (there's a tiny difference between them, so consult the docs). That's actually done by print internally.

提交回复
热议问题