일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 43. Multiply Strings
- 밴픽
- Python
- Convert Sorted List to Binary Search Tree
- 컴퓨터의 구조
- shiba
- 715. Range Module
- 시바견
- LeetCode
- 315. Count of Smaller Numbers After Self
- concurrency
- data science
- Substring with Concatenation of All Words
- kaggle
- 파이썬
- Generator
- Decorator
- iterator
- Protocol
- 운영체제
- 프로그래머스
- 30. Substring with Concatenation of All Words
- Regular Expression
- 109. Convert Sorted List to Binary Search Tree
- DWG
- Python Implementation
- Python Code
- Class
- t1
- attribute
- Today
- Total
목록Python (33)
Scribbling
1. Iterator __iter__, __next__를 가진 객체를 iterator protocol을 지원한다고 일컫는다. class Counter: def __init__(self, limit): self.num = 0 self.limit = limit def __iter__(self): return self def __next__(self): if self.num < self.limit: ret = self.num self.num += 1 return ret else: raise StopIteration for i in Counter(10): print(i, end=' ') 클래스에서 __getitem__ 메서드만 구현해도 이터레이터가 된다. class Counter: def __init__(sel..
Python Class 관련하여 잘 몰랐던 부분을 정리해둔다. 1. 비공개 속성 및 메서드 속성이나 메서드에 "__"를 붙이면 클래스 외부에서 접근할 수 없다. class person: def __init__(self, name, nickname): self.name = name self.__nickname = nickname def __tease(self): print(self.__nickname) 2. 클래스 속성 클래스 속성은 아래처럼 선언가능하며, 클래스명으로 접근하는 것이 가독성에 좋다. class Person: all_names = [] def __init__(self, name): Person.all_names.append(name) self.name = name 3. 정적 메서드 (Stat..
클로저는 간단히 말해 함수 안에 함수를 만드는 것이다. 클로저를 사용하는 이유는 크게 두가지이다. 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..