Development/Python
2BPerfect...6
Kirok Kim
2022. 1. 24. 15:28
κ°μ²΄μ ν΄λμ€
## μ μ λ©μλ
μ μ λ©μλλ ν΄λμ€μ κ΄λ ¨μ΄ μμ΄μ ν΄λμ€ μμ λκΈ°λ νμ§λ§ ν΄λμ€λ
ν΄λμ€μ μΈμ€ν΄μ€μλ 무κ΄νκ² λ
립μ μΌλ‘ λμνλ ν¨μλ₯Ό λ§λ€κ³ μΆμλ μ΄μ©
ν¨μλ₯Ό μ μν λ μΈμλ‘ selfμ¬μ© x μ μ λ©μλ μμμ μΈμ€ν΄μ€ λ©μλλ
λ³μμ μ κ·Όν μ μλ€. ν¨μ μμ λ°μ½λ μ΄ν°μΈ @staticmethodλ₯Ό μ μΈνμ¬ μ μ λ©μλ νν
class Car():
def __init__(self,size,color):
def move(self,speed):
def auto_cruise(self):
## μ μ λ©μλ μμ
@staticmethod
def check_type(model_code):
if(model_code>=20):
print('μ΄ μλμ°¨λ μ κΈ°μ°¨μ
λλ€.')
elif(10<=model_code<20):
print('μ΄ μλμ°¨λ κ°μλ¦°μ°¨μ
λλ€.')
else:
print('μ΄ μλμ°¨λ λμ €μ°¨μ
λλ€.')
## ν΄λμ€ λ©μλ
@classmethod
def count_instance(cls):
print('μλμ°¨ κ°μ²΄μ κ°μ :{0}'.format(cls.instance_count))
ν΄λμ€ λ©μλλ ν΄λμ€ λ³μλ₯Ό μ¬μ©νκΈ° μν ν¨μ
ν΄λμ€ λ©μλλ ν¨μλ₯Ό μ μν λ 첫 λ²μ§Έ μΈμλ‘ ν΄λμ€λ₯Ό λ겨λ°λ clsκ° νμ
ν΄λμ€ λ©μλλ₯Ό μ¬μ©νκΈ° μν΄μλ @classmethodλ₯Ό μ§μ ν΄μΌν¨
ν΄λμ€ λ©μλλ μμ±λ κ°μ²΄μ κ°μλ₯Ό λ°ννλ λ± ν΄λμ€ μ 체μμ κ΄λ¦¬ν΄μΌ ν κΈ°λ₯μ΄ μμ λ
μ£Όλ‘ μ΄μ©
λ°μν