-
[Variable scope] global scope vs function scope🐍 파이썬/파이썬 기본 문법 2022. 7. 18. 08:35
- when you create a variable outside a function, we say the variable was defined inside the global scope
- when you define a variable inside a function, it is available in the function scope
- variables that are defined inside a function cannot be accessed from outside of the function
x = 10 # gloabl scope def f(): x = 20 # function scope y = 30 print (x) print (x) # 10 f() # 20 this does not change the gobal x print(x) # still 10 print(y) # name error
'🐍 파이썬 > 파이썬 기본 문법' 카테고리의 다른 글
[List] 자주쓰이는 리스트 메소드 정리 (0) 2022.07.19 [concept] list vs tuple (0) 2022.07.19 what is first class object? (0) 2022.07.18 함수를 함수의 변수로 넘기기 (0) 2022.07.18 [Function] 함수란 (0) 2022.07.18