분류 전체보기408 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. Static Methods https://www.pythontutorial.net/python-oop/python-static-methods/ Python Static Methods Explained Clearly By Practical Examples In this tutorial, you'll learn about Python static methods and how to use define utility methods for a class. www.pythontutorial.net Introduction to Python static methods instance method는 바인딩된 개체의 상태에 액세스하고 수정할 수 있다. class method는 클래스 상태에 액세스하고 수정할 수 있습니다. static method는.. 2023. 3. 31. __new__() Method https://www.pythontutorial.net/python-oop/python-__new__/ Python __new__ In this tutorial, you'll learn about the Python __new__ method and understand how Python uses it to create a new object. www.pythontutorial.net 파이썬 __new__ 메서드 소개 1. 클래스의 인스턴스를 만들 때 Python은 먼저 __new__() method를 호출하여 객체를 생성한 다음 __init__() method를 호출하여 객체의 속성을 초기화합니다. 2. __new__()는 object Class 의 static method입니다. 3. [수동 객체 생.. 2023. 3. 31. [ OOP ] Index CLASSES & OBJECTS Python Object-oriented Programming - callable Class Class Variables 함수& Methods __init__: Initializing Instance Attributes Instance Variables Private Attributes Class Attributes Static Methods - class methods SPECIAL METHODS __str__ __repr__ __eq__ __hash__ __bool__ __del__ PROPERTY Property @property Decorator Readonly Property Delete Property SINGLE INHERITANCE Inheritance Ov.. 2023. 3. 31. 이전 1 ··· 20 21 22 23 24 25 26 ··· 46 다음