목록Language/Python (9)
Kim Jinung
functools — Higher-order functions and operations on callable objects Source code: Lib/functools.py The functools module is for higher-order functions: functions that act on or return other functions. In general, any callable object can be treated as a function for t... docs.python.org Reduce 함수는 이터러블한 객체의 두 인자에, 함수를 누적 해서 적용할 때 사용할 수 있는 함수다. 리스트 [1, 2, 3]이 있을 때 두 인자에 덧셈이라는 함수를 누적 해서 적용하면 1 + 2 ..
functools — Higher-order functions and operations on callable objects Source code: Lib/functools.py The functools module is for higher-order functions: functions that act on or return other functions. In general, any callable object can be treated as a function for t... docs.python.org cmp_to_key 함수는 파이썬의 old style 비교 함수다. 파이썬의 sort 함수를 사용하다 보면 람다식을 이용해서 중첩 리스트의 특정 요소를 기준으로 정렬한다던가 하는 방법을 종종 사용한다..
heapq — Heap queue algorithm — Python 3.11.1 documentation heapq — Heap queue algorithm Source code: Lib/heapq.py This module provides an implementation of the heap queue algorithm, also known as the priority queue algorithm. Heaps are binary trees for which every parent node has a value less than or equal to an docs.python.org heapq 모듈은 heap queue 알고리즘의 구현을 제공한다. (우선순위 큐 알고리즘으로도 알려져있다.) *주의할 점은..
collections — Container datatypes — Python 3.11.0 documentation collections — Container datatypes Source code: Lib/collections/__init__.py This module implements specialized container datatypes providing alternatives to Python’s general purpose built-in containers, dict, list, set, and tuple. namedtuple() factory f docs.python.org Counter 클래스는 Dictionary의 subclass로 hashable한 객체를 카운팅할 때 사용할 수 있다...
4. More Control Flow Tools — Python 3.11.0 documentation 4. More Control Flow Tools Besides the while statement just introduced, Python uses the usual flow control statements known from other languages, with some twists. 4.1. if Statements Perhaps the most well-known statement type is the if statement. For examp docs.python.org for loop 순회 중 특정 조건을 찾고 break를 걸어야하는 일이 있다. 그리고 break 조건에 해당하는 케이스를 ..
re — Regular expression operations — Python 3.11.0 documentation re — Regular expression operations Source code: Lib/re/ This module provides regular expression matching operations similar to those found in Perl. Both patterns and strings to be searched can be Unicode strings (str) as well as 8-bit strings (bytes). Ho docs.python.org Regex(Regular Expression)은 텍스트에서 패턴을 찾아내어 복잡한 문자열 처리에 사용하는 기법이..
What Is the Python Global Interpreter Lock (GIL)? – Real Python Python's Global Interpreter Lock or GIL, in simple words, is a mutex (or a lock) that allows only one thread to hold the control of the Python interpreter at any one time. In this article you'll learn how the GIL affects the performance of your Python prog realpython.com What is the Python Global Interpreter Lock (GIL)? Understandin..
파이썬의 리스트, 딕셔너리, 스트링 같이 원소를 가지는 데이터 구조를 컨테이너라고 부른다. 그리고 컨테이너는 이터레이블하며 이는 반복이 가능한, 순회가 가능한 자료구조라는 의미다. 그리고 이터레이블한 객체는 이터레이터라는 인스턴스를 생성할 수 있다. num_list = [1, 2, 3] for num in num_list: print(num) num_list는 리스트라는 컨테이너다. 따라서 이터레이블하다. for 문에서는 이터레이블한 num_list를 순회하고자 한다. 이때 num_list를 그대로 사용하는 것이 아니라 num_list를 활용해서 이터레이터 인스턴스를 생성한다. 이터레이터는 값 생성기로 다음 값을 요청하면 반환하고 그 다음 값을 반환하게 된다. 위 for 문에서 num 변수는 처음 1을 ..
Goal Python의 Instance method, static method 그리고 class method의 차이점을 정리한다. Instance method 파이썬에서 클래스를 선언하고 메서드를 생성하는 일반적인 방법은 아래와 같다. class Person: count = 0 def __init__(self, name, age): self.name = name self.age = age Person.count += 1 def greeting(self): print(f"Hi {self.name}") class에서 self는 instance를 가르킨다. 즉 인스턴스로 생성 될 객체를 가르킨다. 그러므로 메서드를 선언하고 self 키워드를 이용해서 instacne attribute(속성)에 접근할 수 있다...