print "NUCLEAR CORE UNSTABLE!!!, Quarantine is in effect. , Surrounding hamlets will be evacuated. , Anti-radiationsuits and iodine pills are mandatory."
繁花如伊
浏览 153回答 2
2回答
一只甜甜圈
您使用的是print 语句,而不是函数,并且有几种方法可以做到:这使用三引号字符串来保留换行符:def printit(): print """NUCLEAR CORE UNSTABLE!!!Quarantine is in effect.Surrounding hamlets will be evacuated.Anti-radiationsuits and iodine pills are mandatory. """只需运行 3 次:for i in range(3): printit()这使用了多个print语句:def printit(): print "NUCLEAR CORE UNSTABLE!!!" print "Quarantine is in effect." print "Surrounding hamlets will be evacuated." print "Anti-radiationsuits and iodine pills are mandatory.\n"这仅使用嵌入换行符的一行:def printit(): print "NUCLEAR CORE UNSTABLE!!!\nQuarantine is in effect.\nSurrounding hamlets will be evacuated.\nAnti-radiationsuits and iodine pills are mandatory.\n"但是,您提到了print 函数并抱怨逗号分隔符没有做任何事情,所以:from __future__ import print_functiondef printit(): print ("NUCLEAR CORE UNSTABLE!!!", "Quarantine is in effect.", "Surrounding hamlets will be evacuated.", "Anti-radiationsuits and iodine pills are mandatory.\n", sep="\n")个人比较喜欢这个。您可以将所有内容放在一行中,但这会使代码难以阅读和维护。