How to print a linebreak in a python function?

前端 未结 8 761
旧时难觅i
旧时难觅i 2020-12-07 14:19

I have a list of strings in my code;

A = [\'a1\', \'a2\', \'a3\' ...]
B = [\'b1\', \'b2\', \'b3\' ...]

and I want to print them separated b

相关标签:
8条回答
  • 2020-12-07 14:31

    The newline character is actually '\n'.

    0 讨论(0)
  • 2020-12-07 14:31

    You can print a native linebreak using the standard os library

    import os
    with open('test.txt','w') as f:
        f.write(os.linesep)
    
    0 讨论(0)
  • 2020-12-07 14:39

    \n is an escape sequence, denoted by the backslash. A normal forward slash, such as /n will not do the job. In your code you are using /n instead of \n.

    0 讨论(0)
  • 2020-12-07 14:42

    Also if you're making it a console program, you can do: print(" ") and continue your program. I've found it the easiest way to separate my text.

    0 讨论(0)
  • 2020-12-07 14:43

    You have your slash backwards, it should be "\n"

    0 讨论(0)
  • 2020-12-07 14:46

    All three way you can use for newline character :

    '\n'
    
    "\n"
    
    """\n"""
    
    0 讨论(0)
提交回复
热议问题