• 회원가입
  • 로그인
  • 구글아이디로 로그인

[keyword] Python - nonlocal 키워드 - 안긴 함수 안의 변수 효력 범위 확장. (= 넌로컬)

723  
nonlocal 예제 - nonlocal 선언 O 경우.

 

def hz1():

  x = "홈짱닷컴"

  def hz2():

    nonlocal x

    x = "Homzzang.com"

  hz2() 

  return x

 

print(hz1())

 

결과값: Homzzang.com

 

nonlocal 정의

 

안긴 함수 안의 변수가 내부 함수에 속하지 않아야 함을 선언.

※ 즉, 안긴 함수 안 변수의 효력 범위를 바깥 함수로 확장.

 


cf.

global 키워드 : 로컬 범위에서 전역변수 선언.

 

 

nonlocal 예제 - nonlocal 선언 X 경우.

 

def hz1():

  x = "홈짱닷컴"

  def hz2():

    x = "Homzzang.com"

  hz2() 

  return x

 

print(hz1())

 

결과값: 홈짱닷컴



분류 제목
module Python - statistics.mode() 메서드 ★ - 최빈값 반환. (= mode메서드 = 모드)
module Python - statistics.pstdev() 메서드 -
module Python - statistics.stdev() 메서드 -
module Python - statistics.pvariance() 메서드 -
module Python - statistics.variance() 메서드 -
module Python - math 모듈 메서드・상수 종류 (※ 수학 모듈)
module Python - math.acos() 메서드 -
module Python - math.acosh() 메서드 -
module Python - math.asin() 메서드 -
module Python - math.asinh() 메서드 -
module Python - math.atan() 메서드 -
module Python - math.atan2() 메서드 -
module Python - math.atanh() 메서드 -
module Python - math.ceil() 메서드 ★ - 천장 반올림 (= 상위 정수로 반올림. = ceil메서드…
module Python - math.comb() 메서드 -
module Python - math.copysign() 메서드 -
module Python - math.cos() 메서드 -
module Python - math.cosh() 메서드 -
module Python - math.degrees() 메서드 -
module Python - math.dist() 메서드 -
19/24
목록
찾아주셔서 감사합니다. Since 2012