Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does printing an empty line do?

Tags:

python

I know this question may well be the silliest question you've heard today, but to me it is a big question at this stage of my programming learning.

Why is the second empty line needed in this Python code? What does that line do?

print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
like image 548
brilliant Avatar asked Apr 04 '10 19:04

brilliant


People also ask

What does an empty print statement do?

It prints an empty line, just as you have said. It will leave a blank line in the output. The print statement prints its arguments, and then a newline, so this prints just a newline.

What does empty print do in Python?

Using an empty print() function In Python, multiple uses of the print() function can display the output in different lines. See the following example. This is because the print() function has a parameter end , which is \n by default. The end parameter adds this character to the end of the output.

Which function prints a blank line?

Using Print() function with a newline character To Print Blank Line In Python.

What do you mean by blank line in Python?

The new line character in Python is \n . It is used to indicate the end of a line of text. You can print strings without adding a new line with end = <character> , which <character> is the character that will be used to separate the lines.


1 Answers

It prints an empty line, just as you have said. It will leave a blank line in the output. The print statement prints its arguments, and then a newline, so this prints just a newline.

You could accomplish the same thing with just:

print
like image 194
Ned Batchelder Avatar answered Sep 21 '22 00:09

Ned Batchelder