c - 如何在 Python 列表中动态插入数据?

标签 c python-2.7

以下用 C 编写的代码在 Python 中的等效项是什么?

int a[100];
int lim;
scanf("%d",&lim)
for(i=0;i<lim;i++)
    scanf("%d",&a[i]);

最佳答案

这里

# create an empty list
a = [];
# take limt as input
lim = raw_input("Enter limit")

# this is python style of for loop
# here i will start from 0 and will go upto limit
for i in range (0, int(lim)):
    # take input from user one by one and append to list
    elem = raw_input("")
    a.append(int(elem))

关于c - 如何在 Python 列表中动态插入数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23925042/

相关文章:

c - 如何创建分布式阵列 MPI

python-2.7 - 由于 Windows 程序文件权限,conda 更新 conda 无法正常工作

python - 尝试在 Python 中加载 C DLL 时出现错误的 ELF 类

c - 高斯消元法 - 线性方程矩阵,算法

c中读/写文本文件的困惑

python-2.7 - matplotlib.pyplot.plot() 和 matplotlib.pyplot.figure() 之间的区别?

python - 类型错误 : 'int' object is not iterable - Python

python - 了解 Python 中 namedtuple typename 和 pickle 的问题

比较两个结构文件(Linux 内核)

c - 为什么 inet_aton 返回的十六进制数是倒序的?