[python] python의 self와 __init__의 이해
·
Study/Python
Python의 클래스에 대한 이해 다른 언어와 동일하게 python에서도 클래스를 이용하여 보다 편리하게 함수를 다룰 수 있다. 참고로 클래스는 데이터나 처리의 정의 등을 하나로 정리해둔 모형과 같은 것이다. 클래스를 사용하지 않고 함수 작성한다면 보통 다음과 같이 작성한다. def some_function(something): print(something) 그러나 클래스를 이용한다면 기본적으로 다음과 같이 작성하게 된다. class Someclass: def __init__(self, something): self.something = something def some_function(self): print(self.something) 클래스 구성을 사용하는 메리트는 다음과 같다고 할 수 있다. 글로벌..
Python 기본 (2022/01/12)
·
Study/Python
def : function을 정의할 때 :를 이용하여 작성 python은 항상 tab을 잘 이용해야 한다 들여쓰기가 문법을 결정 짓기 때문이다 def say_hello(who): print("hello", who) say_hello("Jimin") def plus(a,b): print(a + b) def minus(a,b): print(a - b) plus(2, 3) minus(2, 3) def say_hello(name = "annoymous"): print("hello",name) say_hello() say_hello("Jimin") def p_plus(a, b): print(a + b) def r_plus(a, b): return a + b p_result = p_plus(2,3) r_result..