a = ['a-b'] b = a.replace('-','') print(b)
报错:
AttributeError: 'list' object has no attribute 'replace'
原因:
list对象没有replace方法,str对象才有。
解决方案:
a = ['a-b'] b = str(a).replace('-','') print(b)
》》['ab']
完美解决!
a = ['a-b'] b = a.replace('-','') print(b)
报错:
AttributeError: 'list' object has no attribute 'replace'
原因:
list对象没有replace方法,str对象才有。
解决方案:
a = ['a-b'] b = str(a).replace('-','') print(b)
》》['ab']
完美解决!