打印表示整个变量
Print says the whole variable
所以我一直在努力做到这一点,这样我就可以打印出很长的一行,这样我就可以让它看起来很漂亮,但似乎并没有像往常一样工作...
playerguess = input()
playerguess = int(playerguess)
days = 2
example = ("Looks like this storm won't stop for another ", days + playerguess, " we will have to wait")
print("-Captain Strand- \"", example, "\" (You can barely hear him but thats all you hear)")
对于您的示例,您可能打算使用 "".join(example)
,但是,您可能真的想要模板化多行字符串并使用 .format()
(这两种方法都是 字符串)
TEMPLATE = """{header}
"Looks like this storm won't stop for another {days}, we will have to wait"
(You can barely hear him but thats all you hear)"""
TEMPLATE.format(
header="-Captain Strand-",
days=days + playerguess,
)
>>> print(TEMPLATE.format(
... header="-Captain Strand-",
... days=days + playerguess,
... ))
-Captain Strand-
"Looks like this storm won't stop for another 5, we will have to wait"
(You can barely hear him but thats all you hear)
原本
>>> example = ("Looks like this storm won't stop for another ", days + playerguess, " we will have to wait")
>>> example # example is a tuple of strings
("Looks like this storm won't stop for another ", 5, ' we will have to wait')
>>> example = "".join(("Looks like this storm won't stop for another ", str(days + playerguess), " we will have to wait"))
>>> example # example is a single string
"Looks like this storm won't stop for another 5 we will have to wait"
所以我一直在努力做到这一点,这样我就可以打印出很长的一行,这样我就可以让它看起来很漂亮,但似乎并没有像往常一样工作...
playerguess = input()
playerguess = int(playerguess)
days = 2
example = ("Looks like this storm won't stop for another ", days + playerguess, " we will have to wait")
print("-Captain Strand- \"", example, "\" (You can barely hear him but thats all you hear)")
对于您的示例,您可能打算使用 "".join(example)
,但是,您可能真的想要模板化多行字符串并使用 .format()
(这两种方法都是 字符串)
TEMPLATE = """{header}
"Looks like this storm won't stop for another {days}, we will have to wait"
(You can barely hear him but thats all you hear)"""
TEMPLATE.format(
header="-Captain Strand-",
days=days + playerguess,
)
>>> print(TEMPLATE.format(
... header="-Captain Strand-",
... days=days + playerguess,
... ))
-Captain Strand-
"Looks like this storm won't stop for another 5, we will have to wait"
(You can barely hear him but thats all you hear)
原本
>>> example = ("Looks like this storm won't stop for another ", days + playerguess, " we will have to wait")
>>> example # example is a tuple of strings
("Looks like this storm won't stop for another ", 5, ' we will have to wait')
>>> example = "".join(("Looks like this storm won't stop for another ", str(days + playerguess), " we will have to wait"))
>>> example # example is a single string
"Looks like this storm won't stop for another 5 we will have to wait"