开发者

What does printing an empty line do?

I know this question may well be the silliest question you've heard today, but to me it is a bi开发者_JAVA技巧g 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!'


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


A blank line is required between the headers and the body in an HTTP response, so a CGI script will print a blank line at just that spot. There's no need for the quotes though, since an unadorned print will output a blank line.


Did you even tried to telnet web-server? It needs \n. So, it's what it does, you can write it in one line if needed.

print 'Content-Type: text/plain\n\nHello World'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜