【发布时间】:2021-12-10 05:50:26
【问题描述】:
from array import *
ar = array("B", ['hello', 'to', 'myuniVerse'])
for i in range(len(ar)):
print(ar[i])
错误:
ar = array("B", ['hello', 'to', 'myuniVerse'])
TypeError: an integer is required (got type str)
请帮助解决上述代码中的问题。
【问题讨论】:
-
因为您正在创建整数数组(类型代码“B”)并尝试使用字符串列表对其进行初始化...为什么需要使用数组而不是列表类型的 ibject?