#1 ๋ค์๊ณผ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑํ์๋, ์คํ๊ฒฐ๊ณผ๋ก ์๋ง์ ๊ฒ์? 5๋ฒ
class Bit(object):
def __init__(self):
self.__password = 5678
def set_password(self,new_pw):
self.__password = new_pw
print('Passwird changed')
def get_password(self):
print('Your password is :',self.__password)
coin = Bit()
coin.get_password()
coin.set_password(1234)
print(coin.__password)
#2 ๋ค์๊ณผ ๊ฐ์ ์ฝ๋๋ ๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋จ์ ์ด๋ค ํน์ง์ ๋ณด์ฌ์ฃผ๋์ง ๊ณ ๋ฅด์์ค. 3๋ฒ (์์)
class Class(object):
def __init__(self,name,score):
self.name = name
self,score = score
class Math(Class):
def say():
print('ํ๋ด')
#3 ๋ค์๊ณผ ๊ฐ์ด ์ฝ๋๋ฅผ ์์ฑํ์ ๋, ์คํ ๊ฒฐ๊ณผ๋ก ์๋ง์ ๊ฒ์? 5
class Marvel(object):
def __init__(self,name,characteristic):
self.name = name
self.characteristic =characteristic
def __str__(self):
return "My name is {0} and my weapon is {1}".format(self.name,self.characteristic)
class Villain(Marvel):
pass
first_villain = Villain('Thanos','infinity gaunetlet')
print(first_villain)
4๋ฒ ์ ๋ต : 5๋ฒ
#5 ๋ค์ ์ฝ๋์ ์คํ ๊ฒฐ๊ณผ๋ฅผ ์ฐ์์ค.
class IceCream(object):
def __init__(self,flavor):
self.flavor = flavor
def change_flavor(self,new_flavor):
print('์์ด์คํฌ๋ฆผ์ %s์์ %s๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์'%(self.flavor,new_flavor))
self.flavor=new_flavor
print('์์ด์คํฌ๋ฆผ ๋ง์ %s๋ก ๋ณ๊ฒฝํด๋๋ ธ์ด์'%self.flavor)
ice_cream = IceCream('๋ ์ธ๋ณด์ฐ ์ค๋ฒ ํธ')
ice_cream.change_flavor('๋ฐ๋๊ณผ ํจ๊ป ์ฌ๋ผ์ง๋ค')
์ ๋ต : ์์ด์คํฌ๋ฆผ์ ๋ ์ธ๋ณด์ฐ ์ค๋ฒ ํธ์์ ๋ฐ๋๊ณผ ํจ๊ป ์ฌ๋ผ์ง๋ค๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์
์์ด์คํฌ๋ฆผ ๋ง์ ๋ฐ๋๊ณผ ํจ๊ป ์ฌ๋ผ์ง๋ค๋ก ๋ณ๊ฒฝํด๋๋ ธ์ด์
#6 ๊ฐ์ฒด์งํฅํ์ ํน์ง 3๊ฐ์ง๋ฅผ ๊ฐ๋จํ ์์ ํ์์ค
1. ์์ : ๋ถ๋ชจ ํด๋์ค์ ์ ์๋ ์์ฑ๊ณผ ๋งค์๋๋ฅผ ์์ ํด๋์ค๊ฐ ๋ฌผ๋ ค๋ฐ์ ์ฌ์ฉํ๋
2. ๋คํ์ฑ : ๊ฐ์ ์ด๋ฆ์ ๋งค์๋๊ฐ ๋ค๋ฅธ ๊ธฐ๋ฅ์ ํ๋ ๊ฒ
3. ๊ฐ์์ฑ : ๊ฐ์ฒด์ ์ ๋ณด๋ฅผ ๋ณผ ์ ์๋ ๋ ๋ฒจ์ ์กฐ์ ํ์ฌ ๊ฐ์ฒด์ ์ ๋ณด ์ ๊ทผ์ ์จ๊ธฐ๋ ๊ฒ์ ๋งํจ
'๐ ์คํฐ๋ > ํ์ด์ฌ ์คํฐ๋ ๊ณผ์ ์ ์ถ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[4ํ/๊น์ค] 8์ฐจ์ ํ์ด์ฌ ๊ณผ์ - ๊ฐ์ฒด์งํฅ (0) | 2023.05.19 |
---|---|
[2ํ/์ด์ ์ง] 8์ฐจ์ ํ์ด์ฌ ๊ณผ์ - ๊ฐ์ฒด ์งํฅํ ๊ณผ์ (0) | 2023.05.19 |
[1ํ/์ด๋์ฐ] 7์ฐจ์ ํ์ด์ฌ๊ณผ์ - ์๋ฃ๊ตฌ์กฐ (0) | 2023.05.18 |
[4ํ/๊น์ ๊ฒฝ] 7์ฐจ์ ํ์ด์ฌ ๊ณผ์ - ์๋ฃ๊ตฌ์กฐ (1) | 2023.05.17 |
[1ํ / ๊ถ๋จ์] 7์ฐจ์ ํ์ด์ฌ ๊ณผ์ - ์๋ฃ๊ตฌ์กฐ (0) | 2023.05.17 |