본문 바로가기

Language/Python12

[Python] Decorator [Python] Decorator Decorator - Decorator : 기존 코드에 여러 기능을 덧댈 수 있는 함수 - annotation을 이용하여 사용한다. - def 함수명(func):def wrapper(): 의 형태를 갖추고 있다.12345678910111213141516171819202122232425262728#-*- coding: utf-8 -*-''' - decorator 학습하기'''def helloBye(func): def wrapper(): print "hello" # helloBye 의 인자로 전달된 함수를 호출 func() print "bye" return wrapper @helloByedef f1(): print u"f1() 함수를 수행했습니다." def f2(): pri.. 2017. 8. 16.
[Python] Extends / super [Python] Extends / superExtends 상속 - python에서 상속은 class 클래스명(상속받을 클래스명)으로 작성해준다. - 28 : 메소드 재정의(오버라이딩) - 40 : HandPhone에서 call메소드를 정의하지 않았어도 상속으로 인해 이용할 수 있다. 1234567891011121314151617181920212223242526272829303132333435363738394041424344#-*- coding: utf-8 -*-''' 상속 class 클래스명(상속받을 클래스명): pass'''class Phone(object): #전화 거는 기능 def call(self): print u"전화를 걸어요" # Phone 클래스를 상속 받아서 클래스 정의하기class Han.. 2017. 8. 16.
[Python] Main / class / 생성자 / return [Python] Main / class / 생성자 / return Main 이용하기 * main - 05 : import를 하면 각 모듈이 적용된다. - 11 : __name__은 해당 모듈의 이름을 출력해준다. - 17 : 메인 메소드는 if __name__="__main__": 을 이용한다. - 19, 20 : 각 모듈의 메소드 이용 1234567891011121314151617181920#-*- coding: utf-8 -*- # Step13_main.py import MyModule, YourModuleprint "----" #print "MyModule.nick : ", MyModule.nick#MyModule.printNick() print "Step13_main.py __name__:", _.. 2017. 8. 16.
[Python] 정규표현식(Regulation Express) / input [Python] 정규표현식(Regulation Express) / input 정규표현식 - 07 : import re 를 해서 사용한다. (regulation express 줄임) - 22 : ^who : who로 시작하는 문장을 찾는다. - 18 : re.search를 이용해 문자열을 검증하고 bool type으로 받아본다. - 35 : findall은 내장된 모든 해당 문자열 검증하여 list type으로 반환. - 46 : \(역슬레시)를 붙이면 온전한 그 문자를 나타낸다. - 47 : \^ = 문자 ^, \$ = 문자 $ 등 - 54 : [가-힝] : 한글에 해당하는 모든 문자열 찾기 - 59 : [가-힝]+ : 연속된 한글 문자열 찾기 - 67 : [a-zA-Z0-9] : 특수문자 허용하지 않기.. 2017. 8. 16.