class test:
def __init__(self):
print('inside the code')
def add(self,x,y):
a=x+y
def list_test(self):
ar=[]
ar.append(1)
ar.append(2)
def dict_test(self):
dict_t={1:2,2:3}
cl=test()
어떻게 접근을 a
, ar
그리고 dict_t
클래스 외부? 여기 에 인쇄 a
하고 싶습니다 ar
. 감사합니다.
이렇게 :
class test:
def __init__(self):
self.ar = []
self.dict_t = {}
self.a = 0
print('inside the code')
def add(self, x, y):
self.a = x+y
def list_test(self):
self.ar.append(1)
self.ar.append(2)
def dict_test(self):
self.dict_t = {1: 2, 2: 3}
t = test()
t.list_test()
print(t.ar)
t.add()
print(t.a)
노트 :
시작 함수에서 변수를 정의하십시오. 그런 다음 다음을 통해 액세스 할 수 있습니다.
class_name.var_name
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다