💻 keep going
갈수록 너무 어렵고 잘 할 수 있을지, 끝까지 할 수 있을지 모르겠지만 그냥 해보자.
ex)
class CalculatorSuper:
def add(self, n1, n2):
return n1 + n2
def sub(self, n1, n2):
return n1 - n2
class CalculatorChild(CalculatorSuper):
def mul(self, n1, n2):
return n1 * n2
def div(self, n1, n2):
return n1 / n2
cal = CalculatorChild()
print(f"cal.add(10,10) : {cal.add(10, 20)}")
print(f"cal.sub(10,10) : {cal.sub(10, 20)}")
print(f"cal.mul(10,10) : {cal.mul(10, 20)}")
print(f"cal.div(10,10) : {cal.div(10, 20)}")
기능 같은 경우에는 상속만 하면 사용할 수 있지만 속성은
__init__
메소드를 호출해야한다.
실습 :
class BasicCalculator:
def add(self, n1, n2):
return n1 + n2
def sub(self, n1, n2):
return n1 - n2
def mul(self, n1, n2):
return n1 * n2
def div(self, n1, n2):
return n1 / n2
class DeveloperCalculator:
def mod(self, n1, n2):
return n1 % n2
def flo(self, n1, n2):
return n1 // n2
def exp(self, n1, n2):
return n1 ** n2
class NewCalculator(BasicCalculator, DeveloperCalculator):
def __init__(self):
pass
cal = NewCalculator()
@ abstractmethod
적용된 함수는 반드시 구현을 해줘야함 상속받은 클래스에서.
import time
lt = time.localtime()
dateStr = "[" + str(lt.tm_year) + "년" + str(lt.tm_mon) + "월" + \
str(lt.tm_mday) + "일]"
todaySchedule = input("오늘 일정 : ")
file = open("C:/pythonTxt/new.txt", "w")
file.write(dateStr + todaySchedule)
file.close()
- 마지막에 꼭 닫아주기 👉 .close()
- 내용은 계속 덮어 씌워진다.
- 방향 /로 꼭 바꿔주기 👉 C:/pythonTxt/
file = open("C:/pythonTxt/test.txt", "r", encoding="UTF8")
👉encoding="UTF8"
: 인코등 오류 날경우 사용 (cp949 Error)
✔ str.replace("Python", "파이썬", 2)
👉 Python 을 파이썬으로 2번째까지 변경
✔ print(f"공과금 : {utilily.getUtilityBill():,.0f}원")
👉f"" 함수에서 :,.0f
= 1000단위씩 ,
적용