[英]is there another way i can write this? i only know the print function,but i can not seem to get it like the example
i can not seem to get the same print function as the example i have used the basic print but it wont give me what i am looking for, also the commas don not seem to divide it 我似乎无法获得与我使用基本打印的示例相同的打印功能,但它不会给我我想要的东西,而且逗号似乎也没有分开它
python 2.7 python 2.7
print "NUCLEAR CORE UNSTABLE!!!, Quarantine is in effect. , Surrounding hamlets will be evacuated. , Anti-radiationsuits and iodine pills are mandatory."
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
print bcolors.WARNING + "Warning: No active frommets remain. Continue?"
+ bcolors.ENDC
This is a code snippet that I found online and works! 这是我在网上找到并且有效的代码片段!
print bcolors.WARNING + "NUCLEAR CORE UNSTABLE!!!" + bcolors.ENDC + '''\n Quarantine is in effect. \n
Surrounding hamlets will be evacuated. , Anti-radiationsuits and iodine pills are mandatory.'''
You can also use \\t to put in a tab space 您还可以使用\\ t来放置选项卡空间
You are using the print
statement , not function, and there are several ways to do it: 您正在使用
print
语句 ,而不是函数,有几种方法可以实现:
This uses a triple quoted string to preserve newlines: 这使用三引号字符串来保留换行符:
def printit():
print """NUCLEAR CORE UNSTABLE!!!
Quarantine is in effect.
Surrounding hamlets will be evacuated.
Anti-radiationsuits and iodine pills are mandatory.
"""
To run it 3 times just: 要运行3次:
for i in range(3):
printit()
This uses multiple print
statements: 这使用多个
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"
This uses just one line with embedded newlines: 这只使用一行嵌入的换行符:
def printit():
print "NUCLEAR CORE UNSTABLE!!!\nQuarantine is in effect.\nSurrounding hamlets will be evacuated.\nAnti-radiationsuits and iodine pills are mandatory.\n"
However, you mentioned print
function and complained about the comma separators not doing anything, so: 但是,你提到了
print
函数,并抱怨逗号分隔符没有做任何事情,所以:
from __future__ import print_function
def printit():
print ("NUCLEAR CORE UNSTABLE!!!",
"Quarantine is in effect.",
"Surrounding hamlets will be evacuated.",
"Anti-radiationsuits and iodine pills are mandatory.\n",
sep="\n")
Personally I prefer this one. 我个人更喜欢这个。 You could put it all on one line, but that makes the code difficult to read and maintain.
你可以将它全部放在一行上,但这会使代码难以阅读和维护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.