如何创建两个包含 10 个实例的列表

How to create two lists which contain 10 instances

我刚开始学习 python 并卡在这里:

创建两个名为 x_listy_list 的列表,其中分别包含变量 xy 的 10 个实例。

您还需要创建一个名为 big_list 的列表,其中包含变量 xy,每个变量 10 次,方法是连接您创建的两个列表。

我建议您阅读更多关于 python 文档和 list 文档,您可以找到它 here

但你可以这样做:

x_list = [x]*10 # Create list with 10 vars of the value of x
y_list = [y]*10
big_list = x_list + y_list # conact two list into one

您可以通过 python 运算符连接列表。

x_list = [1] * 10 #This is for example.  
y_list = [2] * 10 #This is for example.  

x_y_list = (x_list + y_list)
print(x_y_list)

x_y_list 给出结果列表