Python List object attribute 'append' is read-only

后端 未结 2 1310
生来不讨喜
生来不讨喜 2021-02-19 09:01

as the title says, in python, I\'m trying to make it so when someone types in a choice (in this case Choice13) then it deletes the old password from the list passwords and adds

相关标签:
2条回答
  • 2021-02-19 09:03

    or you could modify the same list slot by doing:

    passwords[passwords.index('mrjoeadmin')] = Choice13
    
    0 讨论(0)
  • 2021-02-19 09:13

    To append something to a list, you need to call the append method:

    passwords.append(Choice13)
    

    As you've seen, assigning to the append method results in an exception as you shouldn't be replacing methods on builtin objects -- (If you want to modify a builtin type, the supported way to do that is via subclassing).

    0 讨论(0)
提交回复
热议问题