python - 如何在 Python 中的 for 循环中创建不同的变量
问题描述
我正在制作一个具有 for 循环的程序,每次运行循环时,我都希望它创建一个新变量,例如
for item in range(0, size)
(Make new variable bit1, bit2, bit3, bit4, etc with value of 0)
这可能吗?
解决方案
创建一个List
变量并像这样附加到它:
bits = []
for item in range(0, size)
bits.append(0)
# now you have bits[0], bits[1], bits[2], etc, all set to 0
推荐阅读
- c# - 如何使用对象列表而不是循环填充 SQL Server 数据库
- regex - Perl替换匹配模式上方一行中的字符串
- c# - 在 C# 中通过串行端口进行高速串行通信
- mysql - 运行查询时是否可以在导出 .csv 文件中硬编码下拉菜单?
- node.js - 角度形式组 patchValue 围绕值包装大括号
- node.js - 上传图片时出现错误 500(内部服务器错误)
- qr-code - 如何在二维码中编码 Ctrl 函数?
- python - 服务于 TensorFlow 预建的线性分类器估计器模型
- c# - 在哪里添加代码以根据来自另一个模型字段值的值填充数据库中模型字段的值
- jvm - 确定 String 是否为编译时常量