+ 파이썬 이야기
교수님의 Lecture 2에서
- Your code should be a tool used to gain insights, not something that leaves you waiting for results.
"효율적인" 파이썬 코드를 정의하면
efficient 파이썬 코드는 런타임이 빠르고 메모리가 적은 것
효율적인 "파이썬" 코드를 적기
읽을 수 있는지에 집중. 파이썬의 코드를 의도된 것으로 사용하기
# Non - Pythonic
doubled_numbers = []
for i in range(len(numbers)):
doubled_numbers.append(numbers[i]*2)
# Pythonic
doubled_numers = [ x*2 for x in numbers ]
처럼 효율적으로 코드를 작성하라는 얘기이다.
Zen of Python by Tim Peters
파이썬에 import this 를 치면 나온다.
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
빌트인 타입
list, tuple, set, dict 등
빌트인 함수
print(), len(), range(), round(), enumerate(), map(), zip() 등
빌트인 모듈
os, sys, itertools, collections, math 등