파이썬 | 섹션1. Python Advanced(1)

sojung·2021년 3월 18일
0
post-thumbnail

Variable Scope

Keyworld - scope, global, nonlocal, locals, globals

전역변수

지역변수

py.ad_1_1.py

a = 10 # Global variable
def foo():
	# Read global variable
    print('Ex1 > ', a)

foo()

실행된다.

print('Ex1 > ', a)

실행된다.

b = 20

def bar():
	b = 30 # Local variable
    print('Ex2 > ', b) # Read lacal variable
    
bar()
print('Ex2 > ', b)

30이 나온다.

20이 나온다.

c = 40

def foobar():
	c = c + 10
    
    print('Ex3 > ', c)
    
foobar()

에러 발생

인프런_모두를 위한 파이썬 : 필수 문법 배우기 Feat. 오픈소스 패키지 배포 (Inflearn Original) 바로가기

profile
걸음마코더

0개의 댓글