[問題] Class 範例,不知道哪出錯

看板Python作者 (哇係gary)時間15年前 (2009/10/09 14:22), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
Hi. 我是新手中的新手 我目前按照 http://pydoing.blogspot.com/2008/10/blog-post_1288.html 了解Python 以下是CODE: class Point(object): def _init_(self,x=0,y=0): self.x=x self.y=y def _str_(self): return "("+str(self.x)+","+str(self.y)+")" 先編譯後 在Python Shell下輸入p1=Point(1,1) 卻出現 Traceback (most recent call last): File "<pyshell#20>", line 1, in <module> p=Point(1,1) TypeError: object.__new__() takes no parameters 哪裡的問題呢?我對照這個教學的內容照著打上的 感謝大家寶貴的時間啦~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 71.196.234.172

10/09 14:29, , 1F
是 __init__ 不是 _init_
10/09 14:29, 1F

10/09 14:34, , 2F
原來,網頁上寫連續兩個底線,真是閱讀不仔細。感謝!!
10/09 14:34, 2F
文章代碼(AID): #1ApjQFd3 (Python)
文章代碼(AID): #1ApjQFd3 (Python)