160x600
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 훈련
- Deep Learning
- 크롤링(crawling)
- sklearn
- HeidiSQL
- 데이터전처리
- 데이터 수집
- SQL예제
- keras
- 데이터
- pandas
- 딥러닝
- 머신러닝
- 해석
- pythone
- 선형회기모델
- 데이터 가공
- 시각화
- MariaDB
- tensorflow
- 알고리즘기초
- 파이썬
- python
- 예측
- 정확도
- 데이터 분석
- 데이터베이스
- 회귀모델
- python기초
- Database
Archives
- Today
- Total
코딩헤딩
python 알고리즘 기초1 (유니코드, 클로저함수 기초) 본문
728x90
1. 유니코드
*문자열을 UTF-8로 인코딩하기
text = "안녕하세요"
encode_text = text.encode("utf-8")
encode_text
결과 : b'\xec\x95\x88\xeb\x85\x95\xed\x95\x98\xec\x84\xb8\xec\x9a\x94'
*문자열을 UTF-8로 디코딩하기
decode_text = encode_text.decode("utf-8")
decode_text
결과 : '안녕하세요'
2. 클로저
### 클로저 함수 정의하기
def outer_function(x):
# 내부 함수 정의 : 실제 실행되는 함수
def inner_function(y):
s = x+y
return s
return inner_function
### 클로저 함수 호출하기
closure_exe = outer_function(10)
print(closure_exe)
### 내부 함수 호출하기
resutl1 = closure_exe(5)
print(resutl1)
결과 : 15
중간중간 값과 주소를 찍어가며 확인해 보면
### 클로저 함수 정의하기
def outer_function(x):
print(f"#1 : x = {x}")
# 내부 함수 정의 : 실제 실행되는 함수
def inner_function(y):
print(f"#2 : y = {y}")
s = x+y
print(f"#3 : s = {s}")
return s
print("#4----------")
return inner_function
### 클로저 함수 호출하기
closure_exe = outer_function(10)
print(closure_exe)
결과 : #1 : x = 10
#4----------
<function outer_function.<locals>.inner_function at 0x000002D34F715B20>
closure_exe는 inner_funnction자체를 리턴 받으며 주소값을 가진다.
### 내부 함수 호출하기
resutl1 = closure_exe(5)
print(resutl1)
결과 : #2 : y = 5
#3 : s = 15
15
728x90
'python' 카테고리의 다른 글
python 알고리즘 기초3 데코레이터(Decorator) (1) | 2023.11.15 |
---|---|
python 알고리즘 기초2 (클로저함수) (1) | 2023.11.14 |
python 연습문제2 (도서관리 키오스크 프로그램 만들기) (2) | 2023.11.14 |
python 기초 12 (예외처리) (1) | 2023.11.10 |
python 기초 11 (정규식 Regular Expression) (1) | 2023.11.10 |