Python print issue


#1

How can I use "print" linebreak?

I just write a Python file(compary.py) code as below:
ool_one = 17 < 328
bool_two = 100 == (1 * 50)
bool_three = 19 <= 19
bool_four = -22 >= -18
bool_five = 99 != (98+1)
print bool_one, bool_two, bool_three, bool_four, bool_five

when I running compary.py and get the result:
True False True False False

and now I need the result as below:
True
False
True
False
False

How can I do it? I tried using "print bool_one \n" and it's not correct.


#2

you could use separate print statements. The , is what causes them to be printed on a single line

or you could use +:

hello="hello"
print hello + "\nworld"

or even better, use format


#3

Hello Steim94, it doesn't work, now I have fixed:

print bool_one,"\n",bool_two,"\n",bool_three,"\n",bool_four,"\n",bool_five
True
False
True
False

Thanks!


#4

the output is now on separate lines, what is the problem?


#5

It's syntax error, the right is:
print bool_one,"\n",bool_two,"\n",bool_three,"\n",bool_four,"\n",bool_five

Thank you.


#6

\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.
The newline character is '\n'.
Learn Python here: https://hackr.io/tutorials/learn-python

I hope it helps...


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.