{"id":2051,"date":"2015-08-17T23:10:54","date_gmt":"2015-08-17T14:10:54","guid":{"rendered":"http:\/\/tech.akat.info\/?p=2051"},"modified":"2015-08-19T23:08:12","modified_gmt":"2015-08-19T14:08:12","slug":"python","status":"publish","type":"post","link":"https:\/\/tech.akat.info\/?p=2051","title":{"rendered":"python"},"content":{"rendered":"<h1>\u6982\u8981<\/h1>\n<p>\u30c9\u30c3\u30c8\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304a\u52c9\u5f37\u3057\u305f\u3053\u3068\u3092\u30e1\u30e2<br \/>\n<a href=\"http:\/\/tech.akat.info\/wp-content\/uploads\/2015\/08\/2015-08-17_225517.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/tech.akat.info\/wp-content\/uploads\/2015\/08\/2015-08-17_225517-300x148.png\" alt=\"2015-08-17_225517\" width=\"300\" height=\"148\" class=\"alignnone size-medium wp-image-2052\" srcset=\"https:\/\/tech.akat.info\/wp-content\/uploads\/2015\/08\/2015-08-17_225517-300x148.png 300w, https:\/\/tech.akat.info\/wp-content\/uploads\/2015\/08\/2015-08-17_225517-660x326.png 660w, https:\/\/tech.akat.info\/wp-content\/uploads\/2015\/08\/2015-08-17_225517.png 744w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nhttp:\/\/dotinstall.com\/lessons\/basic_python_v2<\/p>\n<h1>python\u3068\u306f<\/h1>\n<p>\u30b7\u30f3\u30d7\u30eb\u3067\u53d6\u5f97\u3057\u3084\u3059\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u8a00\u8a9e<\/p>\n<h1>Hello World<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# python --version\r\nPython 2.7.9\r\n\r\nroot@hostname:\/home\/shimizu\/python# cat hello.py\r\n# coding: UTF-8\r\n# \u2191\u304c\u306a\u3044\u3068\u65e5\u672c\u8a9e\u5229\u7528\u6642\u306b\u30a8\u30e9\u30fc\u3068\u306a\u308b\r\nprint &quot;hello world&quot;\r\n\r\nroot@hostname:\/home\/shimizu\/python# python hello.py\r\nhello world\r\n<\/pre>\n<h1>\u5909\u6570\u306e\u578b\u306a\u3069<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# cat hensu.py\r\n# coding: UTF-8\r\n# \u5909\u6570\u306f\u5927\u6587\u5b57\u5c0f\u6587\u5b57\u3092\u533a\u5225\u3059\u308b\r\nmsg = &quot;hello world&quot;\r\nprint msg\r\n\r\n# \u65e5\u672c\u8a9e\u306fu\u3092\u3064\u3051\u308b\u3001\u3064\u3051\u306a\u3044\u3068\u6587\u5b57\u5217\u64cd\u4f5c\u304c\u3067\u304d\u306a\u3044\u3089\u3057\u3044\r\nmsg2 = u&quot;\u3053\u3093\u306b\u3061\u306f&quot;\r\nprint msg2\r\n\r\n# \u6539\u884c\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f &quot;&quot;&quot; \u3067\u52a0\u5de5\r\nprint &quot;&quot;&quot;\r\nthis\r\nis\r\npen\r\n&quot;&quot;&quot;\r\n# \u6f14\u7b97\u5b50 + - * \/ \/\/ % **\r\n# \u6574\u6570\u3068\u5c0f\u6570\u306e\u6f14\u7b97 \u2192 \u7b54\u3048\u306f\u5c0f\u6570\u3068\u306a\u308b\r\n# \u5272\u308a\u7b97 \u2192 \u7b54\u3048\u306f\u6574\u6570\r\nprint 10 * 5\r\nprint 10 \/\/ 4\r\nprint 10 \/\/ 4 # \u4f59\u308a\u3092\u6c42\u3081\u308b\r\nprint 2 ** 3\r\nprint 10 \/ 4\r\n\r\n# \u30ea\u30b9\u30c8\r\nsales = &#x5B;25, 50, 70]\r\nprint len(sales)\r\nsales&#x5B;2] = 100\r\nprint sales&#x5B;2]\r\nprint range(10)\r\n\r\n# \u30ea\u30b9\u30c8\u64cd\u4f5c\r\nsales.sort()\r\nsales.reverse()\r\nprint sales\r\n\r\nd = &quot;2015\/8\/15&quot;\r\nprint d.split(&quot;\/&quot;)\r\nds = d.split(&quot;\/&quot;)\r\nprint &quot;-&quot;.join(ds)\r\n\r\n# \u30bf\u30d7\u30eb(\u5909\u66f4\u304c\u3067\u304d\u306a\u3044) &quot;()&quot;\u3067\u56f2\u3080\r\n# \u8a08\u7b97\u6642\u306b\u9ad8\u901f\u306b\u51e6\u7406\u3067\u304d\u305f\u308a\u3001\u30df\u30b9\u304c\u5c11\u306a\u304f\u306a\u308b\r\n# \u5909\u66f4\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\r\n# TypeError: 'tuple' object does not support item assignment\r\nprint &quot;tuple&quot;\r\na = (2,4,8)\r\n\r\n# \u30bb\u30c3\u30c8(\u96c6\u5408\u578b) - \u91cd\u8907\u3092\u8a31\u3055\u306a\u3044\r\na = set(&#x5B;1,2,3,4,5,6])\r\nprint a\r\n\r\n# \u8f9e\u66f8\u578b\u30c7\u30fc\u30bf key value\r\nfruit = {&quot;apple&quot;:100, &quot;banana&quot;:200, &quot;pearch&quot;:600}\r\nprint fruit\r\nprint fruit&#x5B;&quot;apple&quot;]\r\nprint &quot;banana&quot; in fruit # True or False\r\nprint fruit.keys()\r\nprint fruit.values()\r\nprint fruit.items()\r\n\r\n# \u7d44\u307f\u8fbc\u307f\r\na = 10\r\nprint &quot;age: %d&quot; % a\r\n# \u30aa\u30d7\u30b7\u30e7\u30f3\u3082\u5229\u7528\u53ef\u80fd\r\nprint &quot;age: %10d&quot; % a\r\nprint &quot;age: %010d&quot; % a\r\n\r\nroot@hostname:\/home\/shimizu\/python# python hensu.py\r\nhello world\r\n\u3053\u3093\u306b\u3061\u306f\r\n\r\nthis\r\nis\r\npen\r\n\r\n50\r\n2\r\n2\r\n8\r\n2\r\n3\r\n100\r\n&#x5B;0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\r\n&#x5B;100, 50, 25]\r\n&#x5B;'2015', '8', '15']\r\n2015-8-15\r\ntuple\r\nset(&#x5B;1, 2, 3, 4, 5, 6])\r\n{'pearch': 600, 'apple': 100, 'banana': 200}\r\n100\r\nTrue\r\n&#x5B;'pearch', 'apple', 'banana']\r\n&#x5B;600, 100, 200]\r\n&#x5B;('pearch', 600), ('apple', 100), ('banana', 200)]\r\nage: 10\r\nage:         10\r\nage: 0000000010\r\n<\/pre>\n<h1>\u578b\u306e\u5909\u63db\u306b\u6ce8\u610f<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# cat henkan.py\r\n# coding: UTF-8\r\n# \u6570\u5024 int float\r\n# \u6587\u5b57\u5217 str\r\nprint 5 + int(&quot;5&quot;)\r\nage = 20\r\nprint &quot;i am &quot; + str(age) + &quot; years old&quot;\r\n\r\nroot@hostname:\/home\/shimizu\/python# python henkan.py\r\n10\r\ni am 20 years old\r\n<\/pre>\n<h1>\u6587\u5b57\u5217\u64cd\u4f5c<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# cat mojisousa.py\r\n# coding: UTF-8\r\nword = &quot;abcdefghijklm&quot;\r\nprint len(word)\r\nprint word.find(&quot;b&quot;)\r\n# 2\u756a\u76ee\u304b\u30895\u756a\u76ee\u3092\u8868\u793a\u3059\u308b\r\nprint word&#x5B;2:5]\r\n\r\nroot@hostname:\/home\/shimizu\/python# python mojisousa.py\r\n13\r\n1\r\ncde\r\n<\/pre>\n<h1>if\u6587<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# cat if.py\r\n# coding: UTF-8\r\nscore = 50\r\n# if \u4ee5\u4e0b\u3092\u5b57\u4e0b\u3052\u3059\u308b\r\nif score &gt; 60:\r\n    print &quot;OK!&quot;\r\nelif score &gt; 40:\r\n    print &quot;SOSO..&quot;\r\nelse:\r\n    print &quot;NG!&quot;\r\n\r\nroot@hostname:\/home\/shimizu\/python# python if.py\r\nSOSO..\r\n<\/pre>\n<h1>\u30eb\u30fc\u30d7\u6587<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# cat loop.py\r\n# coding: UTF-8\r\n\r\nfruits = &#x5B;&quot;apple&quot;,&quot;banana&quot;,&quot;orange&quot;]\r\nfor fruit in fruits:\r\n    print fruit\r\n# for\u6587\u304c\u7d42\u308f\u3063\u305f\u3089\u5b9f\u884c\u3059\u308b\r\nelse:\r\n    print &quot;Finish&quot;\r\n\r\nfor i in range(4):\r\n    if i ==2:\r\n        continue\r\n    print &quot;number&quot;\r\n    print i\r\nprint &quot;Finish&quot;\r\n\r\nvegis = {&quot;cabbage&quot;:200,&quot;carrot&quot;:100,&quot;radish&quot;:150}\r\nfor key,value in vegis.iteritems():\r\n        print &quot;key:%s value:%d&quot; % (key,value)\r\n\r\nfor key in vegis.iterkeys():\r\n     print key\r\nfor value in vegis.itervalues():\r\n     print value\r\n\r\n# while\u6587\r\nprint &quot;while&quot;\r\nn = 0\r\nwhile n &lt; 10:\r\n    print n\r\n    n += 1\r\nelse:\r\n    print &quot;Finish&quot;\r\n\r\nroot@hostname:\/home\/shimizu\/python# python loop.py\r\napple\r\nbanana\r\norange\r\nFinish\r\nnumber\r\n0\r\nnumber\r\n1\r\nnumber\r\n3\r\nFinish\r\nkey:radish value:150\r\nkey:cabbage value:200\r\nkey:carrot value:100\r\nradish\r\ncabbage\r\ncarrot\r\n150\r\n200\r\n100\r\nwhile\r\n0\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\nFinish\r\n<\/pre>\n<h1>\u65e5\u4ed8\u64cd\u4f5c<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# cat datetime.py\r\n# -*- coding: utf-8 -*-\r\nimport datetime\r\n\r\nif __name__ == &quot;__main__&quot;:\r\n    today = datetime.date.today()\r\n    todaydetail = datetime.datetime.today()\r\n\r\n    print today\r\n    print todaydetail\r\n\r\n    print todaydetail + datetime.timedelta(days=1)\r\n\r\n    newyear = datetime.datetime(2016,1,1)\r\n    print newyear\r\n\r\n    lastday = newyear - todaydetail\r\n    print lastday.days\r\nroot@hostname:\/home\/shimizu\/python# python datetime.py\r\n2015-08-19\r\n2015-08-19 23:07:22.489915\r\n2015-08-20 23:07:22.489915\r\n2016-01-01 00:00:00\r\n134\r\n<\/pre>\n<h1>\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5229\u7528<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# cat module.py\r\n# coding: UTF-8\r\nimport math, random\r\n# \u5207\u308a\u4e0a\u3052\u3059\u308b\r\nprint math.ceil(5.2)\r\nprint random.random()\r\n\r\nroot@hostname:\/home\/shimizu\/python# python module.py\r\n6.0\r\n0.655057714917\r\n<\/pre>\n<h1>\u95a2\u6570<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# cat function.py\r\n# coding: UTF-8\r\ndef hello(name):\r\n    print &quot;hello %s&quot; % name\r\n\r\nhello(&quot;John&quot;)\r\nhello(&quot;Agrini&quot;)\r\n\r\nroot@hostname:\/home\/shimizu\/python# python function.py\r\nhello John\r\nhello Agrini\r\n<\/pre>\n<h1>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nroot@hostname:\/home\/shimizu\/python# cat object.py\r\n# coding: UTF-8\r\n# \u30af\u30e9\u30b9:\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u8a2d\u8a08\u56f3\r\n# \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9:\u30af\u30e9\u30b9\u3092\u5b9f\u4f53\u5316\u3057\u305f\u3082\u306e\r\nclass User(object):\r\n     def __init__(self,name):\r\n         self.name = name\r\n     def greet(self):\r\n         print &quot;my name is %s!&quot; % self.name\r\n\r\nbob = User(&quot;Bob&quot;)\r\nprint bob.name\r\nbob.greet()\r\n\r\n# \u7d99\u627f\r\nclass SuperUser(User):\r\n    def shout(self):\r\n        print &quot;%s is SUPER!!&quot; % self.name\r\n\r\ntom = SuperUser(&quot;Tom&quot;)\r\ntom.greet()\r\ntom.shout()\r\n\r\nroot@hostname:\/home\/shimizu\/python# python object.py\r\nBob\r\nmy name is Bob!\r\nmy name is Tom!\r\nTom is SUPER!!\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 \u30c9\u30c3\u30c8\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304a\u52c9\u5f37\u3057\u305f\u3053\u3068\u3092\u30e1\u30e2 http:\/\/dotinstall.com\/lessons\/basic_python_v2 python\u3068\u306f \u30b7\u30f3\u30d7\u30eb\u3067\u53d6\u5f97\u3057\u3084\u3059\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u8a00\u8a9e Hello Wor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[76],"tags":[],"_links":{"self":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/2051"}],"collection":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2051"}],"version-history":[{"count":2,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/2051\/revisions"}],"predecessor-version":[{"id":2054,"href":"https:\/\/tech.akat.info\/index.php?rest_route=\/wp\/v2\/posts\/2051\/revisions\/2054"}],"wp:attachment":[{"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.akat.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}