본문 바로가기

전체 글

Python 어렵게 배우기 - Exercise 13: Parameters, Unpacking, Variables 원문 : http://learnpythonthehardway.org/book/ex13.html ex13.py from sys import argv script, first, second, third = argv print "%r" % argv print "The script is called:", script print "Your first variable is:", first print "Your second variable is:", second print "Your third variable is:", third 결과 (python ex13.py one two three) 알 수 있는 내용...1. 외부 라이브러리의 기능을 사용할때는 (from...) import를 사용한다.2. 스크립트를 실행할때.. 더보기
Python 어렵게 배우기 - Exercise 12: Prompting People 원문 : http://learnpythonthehardway.org/book/ex12.html raw_input을 조금 다르게 사용해 보자 (ex12.py) age = raw_input("How old are you? ") height = raw_input("How tall are you? ") weight = raw_input("How much do you weigh? ") print "So, you're %r old, %r tall and %r heavy." % (age, height, weight) 결과 알 수 있는 내용...1. raw_input("입력 받을때 표시 할 내용") 더보기
Python 어렵게 배우기 - Exercise 11: Asking Questions 원문 : http://learnpythonthehardway.org/book/ex11.html 키보드로 입력을 받아보자 (ex11.py) print "How old are you?", age = raw_input() print "How tall are you?", height = raw_input() print "How much do you weigh?", weight = raw_input() print "So, you're %r old, %r tall and %r heavy." % (age, height, weight) print 문 뒤에 콤마(",")를 사용하는 이유는 입력받는 문자가 print 된 문자열 바로 뒤에 표시 되도록 하기 위함이다. (간단히 테스트 해볼것) 결과 알 수 있는 내용...1... 더보기
Python 어렵게 배우기 - Exercise 10: What Was That? 원문 : http://learnpythonthehardway.org/book/ex10.html 이스케이프 시퀀스 (Escape Sequence)에 대해서 알아보자 (ex10.py) tabby_cat = "\tI'm tabbed in." persian_cat = "I'm split\non a line." backslash_cat = "I'm \\ a \\ cat." fat_cat = """ I'll do a list: \t* Cat food \t* Fishies \t* Catnip\n\t* Grass """ print tabby_cat print persian_cat print backslash_cat print fat_cat 결과 알 수 있는 내용...1. 탭, 줄 바꿈 과 같은 특수문자(?)를 표현할 .. 더보기
Python 어렵게 배우기 - Exercise 9: Printing, Printing, Printing 원문 : http://learnpythonthehardway.org/book/ex9.html 또 프린트... (ex9.py) # Here's some new strange stuff, remember type it exactly. days = "Mon Tue Wed Thu Fri Sat Sun" months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug" print "Here are the days: ", days print "Here are the months: ", months print """ There's something going on here. With the three double-quotes. We'll be able to type as much as we l.. 더보기
Python 어렵게 배우기 - Exercise 8: Printing, Printing 원문 : http://learnpythonthehardway.org/book/ex8.html 또 프린트...(ex8.py) formatter = "%r %r %r %r" print formatter % (1, 2, 3, 4) print formatter % ("one", "two", "three", "four") print formatter % (True, False, False, True) print formatter % (formatter, formatter, formatter, formatter) print formatter % ( "I had this thing.", "That you could type up right.", "But it didn't sing.", "So I said goodni.. 더보기
Python 어렵게 배우기 - Exercise 7: More Printing 원문 : http://learnpythonthehardway.org/book/ex7.html 좀더 다양하게 print 문을 사용해 보자 (ex7.py) print "Mary had a little lamb." print "Its fleece was white as %s." % 'snow' print "And everywhere that Mary went." print "." * 10 # what'd that do? end1 = "C" end2 = "h" end3 = "e" end4 = "e" end5 = "s" end6 = "e" end7 = "B" end8 = "u" end9 = "r" end10 = "g" end11 = "e" end12 = "r" # watch that comma at the end.. 더보기
Python 어렵게 배우기 - Exercise 6: Strings and Text 원문 : http://learnpythonthehardway.org/book/ex6.html 일단 코딩 (ex6.py) x = "There are %d types of people." % 10 binary = "binary" do_not = "don't" y = "Those who know %s and those who %s." % (binary, do_not) print x print y print "I said: %r." % x print "I also said: '%s'." % y hilarious = False joke_evaluation = "Isn't that joke so funny?! %r" print joke_evaluation % hilarious w = "This is the left.. 더보기