길/Python 20

Class Methods / Static Methods / Properties

Methods는 기본적으로 클래스의 인스턴스에 의해 작동하지만(클래스는 self 인자로 전달됩니다) Class Methods는 클래스에 의해 작동한다. 아래 예시는 class method를 사용하여, 클래스와 다른 파라미터를 이용해서 인스턴스를 생성하는 것을 보여준다. class Rectangle: def __init__(self, width, height): self.width = width self.height = height def calculate_area(self): return self.width * self.height # class method decorator # 첫번째 인자는 class가 들어온다.(cls) @classmethod def new_square(cls, side_length..

길/Python 2021.02.13

클래스 / 객체 / 인스턴스 구분

gmlwjd9405.github.io/2018/09/17/class-object-instance.html [Java] 클래스, 객체, 인스턴스의 차이 - Heee's Development Blog Step by step goes a long way. gmlwjd9405.github.io 클래스 : 설계도 객체 : 설계도로 구현할 대상 -> 클래스의 인스턴스라고도 칭함. 인스턴스 : 구현된 실체 자바스크립트에서 new Date() 같은 것을 할 때 Date 클래스의 new method를 이요해서 인스턴스를 생성하는 것 같기도...

길/Python 2021.02.12

magic methods

__add__ for + __sub__ for - __mul__ for * __truediv__ for / __floordiv__ for // __mod__ for % __pow__ for ** __and__ for & __xor__ for ^ __or__ for | 모든 methods에는 r+ 연산자가 뒤따른다. 연산자에 r을 붙이면, 연산이 반대로 되는 경우를 뜻하는 것으로 보인다. 아래는 magic methods의 예시. class SpecialString: def __init__(self, cont): self.cont = cont def __truediv__(self, other): line = "=" * len(other.cont) return "\n".join([self.cont, line,..

길/Python 2021.02.12

itertools

itertools는 파이썬의 standard library라고 한다. 추후 몇 가지 이용할 수 있는 것을 적어놓아야겠다. docs.python.org/ko/3/library/itertools.html itertools — 효율적인 루핑을 위한 이터레이터를 만드는 함수 — Python 3.9.1 문서 docs.python.org count(n) : n부터 무한으로 숫자를 늘려간다. cycle(arg) : 인자 안에 들어온 것 안에서 반복 repeat(element[,n]) : element를 n만큼, 혹은 무한정 반복

길/Python 2021.02.12