Notice
Recent Posts
Recent Comments
Link
뮤트 개발일지
Python 예제) 재귀함수, 중첩함수, lambda함수 본문
재귀함수
재귀함수recursive function: 자기 스스로를 호출하는 함수
예)
def func(count):
if count > 0:
print(count, '현재')
func(count-1)
print('결과'. count)
f(3)
===>
3 현재
2 현재
1 현재
결과 0
결과 1
결과 2
결과 3
중첩함수
중첩함수nested function: 함수 안에 정의된 함수
예)
def func1(a):
def func2():
nonlocal a
a = a + 1
return a
return func2()
func1(2)
===> 3
lambda 함수
lambda 함수: 이름이 없는 한 줄짜리 함수
기본구조
lambda 인수: 반환할 내용
예) lambda x, y: x + y
'Python' 카테고리의 다른 글
| Python 클래스 - 모듈, 패키지, 클래스, 객체 (0) | 2021.12.20 |
|---|---|
| Python 내장함수, 외장함수 (0) | 2021.12.20 |
| Python 함수 - 기본구조, 매개변수, local변수와 global변수, generator, yield (0) | 2021.12.19 |
| Python 제어문 - while 문 (0) | 2021.12.19 |
| Python 제어문 - for 문 (0) | 2021.12.19 |