본문 바로가기

개발/Python

(5)
Advanced Python #5 [Notion : 1/4] Collections Library Collections Data Structure Deque Counter orderedDict defaultdict namedtuple # Module Importing from collections import deque, Counter, OrderedDict, defaultdict, namedtuple 👉 Deque # Deque deque_list = deque() for i in range(5): deque_list.append(i) print(deque_list) # deque([0,1,2,3,4]) deque_list.appendleft(10) deque_list # deque([10,0,1,2,3,4]) deque_list.rotate(2) deque_li..
Advanced Python #4 [Notion : 1/3] 👉 Asterisk 흔히 알고있는 *를 말함 곱셈 및 거듭제곱 연산으로 사용할 때 리스트형 컨테이너 타입의 데이터를 반복 확장하고자 할 때 가변인자 (Variadic Arguments)를 사용하고자 할 때 컨테이너 타입의 데이터를 Unpacking 할 때 # *args (= Asterisk arguments) # args 가변인자로 사용할 경우 명시된 params을 제외하고 packing되어 tuple로 반환 def aa(a, *args): print(a, args) print(type(args)) aa(1,2,3,4,5,6) # 1 (2,3,4,5,6) # # **kargs (= Double Asterisk Keywords arguments) # kargs 가변인자로 사용할 경우 명시된 params를 ..
Advanced Python #3 [Notion : 1/3] 👉 Lambda 함수 이름없이 사용할 수 있는 익명함수 python3부터 권장하지 않음. # General function def f(x, y): return x+y print(f(1,2)) # 3 # Lambda function f = lambda x ,y:x+y print(f(1,3)) # 4 👉 Map() Sequence 자료형 각 element에 동일한 function을 적용함 ex = [1,2,3,4,5] f = lambda x:x**2 print(list(map(f, ex))) # [1, 4, 9, 16, 25] ex = [1,2,3,4,5] t = lambda x, y:x+y print(list(map(t, ex, ex))) # [2, 4, 6, 8, 10] print(list(map(lam..
Advanced Python #2 [Notion : 1/3] 👉 Pythonic Code 파이썬 스타일의 코딩 기법 파이썬 특유의 문법을 활용한 효율적인 코딩 고급 코드를 작성할수록 더 많이 필요 👉 Why Pythonic Code? 타인의 코드에 대한 이해도 많은 개발자들이 python 스타일로 코딩한다. 효율성 단순한 for loop append보다 list가 조금 더 빠르다. 간지..? 왠지 모를 고수의 느낌? 👉 Split() # Split & Join items = 'zero one two three'.split()#빈칸을 기준으로 문자열 나누기 items # ['zero', 'one', 'two', 'three'] example = 'python,jquery,javascript'#","을 기준으로 문자열 나누기 example.split(",") exam..
Advanced Python #1 [Notion : 1/2] Environment Setting Python 3.9.5 IDE Pycharm, Jupyter Notebook, Github Codespace 👉 Introduction to Variable 변수란? 값을 저장하는 공간 = 연산자로 대입연산 파이썬 변수의 특징 모든 변수는 Memory Address를 가리킨다. 즉, 모든 것은 포인터다! 변수명 일종의 이름표, 선언한 변수에 특정 공간이 생기는 개념이 아니다! 필요할때마다 공간을 만들고 변수명을 붙임! a = 15 b = 4 a+b #19 a = 15 b = a b #15 👉 How to name Variables 알파벳, 숫자, 언더스코어(_)로 선언 숫자로 변수명을 시작할 수 없음. data = 0, _al=2, _gg='adfaf' 변수명은 그 변..