看板 [ Python ]
討論串[問題] 類別中使用List的問題
共 4 篇文章
首頁
上一頁
1
下一頁
尾頁

推噓3(3推 0噓 0→)留言3則,0人參與, 5年前最新作者nevak (^o^)時間5年前 (2019/11/20 09:50), 5年前編輯資訊
0
0
0
內容預覽:
簡單來說:. 你如果需要每一個實體都有自己的x, y, pos,不需要在class裡先assign x, y, pos. 直接在__init__()裡assign self.x, self.y, self.pos就可以了. 複雜一點說明如下:. 首先你在前面寫的. class Point:. x =
(還有1347個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者poototo (poototo)時間5年前 (2019/11/19 21:21), 編輯資訊
0
0
0
內容預覽:
1.您只是要預設值的意思吧?. 2.class屬性跟self屬性,注意不一樣,可看p1.__dict__及dir(p1). ===========. class Point:. def __init__(self, x=0, y=0):. self.x = x. self.y = y. self.p
(還有42個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者TuCH (謬客)時間5年前 (2019/11/19 17:03), 編輯資訊
0
0
0
內容預覽:
可以改成這樣. class Point:. def __init__(self, x, y):. self.x = x. self.y = y. @property. def pos(self):. return [self.x, self.y]. 可以避免產生資料不同步的問題. --. 發信站

推噓2(2推 0噓 3→)留言5則,0人參與, 5年前最新作者jijuan時間5年前 (2019/11/19 10:20), 編輯資訊
0
0
0
內容預覽:
class Point:. x = 0. y = 0. pos = [0, 0]. def __init__(self, x, y):. self.x = x. self.y = y. self.pos[0] = x. self.pos[1] = y. def show_xy(self):. pri
(還有208個字)
首頁
上一頁
1
下一頁
尾頁