{"id":103,"date":"2018-03-07T05:53:15","date_gmt":"2018-03-06T20:53:15","guid":{"rendered":"http:\/\/batmask.dothome.co.kr\/?page_id=103"},"modified":"2026-03-21T20:19:58","modified_gmt":"2026-03-21T11:19:58","slug":"python_reference","status":"publish","type":"page","link":"http:\/\/batmask.net\/index.php\/references\/python_reference\/","title":{"rendered":"Python \uc815\ub9ac"},"content":{"rendered":"\n<p>Python \uc815\ub9ac<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\uc124\uce58<\/li>\n<\/ul>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>python\uc5d0 \ub300\ud55c \uc88b\uc740 \ub808\ud37c\ub7f0\uc2a4 :<\/p>\n\n\n\n<p><a href=\"http:\/\/www.tutorialspoint.com\/python\/index.htm\">http:\/\/www.tutorialspoint.com\/python\/index.htm<\/a><\/p>\n\n\n\n<p>\ud035 \ub808\ud37c\ub7f0\uc2a4 :<\/p>\n\n\n\n<p><a href=\"http:\/\/www.tutorialspoint.com\/python\/python_quick_guide.htm\">http:\/\/www.tutorialspoint.com\/python\/python_quick_guide.htm<\/a><\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>\ud30c\uc774\uc36c\uc744 \ucc98\uc74c \uc2dc\uc791\ud558\uae30 \uc801\ub2f9\ud55c \ud55c\uae00 \uc704\ud0a4\ubd81, \uc810\ud504 \ud22c \ud30c\uc774\uc36c:<\/p>\n\n\n\n<p><a href=\"https:\/\/wikidocs.net\/book\/1\">https:\/\/wikidocs.net\/book\/1<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ubb38\ubc95(C++ \ubca0\uc774\uc2a4\ub85c \uc124\uba85)<\/li>\n<\/ul>\n\n\n\n<p>\ubaa8\ub4e0 statement\ub294 indent\ub85c \uad6c\ubd84. \ud568\uc218\ub098 \ub8e8\ud504, \ud074\ub798\uc2a4\ub4f1\uc740 \ube14\ub7ed\uad6c\ubd84\uc744 \uc704\ud574 {}\uac00 \uc0ac\uc6a9\ub418\uc9c0<\/p>\n\n\n\n<p>\uc54a\uc73c\uba70, \ub77c\uc778\uc758 \ub05d\uc5d0 &#8216;;&#8217; \uac19\uc740 \uac83\ub3c4 \uc0ac\uc6a9\ud558\uc9c0 \uc54a\ub294\ub2e4. \ube14\ub7ed\uc5d0\ub294 \uc2dc\uc791 \ub77c\uc778\uc5d0\ub9cc &#8216;:&#8217;\uac00 \uc0ac\uc6a9\ub41c\ub2e4.<\/p>\n\n\n\n<p>* operator : <a href=\"http:\/\/www.tutorialspoint.com\/python\/python_basic_operators.htm\">http:\/\/www.tutorialspoint.com\/python\/python_basic_operators.htm<\/a>&nbsp;&#8216;++&#8217;, &#8216;&#8211;&#8216; \uc5f0\uc0b0\uc790\ub294 \uc5c6\ub2e4.<\/p>\n\n\n\n<p>* 5 data types : Numbers, String, List, Tuple, Dictionary<\/p>\n\n\n\n<p>&#8211; Numbers : int, long, float, complex<\/p>\n\n\n\n<p>* variable : \uc120\uc5b8\uc774\ub098 \uc815\uc758\uac00 \ud2b9\ubcc4\ud788 \uc5c6\ub2e4.<\/p>\n\n\n\n<p>* boolean operator : and, or, not<\/p>\n\n\n\n<p>* String quatation : single quatation \uacfc double quatation \ucc28\uc774\uac00 \uc5c6\ub2e4. PHP\uc758 \uacbd\uc6b0, variable expanding\uc774 double quatation\uc5d0\uc11c\ub294 \uc77c\uc5b4\ub098\uace0 single quatation\uc5d0\uc11c\ub294 \uc77c\uc5b4\ub098\uc9c0 \uc54a\ub294\ub2e4. PHP\ub294 variable \uad6c\ubd84\uc790 &#8216;$&#8217; \ub97c \uc0ac\uc6a9\ud558\uc9c0\ub9cc, Python\uc740 \uad6c\ubd84\uc790\uac00 \uc5c6\ub294 \ucc28\uc774\uac00 \uc544\ub2d0\uae4c \uc0dd\uac01\ud574\ubcf8\ub2e4. \ub2e4\uc74c\uacfc \uac19\uc774 \uc0ac\uc6a9\ud55c quatation\uacfc \ub2e4\ub978 quatation\uc758 \uacbd\uc6b0 &#8216;\\&#8217;\uc5c6\uc774 \uc0ac\uc6a9\uac00\ub2a5\ud558\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print (\"test string 'whooooo~'\")\nprint ('test string \"whaaaaa~\"')<\/pre>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>* tuple : immutable list. (item1, item2, &#8230;) \uc640 \uac19\uc774 \uad04\ud638\ub97c \uc0ac\uc6a9. \uac12\uc774 \ud558\ub098\uc778 tuple\uc740 &#8216;,&#8217;\ub97c<\/p>\n\n\n\n<p>\uc801\uc5b4\uc918\uc57c \ud55c\ub2e4. (item1,) \uacfc \uac19\uc774.<\/p>\n\n\n\n<p>* list : mutable. [item1, item2, &#8230;] \uc640 \uac19\uc774 \ub300\uad04\ud638 \uc0ac\uc6a9<\/p>\n\n\n\n<p>* list comprehension : \uae30\uc874 \ub9ac\uc2a4\ud2b8\uc5d0\uc11c \uc0c8\ub85c\uc6b4 \ub9ac\uc2a4\ud2b8 \uc0dd\uc131\uc744 \uc27d\uac8c \ud558\ub294 \ubc29\ubc95.<\/p>\n\n\n\n<p>new_list = [item for in old_list if item&#8230;]<\/p>\n\n\n\n<p>for\ubb38\uc744 \uc774\uc6a9\ud574\uc11c \ub9ac\uc2a4\ud2b8 \uc544\uc774\ud15c\uc744 \uad6c\uc131\ud558\uace0, if\ubb38\uc73c\ub85c \ud544\ud130\ub9c1\uc744 \ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<p>* dictionary : C++\uc5d0\uc11c STL Map\uacfc \uac19\uc740 \ub140\uc11d. \ud0a4\uc640 \ubc38\ub958\uc758 \uc30d\uc73c\ub85c \uad6c\uc131. {&#8220;key1&#8243;:&#8221;value1&#8221;,<\/p>\n\n\n\n<p>&#8220;key2&#8243;:&#8221;value2&#8221;, &#8230;} \uc640 \uac19\uc774 {} \uad04\ud638 \uc0ac\uc6a9.<\/p>\n\n\n\n<p>* String formatting : sprintf\uc640 \uac19\uc740 \ubc29\uc2dd\uc774 \uc0ac\uc6a9\ub418\ub098, \ub2e4\uc74c\uacfc \uac19\uc774 % \uac00 \uad6c\ubd84\uc790\ub85c \uc774\uc6a9\ub428.<\/p>\n\n\n\n<p>print (&#8220;%s is not %s&#8221;%(&#8220;value1&#8221;, &#8220;value2&#8221;))<\/p>\n\n\n\n<p>* if \ubb38 : \uc870\uac74\ubb38\uc5d0 \uad04\ud638\uac00 \uc0ac\uc6a9\ub418\uc9c0 \uc54a\ub294\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if a &lt; b :\n\tprint (\"a &lt; b\")\nelif a &lt; c :\n\tprint (\"a &lt; c\")\nelse:\n\tprint(\"else\")<\/pre>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p><span style=\"font-size: 1em; line-height: 1.5;\">switch-case \ubb38\uc774 \ud30c\uc774\uc36c\uc5d0\ub294 \uc5c6\uae30 \ub54c\ubb38\uc5d0, if-elif-else\ub85c \uad6c\ud604\ub418\uc5b4\uc57c \ud55c\ub2e4.<\/span><\/p>\n\n\n\n<p>* for \ubb38<\/p>\n\n\n\n<p>C++\uc5d0\uc11c \uc0ac\uc6a9\ud558\ub294 for \ubb38\uacfc\ub294 \ud615\uc2dd\uc774 \ub2e4\ub974\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#for item in tuple or list\n\nfor item in range(20)\n\tprint (item)<\/pre>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p><span style=\"font-size: 1em; line-height: 1.5;\">&nbsp;<\/span><\/p>\n\n\n\n<p>* while \ubb38<\/p>\n\n\n\n<p>while a &lt; b :<\/p>\n\n\n\n<p>print (a)<\/p>\n\n\n\n<p>a+=1<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>* \ud568\uc218 : &#8216;def&#8217;\ub85c \ud568\uc218\ub97c \uc815\uc758(define)\ud55c\ub2e4.<\/p>\n\n\n\n<p><a href=\"http:\/\/www.tutorialspoint.com\/python\/python_functions.htm\">http:\/\/www.tutorialspoint.com\/python\/python_functions.htm<\/a><\/p>\n\n\n\n<p>\ud30c\uc774\uc36c\uc5d0\uc11c \ubaa8\ub4e0 argument\ub294 reference\ub85c \ub118\uaca8\uc9c4\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def functionname( parameters ):\n   \"function_docstring\"\n   function_suite\n   return [expression]<\/pre>\n\n\n\n<p>\uae30\ubcf8 \uc0ac\uc6a9<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def myFun(arg1):\n\t\"function example\"\n\tprint (arg1)\n\treturn<\/pre>\n\n\n\n<p>\ud30c\ub77c\ubbf8\ud130 \uac1c\uc218 \ubb34\uc81c\ud55c\uc73c\ub85c \ub118\uae30\uae30<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def testFunction(*args):\n\t\"doc string...\"\n\tprint (\"It's a test function! :\")\n\tfor item in args:\n\t\tprint (item + \"\\n\")\n\n\treturn<\/pre>\n\n\n\n<p>* pass : Python\uc5d0\uc11c\ub294 \ud568\uc218\ub098 \ud074\ub798\uc2a4 \uc815\uc758\ub97c \uc548\ud574\ub3c4 \uc5d0\ub7ec\uac00 \ub098\uc9c0 \uc54a\ub3c4\ub85d \ud560 \uc218 \uc788\ub2e4. \ubc14\ub85c &#8220;pass&#8221;\ub97c \uc0ac\uc6a9\ud558\ub294 \uac83. TDD\ub85c \uc811\uadfc\uc2dc, \uc720\uc6a9\ud558\uac8c \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def emptyFunc(arg1):\n\tpass<\/pre>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>* \ubaa8\ub4c8<\/p>\n\n\n\n<p>*Exception : try &#8211; except<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">try:\n   fh = open(\"testfile\", \"w\")\n   fh.write(\"This is my test file for exception handling!!\")\nexcept IOError:\n   print \"Error: can\\'t find file or read data\"\nelse:\n   print \"Written content in the file successfully\"\n   fh.close()<\/pre>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>* \ud074\ub798\uc2a4 : &#8216;class&#8217; \ub97c \uc0ac\uc6a9\ud55c\ub2e4.<\/p>\n\n\n\n<p>&#8211; __init__(self) : \uc0dd\uc131\uc790<\/p>\n\n\n\n<p>&#8211; &#8216;self&#8217; : \uc790\uae30 \uc790\uc2e0\uc744 \uac00\ub9ac\ud0a4\ub294 \ucc38\uc870 \uc778\uc790<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Parent():\n\tpass\n\nclass MyClass(Parent):\n\tdef __init__(self):\n\t\tpass<\/pre>\n\n\n\n<p>&#8211; built-in \uc18d\uc131 : __name__, __doc__, __module__, __dict__<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">__name__ : class name\n__doc__ : class documentation string. \n__module__ : module name which class is defined\n__dict__ : \ud074\ub798\uc2a4 \ub0b4\ubd80\uc758 dictionary. \uba54\uc18c\ub4dc, \ud504\ub85c\ud37c\ud2f0\ub4f1\uc744 \ud0a4\ub85c \uac16\uac8c\ub41c\ub2e4.\n__bases : \ubca0\uc774\uc2a4 \ud074\ub798\uc2a4<\/pre>\n\n\n\n<p>&#8211; \uac00\ubca0\uc9c0 \ucf5c\ub809\uc158\uc5d0 \uc758\ud574 \ucc38\uc870\ub418\uc9c0 \uc54a\ub294 \uac1d\uccb4\ub4e4\uc758 \uba54\ubaa8\ub9ac \ud68c\uc218.<\/p>\n\n\n\n<p>&#8211; overriding : \uc5f0\uc0b0\uc790\ub3c4 \uc624\ubc84\ub77c\uc774\ub529\uc774 \uac00\ub2a5\ud558\ub2e4. \ub2f9\uc5f0\ud558\uc9c0\ub9cc&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Vector:\n   def __init__(self, a, b):\n      self.a = a\n      self.b = b\n\n   def __str__(self):\n      return 'Vector (%d, %d)' % (self.a, self.b)\n\n   def __add__(self,other):\n      return Vector(self.a + other.a, self.b + other.b)<\/pre>\n\n\n\n<p>&#8211; overloading : \uc778\uc790 \ud0c0\uc785\uc744 \uba85\uc2dc \ud560 \uc218\ub294 \uc5c6\uc73c\ubbc0\ub85c \uc778\uc790 \uac1c\uc218\uac00 \ub2e4\ub978 \uba54\uc18c\ub4dc\ub85c\ub9cc \uc624\ubc84\ub85c\ub529 \uac00\ub2a5<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>&#8211; private property : prefix\ub85c underscore\ub97c &nbsp;__privateProperty &nbsp;= 0 \ucc98\ub7fc \ub450\ubc88 \ub123\uc5b4\uc8fc\uba74 \ub41c\ub2e4. \ubb3c\ub860 \uc644\ubcbd\ud55c \ub370\uc774\ud130 \ud558\uc774\ub529\uc740 \uc544\ub2c8\uba70 \ud30c\uc774\uc36c \ub0b4\ubd80\uc801\uc73c\ub85c \ud074\ub798\uc2a4 \uc774\ub984\uc744 \ud3ec\ud568\ud558\ub3c4\ub85d \ud504\ub85c\ud37c\ud2f0 \uba85\uc744 \ubcc0\uacbd\ud55c\ub2e4\uace0 \ud55c\ub2e4.<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>* \uc785\ucd9c\ub825<\/p>\n\n\n\n<p>1) \ucf58\uc194 : input(), print()<\/p>\n\n\n\n<p>2) \ud30c\uc77c file = open(), file.close(), file.write(), file.read(), file.readline(), etc.<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>\uc774\uc288 1 : \ud568\uc218\uc758 \ucf5c \ubc14\uc774 \ub808\ud37c\ub7f0\uc2a4\ub294 \uc5b4\ub5bb\uac8c \ud558\ub294\uac00?<\/p>\n\n\n\n<p>\ud568\uc218 \uc778\uc790\uac00 mutable\uc774\ub0d0, unmutable\uc774\ub0d0\uc5d0 \ub530\ub77c \ub2ec\ub77c\uc9c4\ub2e4. \ub9ac\uc2a4\ud2b8\ub098 \ud074\ub798\uc2a4\ub294 mutable\uc774\uba70 \uc2a4\ud2b8\ub9c1\uc740 unmutable\uc774\ub2e4. \ucf5c\ubc14\uc774 \ub808\ud37c\ub7f0\uc2a4\ub97c \uc4f0\uace0 \uc2f6\uc73c\uba74 mutable\uc744 \uc4f0\uace0 \uc544\ub2c8\ub77c\uba74 \ub9ac\ud134\uac12\uc744 \uc801\uc808\ud788 \ucc98\ub9ac\ud558\ub3c4\ub85d \ud55c\ub2e4.<\/p>\n\n\n\n<p>\uc774\uc2882 : \ud30c\uc77c \uc624\ud508\uacfc \uac19\uc740 \uacbd\uc6b0, \uc608\uc678\ucc98\ub9ac\ub294 \uc5b4\ub5bb\uac8c \ud558\ub294\uac00?<\/p>\n\n\n\n<p>\uc774\uc2883 : \ub85c\uae45\uacfc \ub514\ubc84\uae45\uc740 \uc5b4\ub5bb\uac8c \ud558\ub294\uac00?<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>\uc775\ud600\uc57c\ud560 \ud45c\uc900 \ubaa8\ub4c8 :<\/p>\n\n\n\n<p>&#8211; \uc2dc\uac04, &nbsp;\uc785\ucd9c\ub825, \uc2dc\uc2a4\ud15c, \ub610 \ubb50\uac00 \uc788\uc744\uae4c?<\/p>\n\n\n\n<p>&nbsp;<\/p>\n\n\n\n<p>Excercise :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\uae30\ud0c0<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Python \uc815\ub9ac &nbsp; python\uc5d0 \ub300\ud55c \uc88b\uc740 \ub808\ud37c\ub7f0\uc2a4 : http:\/\/www.tutorialspoint.com\/python\/index.htm \ud035 \ub808\ud37c\ub7f0\uc2a4 : http:\/\/www.tutorialspoint.com\/python\/python_quick_guide.htm &nbsp; \ud30c\uc774\uc36c\uc744 \ucc98\uc74c \uc2dc\uc791\ud558\uae30 \uc801\ub2f9\ud55c \ud55c\uae00 \uc704\ud0a4\ubd81, \uc810\ud504 \ud22c \ud30c\uc774\uc36c: https:\/\/wikidocs.net\/book\/1 \ubaa8\ub4e0 statement\ub294 indent\ub85c \uad6c\ubd84. \ud568\uc218\ub098 \ub8e8\ud504, \ud074\ub798\uc2a4\ub4f1\uc740 \ube14\ub7ed\uad6c\ubd84\uc744 \uc704\ud574 {}\uac00 \uc0ac\uc6a9\ub418\uc9c0 \uc54a\uc73c\uba70, \ub77c\uc778\uc758 \ub05d\uc5d0 &#8216;;&#8217; \uac19\uc740 \uac83\ub3c4 \uc0ac\uc6a9\ud558\uc9c0 \uc54a\ub294\ub2e4. \ube14\ub7ed\uc5d0\ub294 \uc2dc\uc791 \ub77c\uc778\uc5d0\ub9cc &#8216;:&#8217;\uac00 \uc0ac\uc6a9\ub41c\ub2e4. * operator : http:\/\/www.tutorialspoint.com\/python\/python_basic_operators.htm&nbsp;&#8216;++&#8217;, &#8216;&#8211;&#8216; \uc5f0\uc0b0\uc790\ub294 \uc5c6\ub2e4. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":119,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-103","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/pages\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":2,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/pages\/103\/revisions"}],"predecessor-version":[{"id":4235,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/pages\/103\/revisions\/4235"}],"up":[{"embeddable":true,"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/pages\/119"}],"wp:attachment":[{"href":"http:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/media?parent=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}