- 1
Print function
Print A B C D in a list format. When adding \n to create the list. It is creating another line underneath which is blank but coming back as an error. Can anyone help with this?
5 Answers
+ 5
Thomas , your code just prints A B C D, each in a separate line. Not clear what problem you have.
+ 1
where is your code ?
+ 1
a = 'A \nB \nC \nD'
print(a)
+ 1
1. print(['A',"B',"C','D'])
2. x ='ABCD'
z=list(x)
print(z)
3.for i in x:
print(i)
4.print(f"listformat({x})")#this is joke one
0
# Thomas
#is this what you want ??
x="A\nB\nC\nD"
print([i for i in x if not i == "\n"])
#output : [ 'A', 'B', 'C', 'D' ]