簡體   English   中英

如何在課堂上獲得當前實例?

[英]How to get current instance in class?

我不知道如何在課堂上獲得當前實例。

class Basic(object):
    def __init__(self, val):
        self.val = val

    def current_ins(self):
        ???

有什么辦法可以在python中使用val來獲取當前實例? 謝謝。

“當前實例”是self

Self是所有類的當前實例。 就你而言

class Basic(object):
    def __init__(self, val):
        self.val = val

    def current_ins(self):
        #???
        print self.val    # one can use self to access all the member of it's class.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM