【Python】TypeError: descriptor ‘append‘ for ‘list‘ objects doesn‘t apply to a ‘str‘ object
python报错
·
问题描述
提示:这里描述项目中遇到的问题:
Python报错
def fizzBuzz(self, n: int) -> List[str]:
a=List["1"]
for i in range(2,n):
if float(i/3)!=0 and float(i/5)!=0:
a.append("{}".format(i))
原因分析:
提示:这里填写问题的分析:
例如:python中可以通过 a=[ ] 和 a=List [ ] 定义的列表时不一样的,使用第一种不会就不会报错
解决方案:
改成
def fizzBuzz(self, n: int) -> List[str]:
a=[]
for i in range(2,n):
if float(i/3)!=0 and float(i/5)!=0:
a.append("{}".format(i))
更多推荐
已为社区贡献1条内容
所有评论(0)