Programming/Python
2019.11.05
class Parent: def can_sing(self): print('Sing a song') class LuckyChild(Parent): pass class UnluckyChlid: pass class LuckyChild2(Parent): def can_dance(self): print('Shuffle Dance') father = Parent() father.can_sing() child = LuckyChild() child.can_sing() child2 = UnluckyChlid() print(child.__dir__()) print(child2.__dir__()) child3 = LuckyChild2() child3.can_dance() child3.can_sing() 실행결과 $ py i..
Programming/Python
2019.11.05
class BusinessCard: def __init__(self): self.name = 'empty' self.email = 'empty' self.addr = 'empty' def set_info(self, name, email, addr): self.name = name self.email = email self.addr = addr def show_info(self): print('-'*30) print('Name: ', self.name) print('E-mail: ', self.email) print('Address: ', self.addr) print('-'*30) card = BusinessCard() card.show_info() card.set_info('JohnMark','prac..
Programming/Python
2019.11.05
class Account: num_accounts = 0 def __init__(self, name): self.name = name Account.num_accounts +=1 def __del__(self): Account.num_accounts -=1 kim = Account('Chang') lee = Account('Kim') print(kim.name) print(lee.name) print(kim.num_accounts) 실행결과 $ py class_instance.py Chang Kim 2
Programming/Python
2019.11.05
class BusinessCard: def set_info(self, name, email, addr): self.name = name self.email = email self.addr = addr def show_info(self): print('-'*30) print('Name: ', self.name) print('E-mail: ', self.email) print('Address: ', self.addr) print('-'*30) val = BusinessCard() val.set_info('JohnMark','practice1356@gmail.com','Seoul Mapo') print(val) print() val.show_info() 실행결과 $ py basic.py ------------..
Programming/Python
2019.11.05
# list using '[' or ']' keyword for generating list object # but tuple use '(' or ')' keyword. And tuple is can't change elements after generated. # tuple is more faster than list # generate tuple object t = ('SAMSUNG', 'LG', 'SK') print(t) # Also tuple is use index for access elements. print(t[0]) print(t[1]) print(t[2]) # test: change element value # It will be comes up some error message. t[0..
Programming/Python
2019.11.05
t = ('SAMSUNG', 'LG', 'SK') # tuple use '[' or ']' keyword for slicing. # Be careful do not confuse between '(',')' and '[',']' keywords. print(t[0:2]) # if you use '(',')' keyword for slicing. error message is appeared. print(t(0: 2)) 실행결과 $ py tuple_indexing.py File "tuple_indexing.py", line 8 print(t(0: 2)) ^ SyntaxError: invalid syntax
Programming/Python
2019.11.05
kospi_top10 = ['삼성전자', 'SK하이닉스', '현대차', '한국전력', '아모레퍼시픽', '제일모직', '삼성전자우', '삼성생명', 'NAVER', '현대모비스'] print("시가총액 5위: ", kospi_top10[4]) print("시가총액 1~5위: ", kospi_top10[0:4]) print("시가총액 6위부터 하위까지: ", kospi_top10[5:]) print(kospi_top10[:5]) print(kospi_top10[5:9]) print(kospi_top10[5:-1]) print(kospi_top10[:-1]) 실행결과 시가총액 5위: 아모레퍼시픽 시가총액 1~5위: ['삼성전자', 'SK하이닉스', '현대차', '한국전력'] 시가총액 6위부터 하위까지: ['..
Programming/Python
2019.11.05
kospi_top10 = ['삼성전자', 'SK하이닉스', '현대차', '한국전력', '아모레퍼시픽', '제일모직', '삼성전자우', '삼성생명', 'NAVER', '현대모비스'] kospi_top10.append("SK텔레콤") print(len(kospi_top10)) # remove specific item in the list using by 'del' keyword del kospi_top10[-1] print(len(kospi_top10)) print(kospi_top10) 실행결과 $ py list_remove.py 11 10 ['삼성전자', 'SK하이닉스', '현대차', '한국전력', '아모레퍼시픽', '제일모직', '삼성전자우', '삼성생명', 'NAVER', '현대모비스']