【问题标题】:How to create two lists which contain 10 instances [closed]如何创建两个包含 10 个实例的列表 [关闭]
【发布时间】:2021-03-20 10:14:56
【问题描述】:

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

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

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

【问题讨论】:

  • 请添加一些例子

标签: python python-3.x list operators


【解决方案1】:

我会推荐你​​阅读更多关于 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

【讨论】:

    【解决方案2】:

    您可以通过 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 给出结果列表

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      • 1970-01-01
      • 2021-12-17
      • 2017-07-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-07
      相关资源
      最近更新 更多