#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목[re][re][re]local variable과 global variable2023-03-20 13:50
작성자

항상 생략 가능한 건 아닙니다. 제시하신 코드와 같이 전역 변수를 '읽기만' 하는 경우에 한해서만 생략해도 무방한 것이며 아래와 같이 전역 변수를 수정하려 하는 경우에는 꼭 global statement를 기술해줘야 의도대로 동작하는 프로그램을 얻을 수 있습니다.


number_storage = 0


def accumulate(num):

  global number_storage #한번 빼 보고도 실행해 보세요.

  number_storage += num

  return number_storage


accumulate(10)

accumulate(10)

댓글
이전[re][re]local variable과 global variable2023-03-16
다음rounding error 질문 ㅜㅜ2023-03-15