일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Regular Expression
- Python Implementation
- data science
- 43. Multiply Strings
- Python Code
- Convert Sorted List to Binary Search Tree
- Generator
- iterator
- 109. Convert Sorted List to Binary Search Tree
- 프로그래머스
- LeetCode
- 운영체제
- 밴픽
- 파이썬
- 30. Substring with Concatenation of All Words
- 컴퓨터의 구조
- concurrency
- Decorator
- attribute
- t1
- shiba
- 315. Count of Smaller Numbers After Self
- Protocol
- Class
- 715. Range Module
- DWG
- Python
- Substring with Concatenation of All Words
- kaggle
- 시바견
Archives
- Today
- Total
목록Closer (1)
Scribbling
<Python> 클로저
클로저는 간단히 말해 함수 안에 함수를 만드는 것이다. 클로저를 사용하는 이유는 크게 두가지이다. 1) 코드와 지역 변수를 묶어서 사용 가능하다. 2) 지역 변수를 숨기고 싶을 때 사용한다. 아래는 클로저의 예시이다. - 함수가 종료되어도 a, b 값이 유지되는 것을 확인할 수 있다. - nonlocal keyword를 이용하여 지역 변수의 변경이 가능하다. def line(a, b): total = 0 def get_value(x): nonlocal total total += a * x + b print('현재 누적 합: ' + str(total)) return a * x + b return get_value c = line(1, 2) print(c(1)) print(c(2)) print(c(3)) c..
Computer Science/Python
2021. 10. 28. 19:31