How to print a linebreak in a python function?
I have a list of strings in my code;
A = ['a1', 'a2', 'a3' ...]
B = ['b1', 'b2', 'b3' ...]
and I want to print them separated by a linebreak, like this:
>a1
b1
>a2
b2
>a3
b3
I've tried:
print '>' + A + '/n' + B
But /n isn't recognized like a line break.
Solution 1:
You have your slash backwards, it should be "\n"
Solution 2:
The newline character is actually '\n'
.
Solution 3:
>>> A = ['a1', 'a2', 'a3']
>>> B = ['b1', 'b2', 'b3']
>>> for x in A:
for i in B:
print ">" + x + "\n" + i
Outputs:
>a1
b1
>a1
b2
>a1
b3
>a2
b1
>a2
b2
>a2
b3
>a3
b1
>a3
b2
>a3
b3
Notice that you are using /n
which is not correct!
Solution 4:
All three way you can use for newline character :
'\n'
"\n"
"""\n"""
Solution 5:
for pair in zip(A, B):
print ">"+'\n'.join(pair)