
간단히 말하여 객체를 실체화하기 위한 틀
클래스class를 설계도라 했을 때, 속성attribute은 객체의 구성이고, 메서드method는 설계도 안에서의 동작, 객체object는 설계도를 통해 만드려고 하는 것, 인스턴스instance는 설계도를 통해 실제로 만들어낸 것
🔽아래는 조금 더 명확한 용어 구분을 위해 Chat GPT에게 부탁한 예문
class Animal:
# Class attribute: Shared among all instances of the class
kingdom = "Animalia" # All animals belong to the Animalia kingdom
# Initializer
def __init__(self, name, species):
# Instance attributes: Unique to each instance
self.name = name # The name of the animal
self.species = species # The species of the animal
# Method to introduce the animal
def introduce(self):
# Accessing both instance attributes and the class attribute
return (f"Hi, I am {self.name}, a {self.species} from the {Animal.kingdom} kingdom.")
# Create objects (instances of the Animal class)
dog = Animal("Buddy", "Dog") # Instance attributes: name = "Buddy", species = "Dog"
cat = Animal("Whiskers", "Cat") # Instance attributes: name = "Whiskers", species = "Cat"
# Accessing and printing class and instance attributes
print(dog.introduce()) # Output: Hi, I am Buddy, a Dog from the Animalia kingdom.
print(cat.introduce()) # Output: Hi, I am Whiskers, a Cat from the Animalia kingdom.
# Accessing the class attribute directly from the class
print(Animal.kingdom) # Output: Animalia
# Accessing the class attribute from an instance
print(dog.kingdom) # Output: Animalia
print(cat.kingdom) # Output: Animalia
네임스페이스(namespace, 이름공간)란 프로그래밍 언어에서 특정한 객체(Object)를 이름(Name)에 따라 구분할 수 있는 범위를 의미한다. 파이썬 내부의 모든것은 객체로 구성되며 이들 각각은 특정 이름과의 매핑 관계를 갖게 되는데 이 매핑을 포함하고 있는 공간을 네임스페이스라고 한다.
네임스페이스가 필요한 이유는 다음과 같다. 프로그래밍을 수행하다보면 모든 변수 이름과 함수 이름을 정하는 것이 중요한데 이들 모두를 겹치지 않게 정하는 것은 사실상 불가능하다출처 https://hcnoh.github.io/2019-01-30-python-namespace

character1.skills을 추가하여 값을 재출력한 뒤에도 클래스속성 값이 변하지 않은 것을 보아 클래스속성은 인스턴스속성에 영향을 받지 않는 다는 것과 character1.skills을 추가하기 위해 불러온 값이 클래스속성인 skills가 아니라 add.skill 메서드의 self.skills임을 알 수 있다. 그렇다면 생성자 __init__의 역할은 무엇일까?
눈으로 확인해보기 위해 character2 인스턴스를 생성하여 확인해보았다.


생성자를 주석처리하니 인스턴스끼리 클래스속성을 공유하여 character1과 2의 skill이 누적되어 출력된 것을 볼 수 있다. 즉, 클래스속성은 모든 인스턴스가 공유하게 되므로 생성자를 사용해 초기값을 설정해주어야 인스턴스가 개별적으로 출력될 수 있다.
부모클래스를 상속 받아 부모클래스의 속성이나 메서드를 사용할 수 있음
말 그대로 상위클래스에서 하위클래스로의 상속을 의미함. 부모님 돈은 내 돈 내 돈도 내 돈..

모듈(Module)이란 프로그램에 필요한 함수, 변수, 클래스 등을 모아놓은 파일
연습문제를 풀며, 내가 쓴 코드와 강사님이 풀이해주신 코드를 비교해보니 10줄도 안되는 짧은 코드에도 단점이 보였다. 변수 이름을 나만 알게 써놓은 점이라던지 굳이 필요없는 코드를 추가해 놓았다던지. 생각하자 생각~!