Python - Join with newline

后端 未结 5 1170
Happy的楠姐
Happy的楠姐 2020-12-13 03:17

In the Python console, when I type:

>>> \"\\n\".join([\'I\', \'would\', \'expect\', \'multiple\', \'lines\'])

Gives:



        
5条回答
  •  醉梦人生
    2020-12-13 03:55

    The console is printing the representation, not the string itself.

    If you prefix with print, you'll get what you expect.

    See this question for details about the difference between a string and the string's representation. Super-simplified, the representation is what you'd type in source code to get that string.

提交回复
热议问题