0

I tried to use \n but it gives back an error. Am I using it wrong?

list1 = [1, 2, 3]
list2 = [4, 5, 6]
list3 = list1 + list2
list4 = [list1 + list2]
print(list3, list4)

The result should be:

[1, 2, 3, 4, 5, 6]
[[1, 2, 3, 4, 5, 6]]
Guerrero
  • 17
  • 6

4 Answers4

2

You may reach your answer by formatting the string.

list1 = [1, 2, 3]
list2 = [4, 5, 6]
list3 = list1 + list2
list4 = [list1 + list2]
print(f'{list3}\n{list4}')

Output:

[1, 2, 3, 4, 5, 6] 
[[1, 2, 3, 4, 5, 6]]

Have Fun :)

Saeed
  • 3,255
  • 4
  • 17
  • 36
1

You can do this by using 'sep':

list1 = [1, 2, 3]
list2 = [4, 5, 6]
list3 = list1 + list2
list4 = [list1 + list2]
print(list3, list4,sep='\n')

Output:

[1, 2, 3, 4, 5, 6]
[[1, 2, 3, 4, 5, 6]]
0

You need to put the arguments like this in print :

print(list3,'\n', list4)

And the output will be :

[1, 2, 3, 4, 5, 6] 
[[1, 2, 3, 4, 5, 6]]

Or

print(list3)
print(list4)
F Blanchet
  • 1,430
  • 3
  • 21
  • 32
0

Not the cleanest solution but you can do the following:

print(list3,'\n'+str(list4))
KetZoomer
  • 2,701
  • 3
  • 15
  • 43