effective python 클래스와 인터페이스
📌 클래스 와 인스턴스
보통 클래스를 빵틀이라고 많이 설명을 하게되고 ,
이 빵틀에서 찍어내는것을 Object
라하고 인스턴스라고도 한다.
그러면 Object(객체)
는 무엇일까 ??
프로그래밍에서 객체는 어떠한 속성과 행위를 가지고있는것을 객체라고 한다.
속성 + 행위 = 객체
class Person:
def __init__(self , name):
self.name = name
def say_hello(self):
print("hi my name is " + self.name)
person1 = Person("원빈")
person2 = Person("장동건")
person3 = Person("정지훈")
person1.say_hello()
👉 상속
class Person:
def __init__(self , name , age):
self.name = name
self.age = age
def say_hello(self):
print("hi my name is " + self.name)
class Police(Person):
def arrest(self , to_arrest):
print("체포한다."+to_arrest)
class Programmer(Person):
def program(self , to_program):
print("프로그래밍"+to_program)
person1 = Person("person1",20)
person2 = Police("person2",21)
person3 = Programmer("person3",22)
person1.say_hello()
person2.say_hello()
person2.arrest("person1")
person3.say_hello()
person3.program("python")
좀더 파일을 나눠 볼까 ??
Person.py
main.py
Author And Source
이 문제에 관하여(effective python 클래스와 인터페이스), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@ash3767/effective-python-클래스와-인터페이스저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)