변수 전역변수 지역변수 전역변수 함수 밖에 선언된 변수로 어디에서나 사용은 가능하지만, 함수 안에서 수정할 수는 없다. num_out = 10 def printNum(): print(f'num_out: {num_out}') printNum() print(f'num_out: {num_out}') -- 출력 -- num_out: 10 num_out: 10 num_out = 10#전역변수 def printNum(): num_out = 20#지역변수 print(f'num_out: {num_out}') printNum() print(f'num_out: {num_out}') -- 출력 -- num_out: 20 num_out: 10 지역변수 함수 안에 선언된 변수로 함수 안에서만 사용가능하다. def printNu..
파이썬 Python : 전역변수, 지역변수
변수 전역변수 지역변수 전역변수 함수 밖에 선언된 변수로 어디에서나 사용은 가능하지만, 함수 안에서 수정할 수는 없다. num_out = 10 def printNum(): print(f'num_out: {num_out}') printNum() print(f'num_out: {num_out}') -- 출력 -- num_out: 10 num_out: 10 num_out = 10#전역변수 def printNum(): num_out = 20#지역변수 print(f'num_out: {num_out}') printNum() print(f'num_out: {num_out}') -- 출력 -- num_out: 20 num_out: 10 지역변수 함수 안에 선언된 변수로 함수 안에서만 사용가능하다. def printNu..
2023.09.27