본문 바로가기

분류 전체보기402

Class 출처 : https://www.pythontutorial.net/python-oop/python-class/ Objects 개체는 data(데이터)와 functionality(기능)을 포함하는 컨테이너입니다. 데이터는 특정 시점의 개체를 나타냅니다. 따라서 객체의 데이터를 state(상태)라고합니다. 파이썬은 attributes(속성)을 사용하여 객체의 상태를 모델링합니다. 기능은 개체의 behavior(동작)을 나타냅니다 . 파이썬은 함수를 사용하여 동작을 모델링합니다. 함수가 객체와 연관되면 객체의 메소드가됩니다. 즉, 개체는 상태와 메서드를 포함하는 컨테이너입니다. objects를 만들기 전에 먼저 클래스를 정의합니다. 그리고 클래스에서 하나 이상의 개체를 만들 수 있습니다. 클래스의 개체는 클래스.. 2023. 4. 2.
Callable Introduction to Python callables () 연산자를 사용하여 A 객체가 호출 될 수 있는 경우, A는 callable이다. A() 예를 들어, 함수 와 메서드는 callable이다. Python에서는 다른 많은 object도 callable이다. Callable은 항상 값을 반환합니다. 객체가 호출 가능한지 확인하려면 built-in(내장 함수) callable을 사용할 수 있습니다.(반환값 : bool) callable(object) -> bool Python callable function examples 다음은 Python에서 호출 가능한 다양한 유형의 객체를 보여줍니다. 1) built-in functions Built-in function는 callable이다. 예를 들어,.. 2023. 4. 2.
Object-oriented Programming Introduction to Python Object-oriented Programming 파이썬의 모든 것은 object(개체)입니다. 개체에는 state(상태), behaviors(동작)이 있습니다. 개체를 만들려면 먼저 클래스를 정의합니다. 그런 다음 클래스에서 하나 이상의 개체를 만들 수 있습니다. 개체는클래스의 인스턴스입니다. Define a class 클래스를 정의하려면 class 키워드 뒤에 클래스 이름을 사용합니다. 예를 들어, 다음은 Person 클래스를 정의합니다. class Person: pass Person 클래스에서 객체를 만들려면 함수를 호출하는 것처럼 클래스 이름 뒤에 괄호 ()를 사용합니다. person = Person() 이 예제에서 person은 Person 클래스의 인스.. 2023. 4. 2.
Property Decorator Introduction to the Python property decorator 이전 자습서에서는 property class를 사용하여 클래스에 property을 추가하는 방법을 배웠습니다. property class의 구문은 다음과 같습니다. class property(fget=None, fset=None, fdel=None, doc=None) class 정의 class Person: def __init__(self, name, age): self.name = name self.age = age age 속성에 대한 getter를 정의하기위 다음과 같이 property class를 사용합니다. class Person: def __init__(self, name, age): self.name = name.. 2023. 4. 1.
Metaclass Example Introduction to the Python metaclass example 다음은 name, age라는 속성이 있는 Person 클래스를 정의합니다. class Person: def __init__(self, name, age): self.name = name self.age = age @property def name(self): return self._name @name.setter def name(self, value): self._name = value @property def age(self): return self._age @age.setter def age(self, value): self._age = value def __eq__(self, other): return self.name.. 2023. 4. 1.
Metaclass Introduction to the Python Metaclass 메타 클래스는 다른 클래스를 만드는 클래스입니다. 기본적으로 Python은 메타클래스 type 을 사용하여 다른 클래스를 만듭니다. 예를 들어, 다음은 Person 클래스를 정의합니다. class Person: def __init__(self, name, age): self.name = name self.age = age 파이썬은 코드를 실행할 때 type 메타 클래스를 사용하여 Person 클래스를 만듭니다. 그 이유는 Person 클래스가 기본적으로 메타 클래스 type을 사용하기 때문입니다. 명시적인 Person 클래스 정의는 다음과 같습니다. class Person(object, metaclass=type): def __init__.. 2023. 4. 1.
type Class Introduction to the Python type class 파이썬에서 class는 class type의 객체입니다. 예를 들어, 다음은 두 가지 메서드 __init__ 및 greeting을 사용하여 Person 클래스를 정의합니다. class Person: def __init__(self, name, age): self.name = name self.age = age def greeting(self): return f'Hi, I am {self.name}. I am {self.age} year old.' Person 클래스는 다음 문과 같이 class type의 개체입니다. print(type(Person)) Output: Person 클래스는 class type의 인스턴스입니다. print(i.. 2023. 4. 1.
Abstract Class Introduction to Python Abstract Classes 객체 지향 프로그래밍에서 추상 클래스는 인스턴스화할 수 없는 클래스 입니다. 그러나 추상 클래스를 상속하는 클래스를 만들 수 있습니다. 일반적으로 추상 클래스를 사용하여 다른 클래스에 대한 청사진을 만듭니다. 마찬가지로 추상 메서드는 구현이 없는 메서드입니다. 추상 클래스는 추상 메서드를 포함하거나 포함하지 않을 수 있습니다. Python은 추상 클래스를 직접 지원하지 않습니다. 그러나 추상 클래스를 정의할 수 있는 모듈을 제공합니다 . 추상 클래스를 정의하려면 abc(추상 기본 클래스) 모듈을 사용합니다. 이 abc모듈은 추상 기본 클래스를 정의하기 위한 인프라를 제공합니다. from abc import ABC class Abstr.. 2023. 3. 31.
super() Method Introduction to the Python super super() 명령어는 상속 관계에서 대상의 부모 클래스를 반환하는 함수 구문 super(대상클래스_이름, 대상클래스_object) # Class 선언 내부에서 super를 호출하면, 인자 전달을 따로 하지 않아도 자동으로 해당 클래스의 부모 클래스를 호출해줍니다. 참조 Code class Employee: def __init__(self, name, base_pay, bonus): self.name = name self.base_pay = base_pay self.bonus = bonus def get_pay(self): return self.base_pay + self.bonusCode class SalesEmployee(Employee): .. 2023. 3. 31.