看板 Python 關於我們 聯絡資訊
小弟最近剛學python 對於python很不熟悉 想寫一個可以存很多Account的class class Account: def __inti__(self, number, name, deposit, address): self.account_id = number self.account_name = name self.deposit = deposit self.address = address acct = [] i = 0 acct[i].Account(number,name,deposit,address) 為什麼他說acct[i].Account(number,name,deposit,address)這行 IndexError: list index out of range list不能這樣用嗎 請問我錯在哪裡 謝謝各位 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.122.184 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1449202387.A.338.html
bigpigbigpig: acct 裡面沒有東西,為何想取得第一個元素的資料? 12/04 12:20
uranusjr: acct.append(Account(...)) 12/04 13:01
uranusjr: 這其實不是 class 的問題, 是你沒瞭解 list 的用法 12/04 13:02
almaplty: 謝謝各位大大 我知道append 不知道為什麼鬼打牆了 12/04 18:10
almaplty: 我改用dictionary 完成了 12/04 18:11