作者almaplty ()
看板Python
標題[問題] class問題
時間Fri Dec 4 12:13:02 2015
小弟最近剛學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://webptt.com/m.aspx?n=bbs/Python/M.1449202387.A.338.html
1F:→ bigpigbigpig: acct 裡面沒有東西,為何想取得第一個元素的資料? 12/04 12:20
2F:→ uranusjr: acct.append(Account(...)) 12/04 13:01
3F:→ uranusjr: 這其實不是 class 的問題, 是你沒瞭解 list 的用法 12/04 13:02
4F:→ almaplty: 謝謝各位大大 我知道append 不知道為什麼鬼打牆了 12/04 18:10
5F:→ almaplty: 我改用dictionary 完成了 12/04 18:11