[問題] class問題

看板Python作者時間10年前 (2015/12/04 12:13), 編輯推噓0(005)
留言5則, 3人參與, 最新討論串1/1
小弟最近剛學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

12/04 12:20, , 1F
acct 裡面沒有東西,為何想取得第一個元素的資料?
12/04 12:20, 1F

12/04 13:01, , 2F
acct.append(Account(...))
12/04 13:01, 2F

12/04 13:02, , 3F
這其實不是 class 的問題, 是你沒瞭解 list 的用法
12/04 13:02, 3F

12/04 18:10, , 4F
謝謝各位大大 我知道append 不知道為什麼鬼打牆了
12/04 18:10, 4F

12/04 18:11, , 5F
我改用dictionary 完成了
12/04 18:11, 5F
文章代碼(AID): #1MOHBJCu (Python)
文章代碼(AID): #1MOHBJCu (Python)