전역 변수와 지역 변수
def DFS1(): print(cnt) def DFS2(): if cnt==5: print(cnt) if __name__=="__main__": cnt=5 DFS1() DFS2() print(cnt) -위의 출력값은 5, 5, 5이다 cnt=5로 전역 변수로 모든 함수에 적용된다 def DFS1(): cnt=3 print(cnt) def DFS2(): if cnt==5: print(cnt) if __name__=="__main__": cnt=5 DFS1() DFS2() print(cnt) -DFS1()에서 cnt=3으로 지역 변수(local)로 선언되어 5로 출력되지 않는다 출력값은 3, 5, 5이다 def DFS1(): cnt=3 print(cnt) def DFS2(): if cnt==5: cnt+=..
Algorithm/inflearn python algorithm
2021. 8. 10. 12:02