Python - Join with newline

后端 未结 5 1168
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:59

    You have to print it:

    In [22]: "\n".join(['I', 'would', 'expect', 'multiple', 'lines'])
    Out[22]: 'I\nwould\nexpect\nmultiple\nlines'
    
    In [23]: print "\n".join(['I', 'would', 'expect', 'multiple', 'lines'])
    I
    would
    expect
    multiple
    lines
    

提交回复
热议问题