[英]How to create new instance of current class inside the current class method?
[英]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.