适合初学者的 Python 数组

标签 python arrays input

我刚开始学习 Python,对数组有一些疑问。我完全不理解他们。我得到了一个项目,想知道是否有人可以提供帮助。我必须制作一个 1x4 的盒子。用户可以选择四个方框之一,然后 A 将出现在其中。其他三个框然后填充 B C D。

somearray = []
    index= input("")-1
    char = raw_input("")
    somearray[] = char

这就是我的任务。我也知道需要输入或 raw_input

def drawArray():
    somearray = []
    index = input("1 , 2 , 3 , 4") - 1
    char = raw_input("A , B , C, D ")
    somearray[] = char

这是我输入的内容。我不确定从这里应该去哪里。如果有人可以提供帮助,将不胜感激。

最佳答案

你的意思是这样的吗?

>>> def func():
    ind=input("enter the index :")-1
    lis=['B','C','D']
    lis.insert(ind,'A')
    return lis
   ....: 

>>> func()
enter the index :1
>>> ['A', 'B', 'C', 'D']

>>> func()
enter the index :2
>>> ['B', 'A', 'C', 'D']

>>> func()
enter the index :3
>>> ['B', 'C', 'A', 'D']

关于适合初学者的 Python 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14403742/

相关文章:

arrays - C 中权重 [a]= 数据上的段错误;

Angular 2 - 如何从父级触发子级的方法

javascript - 通过javascript以编程方式将文件插入HTML输入

python - 如果语句不读取输入

python - 试图从 scipy powerlaw fit 中获得合理的值(value)

python - Django 没有模块命名设置

python - 如何创建具有多对多关系的模型作为类别(即摇滚、乡村、蓝调和流行)

Python - 正则表达式 - 来自 Xpath - TypeError : '_sre.SRE_Match' object is not subscriptable

php - 将MySQL结果保存到php多维数组(时间表)

arrays - AS3从字母表数组中获取随机唯一字符