전체 글
-
[Python] set란? 그리고 사용법Python 2021. 11. 23. 18:43
set란? 중복을 허용하지 않고, 순서가 없다 s1 = set([1, 2, 3, 4, 5, 6]) s2 = set([4, 5, 6, 7, 8, 9]) # 교집합 print(s1 & s2) print(s1.intersection(s2)) => {4, 5, 6} # 합집합 print(s1 | s2) print(s1.union(s2)) => {1, 2, 3, 4, 5, 6, 7, 8, 9} # 차집합 print(s1 - s2) print(s1.difference(s2)) => {1, 2, 3} print(s2 - s1) print(s2.difference(s1)) => {8, 9, 7}
-
[Python] iterable과 iterator에 대해서Python 2021. 11. 23. 18:33
iterable 객체 : 반복 가능한 객체 iterable types : list, dict, set, str, bytes, tuple, range iterator 객체 : 값을 차례대로 꺼낼 수 있는 객체 interator은 iterable한 객체를 생성할 수 있다. # 예시 1 a = [1, 2, 3] a_iter = iter(a) next(a_iter) => 1 next(a_iter) => 2 next(a_iter) => 3 -------------------- # 에시 2 b = {1, 2, 3} b_iter = b.__iter__() b_iter.__next__() => 1 b_iter.__next__() => 2 b_iter.__next__() => 3
-
[Python] append 와 extend의 차이점Python 2021. 11. 23. 18:22
# example of append a_list = [1,2,3] b_list = [4,5] a_list.append(b_list) print(a_list) => [1, 2, 3, [4, 5]] ------------------------------- # example of extend a_list = [1,2,3] b_list = [4,5] a_list.extend(b_list) print(a_list) => [1, 2, 3, 4, 5] ------------------------------- # example of extend 2 a_list = [1,2,3] b_list = [[4,5]] a_list.extend(b_list) print(a_list) => [1, 2, 3, [4, 5]] appen..
-
[Python] 한줄 반복문으로 코드를 깔끔하게 만들어보자 list comprehensionPython 2021. 11. 23. 18:10
# SUITE와 RANKS 라는 리스트를 만들어준다 SUITE = 'H D S C'.split() RANKS = '2 3 4 5 6 7 8 9 10 J Q K A'.split() # 경우 1 mycards = [(s,r) for s in SUITE for r in RANKS] ------------------------------------- # 경우 2 mycards = [] for r in RANKS: for s in SUITE: mycards.append((s,r))
-
[Python] class에 기능을 더해보자Python 2021. 11. 23. 17:42
class Book(): def __init__(self, title, author, pages): self.title = title self.author = author self.pages = pages def __str__(self): return f"Title: {self.title}, Author: {self.author}, Pages: {self.pages}" def __len__(self): return self.pages def __del__(self): print("a book is destroyed!") myBook = Book("The Fourth Industrial Revolution", "Klaus Schwab", 287) print(str(myBook)) => Title: The ..
-
[Python] class를 써보자Python 2021. 11. 23. 16:06
예전에 몽구스 공부할때 쓰던 schema가 연상된다. class Candidate(): def __init__(self, name, gender, age, party): self.name = name self.gender = gender self.age = age self.party = party 윤 = Candidate(name = "석열", gender = "male", age = 60, party = "국민의힘") 이 = Candidate(name = "재명", gender = "male", age = 57, party = "더불어민주당") print(윤.name) # => 석열 print(이.party) # => 더불어민주당 일종의 틀이라고 생각하자 틀에다가 뭔가를 찍어낼수 있다
-
[Python] Scope를 초월해서 변수에 손을 대보자 globalPython 2021. 11. 23. 15:31
local에서 global변수에 손을 댈수있다 그건 바로 global 내장함수를 사용하는 것이다 adBlue = "10,000 won" def exportBan(): global adBlue adBlue = "80,000 won" print("요소수의 원래 가격은 ", adBlue) # => 요소수의 원래 가격은 10,000 won exportBan() print("중국의 요소수 수출 금지 이후 요소수의 가격은 ", adBlue) # => 중국의 요소수 수출 금지 이후 요소수의 가격은 80,000 won 상급 영역에 손을 대다니 상당히 버르장 머리 없는 함수라고 할수 있겠다
-
[Python] 우수 작품으로 선정!Python/Nomadcoder Python Challenge 2021. 11. 22. 20:09
Post on 노마드 코더 Community – 노마드 코더 Nomad Coders Post on 노마드 코더 Community nomadcoders.co 17기 졸업 작품 정말 재밌게 즐겼던 Python(Flask) 2주 챌린지가 끝났다. 몰입할땐 밤낮없이 새벽까지도 했고 시간 가는지 모르고 즐겼다. 이번 17기에는 470명이 지원했고 28명 졸업, 그리고 우수작 4인에 뽑혔다. 스스로 자랑스럽다! 파이썬에 빠져있는 요즘인데 선택에 더욱 확신이 든다. 이 기세를 몰아 SSAFY 7기도 합격했으면 좋겠다 :) 나의 우수작 보러가기 https://Python-Challenge-Final.insub4067.repl.co remotjob.com Python-Challenge-Final.insub4067.rep..