tu_num1 = ('p','y','t',['o','n'])
tu_num1[3][0].append('h')
print(tu_num1)
报错:AttributeError: ‘str’ object has no attribute ‘append’
百度翻译:属性错误:字符串没有属性‘append’
改正:
tu_num1 = ('p','y','t',['o','n'])
tu_num1[3].append('h')
print(tu_num1)
拓展:向元组中的列表中指定位置添加元素
tu_num1 = ('p','y','t',['o','n'])
tu_num1[3][0].insert('h')
print(tu_num1)
报错:AttributeError: ‘str’ object has no attribute ‘insert’
insert不能应用于字符串
正确代码:
tu_num1 = ('p','y','t',['o','n'])
tu_num1[3].insert(0,'h')
print(tu_num1)