作者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/cn.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