Constructor
Constructor
μμ±μ (Constructor)
class ν΄λμ€λͺ
:
def __init__(self):
λ¬Έμ₯class example:
def __init__(self, sentence):
self.name = sentence
print("κ°μ²΄κ° μμ±: " + sentence + "μ
λλ€.")
object= example("μ¬κ³Ό") # κ°μ²΄κ° μμ±: μ¬κ³Όμ
λλ€.class Student:
def __init__(self, name, age):
self.name = name
self.age = age
def introduction(self):
print("μ μ΄λ¦μ " + self.name + "μ΄λ©°, μ λμ΄λ " + str(self.age) + "μ΄μ
λλ€.")
objectStudent = Student("μλΉ", 28)
objectStudent.introduction() # μ μ΄λ¦μ μλΉμ΄λ©°, μ λμ΄λ 28μ΄μ
λλ€.μλ©Έμ (Destructor)
Last updated