09 lambda

lambda function

  • lambda function(익명함수)란 말 그대로 이름이 없는 함수이며 파이썬에서는 lambda 라는 키워드로 익명 함수를 정의할 수 있다
    • 주로 비교적 간단한 기능의 함수가 컨테이너의 요소로 들어가는 경우 혹은 다른 함수의 인자로 함수를 넘겨줄 필요가 있을 때 사용됨
    • 데이터 처리 특성 상, 그 함수들은 단순한 작업을 하며 이후 함수를 재활용할 필요가 적기 lambda 함수를 많이 사용함
  • lambda 함수는 다음과 같은 3가지 패턴으로 많이 사용된다.
    1. map: 첫번째 argument로 주어진 함수를 이후의 argument에 적용하는 함수
    2. filter:첫번째 argument로 주어진 함수 값의 True/False인지에 따라 두번째로 주어진 argument의 값을 (True일 경우에) 내보내는 함수
    3. reduce: 첫번째 argument로 주어진 함수 값을 이용해 두번째로 주어진 argument의 1st, 2nd 값을 처리한 결과와 3rd 값을, 그리고 다시 이 결과와 4번째 값을 인자로 하는 형태로 주어진 값의 끝까지 처리하는 함수

Continue reading 09 lambda

08 regular expression

Regular Expression

  • 정규표현식(正規表現式, Regular Expression)은 문자열을 처리하는 방법 중의 하나로 특정한 조건의 문자를 '검색'하거나 '치환'하는 과정을 매우 간편하게 처리 할 수 있도록 하는 수단이다.
  • 정규표현식에서 사용하는 기호를 Meta문자라고 합니다. Meta문자는 표현식 내부에서 특정한 의미를 갖는 문자를 말하며, 중요 Matching Meta문자의 종류로는 다음과 같다.

    • .(dot):줄바꿈 문자를 제외한 모든 문자와 매치됨(the default mode, this matches any character)
    • ^(carot):문자열의 시작과 매치됨(Matches the start of the string)
    • \$:문자열의 마지막과 매치됨(Matches the end of the string)
    • []:"["와"]" 사이의 문자들 중에 하나이어야 함.(Used to indicate a set of characters)
    • '[0-9]', '\d':숫자를 의미
    • '[a-zA-Z]','\w':문자를 의미
  • Python에서는 re모듈을 사용하여 정규표현식을 지원한다.Re docs

  • re모듈의 주요메소드는 다음과 같다.
    • re.compile():pattern을 컴파일하여 정규식 객체를 반환
    • re.match():Sring의 시작부분부터 pattern이 존재하는지 검사하여 객체를 반환
    • re.search():Sring의 전체에 대해서 pattern이 존재하는지 검사하여 객체를 반환
    • re.sub():string에서 pattern과 일치하는 부분에 대하여 repl로 교체하여 결과 문자열을 반환
    • re.split():pattern을 구분자로 string을 분리하여 리스트로 반환

Continue reading 08 regular expression

07 string mehtod

String Method

  • 파이썬의 string은 객체이므로 문자를 다루는 여러 메소드들이 존재함
  • 중요 메소드들을 살펴보면 다음과 같다.
    • 문자열의 변환: upper(), lower(), swapcase(), capitalize(), title()
    • 문자열의 검색: count(), find(), index(), startwitch()
    • 분리, 결합, 치환:split(),splitlines(),join(), replace(), strip()
    • 문자열 판별:isdigit(), isalpha(), isspace()
    • 정렬과 채움:center(), rjust(), ljust(), zfill()
  • 파이썬에서 String은 객체이므로 dir(str) 명령어를 입력하면 사용가능함 메소드들을 확인할 수 있다.

Continue reading 07 string mehtod

06 built-in-type

Built-in Types

  • Built-in Types docs 보면 다음과 같은 Python의 기본 자료형을 확인할 수 있다.
    1. Boolean Types: 참(True) 또는 거짓(False) 값 또는 1과 0의 숫자값으로도 표현
    2. Numeric Types: int(정수), float(실수), complex(복소수)
    3. Iterator Types: iter(), next()(컨테이너 또는 이터레이터에 대하여 반복
    4. Sequence Types: list, tuple, range (산술연산, indexing 같은 Sequence Operations을 수행)
    5. Text Sequence Type:str (String Methods를 수행)
    6. Set Types:set, frozentset(정렬되지 않은 유일한 개체의 모음)
    7. Mapping Types:dictionary(연관배열의 키와 값의 쌍의 집합형 자료형
  • 변경 가능형 : list, dict, set 변경 불가능형 : int, float, complex, bool, tuple, str

Continue reading 06 built-in-type

05 build in function

Built_in function

  • Python 내장함수 docs에서 알파벳 순으로 함수 목록을 확인할 수 있다.
  • 속성별로 분류를 해보면
    • 산술연산함수:abs, bin, oct, hex, pow, round, divmod, hash
    • 기본 타입/클래스 생성자:bool, bytearray, bytes, complex, dict, float, frozenset, int, list, memoryview, object, slice, str, tuple, zip
    • 실행관련:complie, eval, exec
    • 연속열/반복관련:all, any, enumrate, filter, iter, len, map, max, min, next, range reversed, sorted, sum,
    • 문자열과 IO관련:ascii, chr, foramt, ord, repr, input, open,print
    • 객체와 모듈관련:help, callable, delattr, dir, gettattr, globals, hasattr, id, isinstance, issubclass, locals, setattar, type, vars
    • 그외:classmethod, staticmethod, property, supter, import

Continue reading 05 build in function

Pagination


© 2017. All rights reserved.

Powered by ZooFighter v0.12