當前位置:成語大全網 - 新華字典 - Python菜鳥出錯:AttributeError: 'NoneType' object has no attribute 'append'

Python菜鳥出錯:AttributeError: 'NoneType' object has no attribute 'append'

問題出在這裏:u_score=u_score.append(lose)

要知道,append方法是沒有返回值的。也就是說,上述語句第壹次會成功執行,並且將u_score賦值為None;第二次調用就會報錯,因為None是不能調.append方法的,

修改方法也簡單,u_score.append(lose)就可以了,不要接返回值