AttributeError: ‘int‘ object has no attribute ‘append‘
python执行报错:Traceback (most recent call last):File “E:\pythonProject2\mobile-test\0622.py”, line , ini.append(x)AttributeError: ‘int’ object has no attribute ‘append’报错代码:i=[]for i in range(3):x=int(in
·
python执行报错:
Traceback (most recent call last):
File “E:\pythonProject2\mobile-test\0622.py”, line , in
i.append(x)
AttributeError: ‘int’ object has no attribute ‘append’
报错代码:
i=[]
for i in range(3):
x=int(input("请输入整数:"))
i.append(x)
i.sort()
print(f"排序为:{i}")
看了很久 总觉得这个写法没问题
后面发现是 i 这个变量重复定义了两次 导致i没办法使用append这个方法,所以将for循环里面的 i 修改一下,运行结果就成功了
i=[]
for m in range(3):
x=int(input("请输入整数:"))
i.append(x)
i.sort()
print(f"排序为:{i}")
更多推荐
已为社区贡献2条内容
所有评论(0)