Python列表对象属性'append'是只读的
问题描述:
正如标题所说,在python中,我试图让某人在某个选择中输入(在这种情况下为Choice13),然后它将旧密码从列出密码并添加新密码。Python列表对象属性'append'是只读的
passwords = ['mrjoebblock' , 'mrjoefblock' , 'mrjoegblock', 'mrmjoeadmin' ]
if choice == '3':
password = raw_input('Welcome admin! I\'m going to need your password ')
if password == 'mrjoeadmin':
print('Welcome Mr. Joe!')
Choice11 = raw_input('What would you like to do? Press 1 for changing your admin password, 2 for viewing a class\'s comments, or 3 for changing a class\'s password')
if Choice11 == '1':
print('You have chosen to change your password! ')
Choice12 = raw_input('You will need to put in your current password to access this feature ')
if Choice12 == 'mrmajoeadmin':
Choice13 = raw_input('What would you like to change your password to? ')
passwords.remove('mrjoeadmin')
passwords.append = Choice13
答
要追加东西的清单,你需要呼叫的append
方法:
passwords.append(Choice13)
正如你所看到的,在一个例外,你分配到 append方法结果不应该替换内建对象的方法 - (如果你想修改内建类型,支持的方式是通过子类化)。
答
,或者你可以做修改同一个列表插槽:
passwords[passwords.index('mrjoeadmin')] = Choice13
我想你的意思是叫'passwords.append(Choice13)提醒我' –
啊,谢谢。我完全忘了 –