我是Python初学者。我已经安装了 python34 和 xampp 1.8.0 并在 httpd.conf 中启用为 AddHandler cgi-script.cgi.pl.asp.py 从如下简单代码开始;
#!"C:\python34\python.exe"
import cgitb
cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print ('Hello World \n')
print ( 'new world' )
print ('\n')
if ( 6 > 5) :
print ("greater")
并在本地主机中执行此代码 http://localhost/cgi-bin/example.py
它的输出为
Hello World new world greater
单词之间没有换行符。我错过了什么? 输出我需要的
Hello world
new world
greater
最佳答案
对于 html 5 使用 print('<br>')
或print('<br />')
.
对于 xhtml 使用 print('<br />')
.
对于 html 4 使用 print('<br>')
.
关于python - 如何创建新行字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30237128/