이 영역을 누르면 첫 페이지로 이동
BIBISUNG 블로그의 첫 페이지로 이동

BIBISUNG

페이지 맨 위로 올라가기

BIBISUNG

IT/재테크/문화/일상 주제로 같이 얘기 나눠요

A deposit and withdrawal programming(입/출금 프로그램)

  • 2019.01.08 20:34
  • Python
글 작성자: 성비비
  • Object orientation 
def person_init(name, money):
	obj = {'name': name, 'money': money}
	obj['give_money'] = Person[1]
	obj['get_money'] = Person[2]
	obj['show'] = Person[3]
	return obj

def give_money(self, other, money):
	self['money'] -= money
	other['get_money'](other, money)

def get_money(self, money):
	self['money'] += money

def show(self):
	print('{} : {}'.format(self['name'], self['money']))

Person = person_init, give_money, get_money, show

if __name__ == "__main__":
	g = Person[0]('greg', 5000)
	j = Person[0]('john', 2000)
	
	g['show'](g)
	j['show'](j)
	print('')

	g['give_money'](g, j, 2000)
	
	g['show'](g)
	j['show'](j)
  • Object orientation using class

class Person:
	def __init__(self, name, money):
		self.name = name
		self.money = money
	
	def give_money(self, other, money):
		self.money -= money
		other.get_money(money)
		
	def get_money(self, money):
		self.money += money
		
	def show(self):
		print('{} : {}'.format(self.name, self.money))
		
if __name__ == "__main__":
	g = Person('greg', 5000)
	j = Person('john', 2000)
	
	g.show()
	j.show()
	
	g.give_money(j, 2000)
	print('')
	
	g.show()
	j.show()

Can you see the difference?

저작자표시 비영리 동일조건 (새창열림)

'Python' 카테고리의 다른 글

Monitor Windows CLI-based processes  (0) 2017.01.11

댓글

이 글 공유하기

  • 구독하기

    구독하기

  • 카카오톡

    카카오톡

  • 라인

    라인

  • 트위터

    트위터

  • Facebook

    Facebook

  • 카카오스토리

    카카오스토리

  • 밴드

    밴드

  • 네이버 블로그

    네이버 블로그

  • Pocket

    Pocket

  • Evernote

    Evernote

다른 글

  • Monitor Windows CLI-based processes

    Monitor Windows CLI-based processes

    2017.01.11
다른 글 더 둘러보기

정보

BIBISUNG 블로그의 첫 페이지로 이동

BIBISUNG

  • BIBISUNG의 첫 페이지로 이동

검색

메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

카테고리

  • 분류 전체보기 (99)
    • 성비비 일상 (16)
    • 해외주식 (0)
      • 수익인증 (0)
      • 종목분석 (0)
    • 물생활 (0)
    • 군대 (5)
    • 영어회화 (12)
      • OPIc (11)
    • 자격증 (6)
    • Python (2)
    • 정보보안 (14)
      • 디지털 포렌식 (9)
      • Wargames (5)
    • /dev/null (11)
    • 걷다, 보다 (32)
      • 시네마천국 (29)
      • 공연·전시·축제 (3)

정보

성비비의 BIBISUNG

BIBISUNG

성비비

블로그 구독하기

  • 구독하기
  • 네이버 이웃 맺기
  • RSS 피드

방문자

  • 전체 방문자
  • 오늘
  • 어제

티스토리

  • 티스토리 홈
  • 이 블로그 관리하기
  • 글쓰기
Powered by Tistory / Kakao. © 성비비. Designed by Fraccino.

티스토리툴바