Python - Join with newline

后端 未结 5 1178
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 04:06

    You need to print to get that output.
    You should do

    >>> x = "\n".join(['I', 'would', 'expect', 'multiple', 'lines'])
    >>> x                   # this is the value, returned by the join() function
    'I\nwould\nexpect\nmultiple\nlines'
    >>> print x    # this prints your string (the type of output you want)
    I
    would
    expect
    multiple
    lines
    

提交回复
热议问题