일부 변수가 ___init____에 설정되어있는 클래스를 만들었으므로 해당 클래스의 메소드에서이 변수를 변경할 수 있기를 원합니다.클래스의 메소드에서 인스턴스 변수를 변경하십시오.
class example_class:
def __init__(self, variable):
self.thing = 'variable'
def example_method(self):
self.thing = 'changed text'
def different_method(self):
print(self.thing)
그래서 "example_method"를 호출하기 전에 self.thing의 값은 문자열 '변수'다음 지금 self.thing 방법 "example_method"를 일치 한 호출 한 후 '변경 텍스트'입니다. 이 작업은 가능해야하지만 수행 방법을 이해할 수 없습니다.
당신이 실제로 구현으로 어떤 문제를보고있다 : 당신은 또한 같은 뭔가를 할 수
? – khelwood
메소드 example_method를 실행 한 후 self.thing의 값은 원래 'variable'인데 'changed text'로 변경되지 않았습니다. – tombat7112