【发布时间】:2021-03-20 10:14:56
【问题描述】:
我刚开始学习 python 并卡在这里:
创建两个名为x_list 和y_list 的列表,分别包含变量x 和y 的10 个实例。
您还需要创建一个名为big_list 的列表,其中包含变量x 和y,每个10 次,通过连接您创建的两个列表。
【问题讨论】:
-
请添加一些例子
标签: python python-3.x list operators
我刚开始学习 python 并卡在这里:
创建两个名为x_list 和y_list 的列表,分别包含变量x 和y 的10 个实例。
您还需要创建一个名为big_list 的列表,其中包含变量x 和y,每个10 次,通过连接您创建的两个列表。
【问题讨论】:
标签: python python-3.x list operators
我会推荐你阅读更多关于 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 给出结果列表
【讨论】: