python - 将元素放入 for lob Python 3 的新数组中
问题描述
我正在开发一个 Python 3 项目。我的代码更长,但我为您准备了我的代码的基本示例,它可以工作。
arr = []
number = (["01", "02", "03", "06", "08"])
arr = number
pos1 = int(arr[1],16)
pos2 = 2 + int(arr[1],16)
for s in range(pos1,pos2):
print(arr[s])
说明:
您看到的数字,它们是十六进制数字,我将其转换pos1
为int
并2
在其上加上pos2
. 过了一会儿,我得到了03 06
. 我想在不同的数组中使用这些数字。有没有办法放入03 06
一个新的数组?
解决方案
如果我理解正确,那么试试这个:
arr2 = []
number = (["01", "02", "03", "06", "08"])
arr = number[:]
pos1 = int(arr[1],16)
pos2 = 2 + int(arr[1],16)
for s in range(pos1,pos2):
arr2.append(arr[s]) # add numbers to arr2
print(arr2[0])
推荐阅读
- python - Python 日志记录 - AttributeError:模块“日志记录”没有属性“处理程序”
- c - 使用 qsort() 真的很难
- javascript - 即使运行了 preventDefault,也会在单击事件上检查单选按钮
- java - 使用 BNF Javacc 验证值是否存在
- python - B样条是否通过控制点?
- c# - c#当文本框文本为null或为空时报错
- firebase - 将文档添加到 Cloud Firestore 中的集合而不覆盖以前的文档 Flutter
- google-analytics - Google Analytics 同意模式(测试版) - 发送数据但不反映在仪表板上
- ruby-on-rails - 如果测试工作流程通过,则运行部署工作流程
- javascript - 从 json 对象中动态删除未使用的键