티스토리 뷰
python/Data Science
(macOS)[python] Class : public, protected, private, inheritance
jinozpersona 2020. 3. 2. 15:241. class 생성 : Naming
public
# public
class Naming:
def __init__(self,head,tail):
self.head = head
self.tail = tail
def get_name(self,head_name,tail_name):
self.head = head_name
self.tail = tail_name
def get_info(self):
print(self.head, self.tail)
def __del__(self):
print('Name object is deleted')
# Use class
object = Naming(head,tail)
# Use delete
del object
protected : single underscore
# protected
class Naming:
def __init__(self,head,tail):
self._head = head
self._tail = tail
def get_name(self,head_name,tail_name):
self._head = head_name
self._tail = tail_name
def _set_name(self,head_name,tail_name):
self._head = head_name
self._tail = tail_name
def get_info(self):
print(self._head, self._tail)
def __del__(self):
print('Name object is deleted')
private : double underscore
# private
class Naming:
def __init__(self,head,tail):
self.__head = head
self.__tail = tail
def get_name(self,head_name,tail_name):
self.__head = head_name
self.__tail = tail_name
def __set_name(self,head_name,tail_name):
self.__head = head_name
self.__tail = tail_name
def get_info(self):
print(self.__head, self__.tail)
def __del__(self):
print('Name object is deleted')
2. class inheritance(상속)
import os
class MakeNaming(NamingDir):
def make_name(self,head_name,tail_name):
self.head = head_name
self.tail = tail_name
반응형
'python > Data Science' 카테고리의 다른 글
(macOS)[python] 파일이름 encoding, 한글 자모분리 해결 (0) | 2022.02.27 |
---|---|
(macOS)[python] 기상청 RSS 서비스를 이용한 데이터 parsing (0) | 2021.02.15 |
(macOS)[python] IP address 확인 : Public/Pravate(Virtual) (0) | 2021.02.15 |
(macOS)[python] crawling, scraping, parsing 용어 - 1 (0) | 2021.02.10 |
[Book_Fluent Python] 2장 시퀀스 : 지능형 리스트, 제너레이터 (0) | 2020.02.26 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 코로나19
- Raspberry Pi
- Pandas
- analysis
- CSV
- Django
- vscode
- ERP
- git
- Python
- 코로나
- DS18B20
- github
- pyserial
- raspberrypi
- template
- Regression
- MacOS
- SSH
- arduino
- Model
- COVID-19
- sublime text
- r
- 확진
- 자가격리
- DAQ
- server
- 라즈베리파이
- Templates
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함