9. 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!
>>> import this
10. 파이썬의 선(禪) 팀 피터슨
!
아름다움이 추함보다 좋다.
명시가 암시보다 좋다.
단순함이 복잡함보다 좋다.
복잡함이 꼬인 것보다 좋다.
수평이 계층보다 좋다.
여유로운 것이 밀집한 것보다 좋다.
가독성은 중요하다.
특별한 경우라는 것은 규칙을 어겨야 할 정도로 특별한 것이 아니다.
허나 실용성은 순수성에 우선한다.
오류 앞에서 절대 침묵하지 말지어다.
명시적으로 오류를 감추려는 의도가 아니라면.
모호함을 앞에 두고, 이를 유추하겠다는 유혹을 버려라.
어떤 일에든 명확하고 바람직하며 유일한 방법이 존재한다.
비록 그대가 우둔하여 그 방법이 처음에는 명확해 보이지 않을지라도.
지금 하는게 아예 안하는 것보다 낫다.
아예 안하는 것이 지금 *당장*보다 나을 때도 있지만.
구현 결과를 설명하기 어렵다면, 그 아이디어는 나쁘다.
구현 결과를 설명하기 쉽다면, 그 아이디어는 좋은 아이디어일 수 있다.
네임스페이스는 대박이다 -- 마구 남용해라!
>>>
19. Indent of C
int main(int argc, char *argv[])
{
printf("Hello World n");
return 0;
}
!
int main(int argc, char *argv[])
{ printf("Hello World n"); return 0;}
!
int main(int argc, char *argv[]){
printf("Hello World n");
return 0;}
20. Indent of Python
if a == 10:
print "a : 10"
else:
print "a : %d" % (a)
if a == 10: print "a : 10"
else: print "a : %d" % (a)
if a == 10:
print "a : 10"
else:
print "a : %d" % (a)
print ("Done") # Error !!
def func(nNum):
nNum+=1
return nNum
def func(nNum):
nNum+=1
print "Error" # Error
return nNum
class Bird(object):
head = 1
body = 1
wing = 2
leg = 2
def fly(self):
print "Fly"
24. a = 10
b = 20
c = 10
!
print "1) a ID : %d " % (id(a))
print "2) 10 ID : %d " % (id(10))
print "3) b ID : %d " % (id(b))
print "4) 20 ID : %d " % (id(20))
print "5) c ID : %d " % (id(c))
1) a ID : 140286848207040
2) 10 ID : 140286848207040
3) b ID : 140286848206800
4) 20 ID : 140286848206800
5) c ID : 140286848207040
28. Number operations
nA = 10
nB = 20
!
print nA+nB
print nA-nB
print nB/nA
print 30%11
print 2**10
29. String
str1 = "Hello World"
print str1
!
str2 = 'Python is fun'
print str2
!
str3 = """Life is too short, You need python"""
print str3
!
str4 = '''Life is too shor, You need python'''
print str4
!
str5 = "Python's favorite food is perl"
print str5
!
str6 = '"Python is very easy." he says.'
print str6
!
str7= "Life is too shortnYou need python"
print str7
Hello World
Python is fun
Life is too short, You need python
Life is too short, You need python
Python's favorite food is perl
"Python is very easy." he says.
Life is too short
You need python
30. String operation
head = "Python"
tail = " is fun!"
print(head + tail)
!
!
a = "python"
print(a * 2)
!
!
print("=" * 11)
print("My Program")
print("=" * 11)
Python is fun!
pythonpython
===========
My Program
===========
str1 = "Life is too short, You need Python"
print str1[0]
!
!
print str1[-1]
!
!
str2 = str1[0] + str1[1] + str1[2] + str1[3]
print str2
!
!
str3 = str1[0:4]
print str2
!
!
str4 = str1[19:]
print str4
!
!
str5 = str1[:17]
print str5
L
n
Life
Life
You need Python
Life is too short
40. Function
def funcSum(a, b):
rst = a+b
return rst
def manyArg(type, *args):
sum = 0
print type
for i in args:
sum = sum + i
return sum
print funcSum(10, 10) print manyArg('type', 10, 20, 30, 40)
20 type
100