defecho(msg): """ echo return its input agument The operation is: 1. print msg 2. return msg parameter param : msg : str return str """ return msg
1
echo?
1
echo??
1
help(echo)
Help on function echo in module __main__:
echo(msg)
echo return its input agument
The operation is:
1. print msg
2. return msg parameter
param : msg : str
return str
1
print(echo.__doc__)
echo return its input agument
The operation is:
1. print msg
2. return msg parameter
param : msg : str
return str
# global gv = 10 defecho(): global gv gv = 100 print(gv) echo() gv # 100
100
100
3. Inner Function
함수가 지역영역에 선언, 함수 안에 함수가 선언
1 2 3 4 5 6
defouter(a, b): definner(c, d): return c + d return inner(a, b)
1
outer(1,2)
3
1
inner(2, 3)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-14-468e0d571ba5> in <module>
----> 1 inner(2, 3)
NameError: name 'inner' is not defined
1 2 3 4 5 6
defouter(a, b): definner(c, d): return c + d return inner
1
outer(1,2)(3, 4)
7
1
# callback function : 함수를 아규먼트 파라미터로 설정해서 사용
1 2 3 4 5
defcalc(func, a, b): # code a **= 2 b **= 2 return func(a, b)