250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- db
- 이력서
- tomoto
- spring MVC(모델2)방식
- 토픽추출
- java
- 게시판 만들기
- 네이버뉴스
- 幼稚园杀手(유치원킬러)
- Topics
- 코사인 유사도
- Websocket
- 지마켓
- lda
- mysql
- 파이썬
- (깃)git bash
- Gmarket
- RESFUL
- jsp 파일 설정
- 자바
- r
- 방식으로 텍스트
- oracle
- word2vec
- Python
- 크롤링
- test
- 과학백과사전
- pytorch
Archives
- Today
- Total
무회blog
Python # 파이썬 + - * / 연산을 할수 있는 클래스 (파이썬클래스) + 상속 본문
# 파이썬 + - * / 연산을 할수 있는 클래스
class FourCal:
def __init__(self, first, second):
self.first = first
self.second = second
# def setdata(self,first,second):
# self.first = first
# self.second = second
def add(self):
result = self.first + self.second
return result
def mul(self):
result = self.first * self.second
return result
def sub(self):
result = self.first - self.second
return result
def div(self):
result = self.first / self.second
return result
a = FourCal(5,2)
# a.setdata(8,2)
# print(a.first) # a 객체에 first 변수가 추가됨
# print(id(a.first)) # id 내장함수가 저장됨
# b = FourCal()
# b.setdata(7,3)
# print(b.first)
# print(id(b.first))
print(a.add())
print(a.mul())
print(a.sub())
print(a.div())
print(a.add() + a.mul())
상속 방식
class MoreFourCal(FourCal): #FourCal 클래스를 상속하는 MoreFourCal 클래스
def pow(self):
result = self.first ** self.second
return result
a = MoreFourCal(4, 2)
print(a.add()) #상속받은 FourCal 클래스의 기능을 모두 사용할 수 있음을 확인할 수 있다.
print(a.pow()) # a의 b제곱(ab)을 계산하는 MoreFourCal 클래스
'Python' 카테고리의 다른 글
win10 EKL 셋팅방법 (0) | 2020.05.11 |
---|---|
python: 파이썬(python) mod1.py 파일쓰기 (open함수_import) (0) | 2020.05.07 |
python: python 파이썬 # html 태그 제거 (0) | 2020.04.26 |
python: 파이썬 특정 문자 개수 세어 보기 (0) | 2020.04.26 |
requets Beautiful Soup 로 네이버 실시간 검색어 크롤링(스크래핑) 하기 (2) | 2020.04.25 |
Comments