How to print list items which contain new line?

后端 未结 4 712
感动是毒
感动是毒 2021-01-29 12:07

These commands:

l = [\"1\\n2\"]    
print(l)

print

[\'1\\n2\']

I want to print

[\'1
2\']
         


        
4条回答
  •  [愿得一人]
    2021-01-29 12:15

    You should probably use this, if you have more than one element

    >>> test = ['1\n2', '3', '4\n5']
    >>> print '[{0}]'.format(','.join(test))
    [1
    2,3,4
    5]
    

提交回复
热议问题