원문 : http://learnpythonthehardway.org/book/ex24.html
여태까지 배웠던것들을 다시한번 해보자 (ex24.py)
print "Let's practice everything."
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs.'
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\twhere there is none.
"""
print "--------------"
print poem
print "--------------"
five = 10 - 2 + 3 - 6
print "This should be five: %s" % five
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates
start_point = 10000
beans, jars, crates = secret_formula(start_point)
print "With a starting point of: %d" % start_point
print "We'd have %d beans, %d jars, and %d crates." % (beans, jars, crates)
start_point = start_point / 10
print "We can also do that this way:"
print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)
결과
알 수 있는 내용
1. 화면에 인쇄 할때는 "print" 명령어
2. python 에서는 " (큰 따옴표), ' (작은 따옴표) 아무거나 막 써도 된다.
3. 문자열 안에서 ', " 를 사용하고 싶을 때는 \를 앞에 붙여서 \', \" 이렇게 사용하면 된다.
4. 여러 줄에 걸쳐 문자열을 지정 하고 싶은 경우 """ 를 사용
5. \n - new line, \t - tab
6. 변수를 인쇄 하고 싶을 때는 print "%s, %d" % (문자 변수, 숫자 변수)
7. 함수를 선언 할 때는 "def"를 사용
8. 함수는 결과값을 돌려주기도 함
9. 결과값이 여러개 인 경우 "결과1, 결과2, 결과3 = 함수(파라미터)" 이런식으로 해도 됨
반응형
'Python > Python 어렵게 배우기' 카테고리의 다른 글
| Python 어렵게 배우기 - Exercise 26: Congratulations, Take a Test! (0) | 2013.12.18 |
|---|---|
| Python 어렵게 배우기 - Exercise 25: Even More Practice (0) | 2013.12.18 |
| Python 어렵게 배우기 - Exercise 23: Read Some Code (0) | 2013.12.16 |
| Python 어렵게 배우기 - Exercise 22: What Do You Know So Far? (0) | 2013.12.16 |
| Python 어렵게 배우기 - Exercise 21: Functions Can Return Something (0) | 2013.12.16 |