
[Python] class
·
기타
파이썬의 class는 객체 지향 프로그래밍 (OOP)의 기본 요소로, 데이터 및 메소드를 하나의 모듈로 묶는 데 사용됩니다. 클래스는 객체를 정의하는 틀이며, 객체는 클래스에서 정의한 데이터와 함수의 집합입니다. # 클래스 정의 class Car: # 멤버 변수 color = "" brand = "" # 생성자 def __init__(self, color, brand): self.color = color self.brand = brand # 메소드 def drive(self): print("{} {}를 운전합니다.".format(self.color, self.brand)) # 클래스 생성 my_car = Car("빨간색", "소나타") # 메소드 호출 my_car.drive() # 결과값 # 빨간색 소나..