Python 使用一个打印命令打印结果

Python 使用一个打印命令打印结果,python,printing,concatenation,Python,Printing,Concatenation,下面是我的python程序,我在其中打印随机数。我要做的是只使用一个print命令进行打印 import random x = list(range(1,100)) y = list(range(1,100)) x = random.sample(x,6) y = random.sample(y,1) print("I think the lottery's winning numbers are ",x) print('\nand the powerball should be ', y

下面是我的python程序,我在其中打印随机数。我要做的是只使用一个print命令进行打印

import random

x = list(range(1,100))
y = list(range(1,100))

x = random.sample(x,6)
y = random.sample(y,1)

print("I think the lottery's winning numbers are ",x)
print('\nand the powerball should be ', y)

Python掩护你了!这很简单,因为abc:

print("I think the lottery's winning numbers are {}\nand the powerball should be {}".format(x, y))
请注意,使用这种将变量放入字符串的简单方法,您可以轻松地放入任意数量的{}

对于更复杂的任务,这可能而且肯定会在将来派上用场。例如,您可以使用此输入方法检查域中是否存在特定的子域数组:

http.request('GET','https://pagetorequest.com/{}.php'.format(subdomains_to_check[index]))
试试这个

print("I think the lottery's winning numbers are {} \n and the powerball should be {}".format(x, y))

您可以这样打印:

print(f"I think the lottery's winning numbers are {x} and the powerball should be {y}")
在“str”之前添加f允许使用{variable}直接在字符串中添加变量

请从。特别是,我们希望您在发布之前访问现有文档和示例。