{"id":9622,"date":"2018-07-02T18:44:24","date_gmt":"2018-07-02T09:44:24","guid":{"rendered":"https:\/\/www.itblog.jp\/?p=9622"},"modified":"2018-07-14T18:59:13","modified_gmt":"2018-07-14T09:59:13","slug":"python%e3%81%ae%e5%8b%89%e5%bc%b7%e3%83%a1%e3%83%a2","status":"publish","type":"post","link":"https:\/\/www.itblog.jp\/?p=9622","title":{"rendered":"python\u306e\u52c9\u5f37\u30e1\u30e2"},"content":{"rendered":"<p>\u6700\u8fd1\u4eba\u6c17\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u300cpython\u300d\u306b\u3064\u3044\u3066\u3001\u52c9\u5f37\u3092\u3057\u305f\u3053\u3068\u3092\u30e1\u30e2\u3057\u3066\u3044\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u304cphp\u3092\u3053\u308c\u307e\u3067\u30e1\u30a4\u30f3\u306b\u4f7f\u3063\u3066\u3044\u305f\u306e\u3067\u3001python\u306e\u57fa\u672c\u7684\u306a\u3053\u3068\u304c\u7406\u89e3\u3067\u304d\u3066\u3044\u306a\u3044\u305f\u3081\u3001\u500b\u4eba\u7684\u306a\u30e1\u30e2\u3068\u3057\u3066\u66f8\u3044\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h2>\u5909\u6570\u3068\u578b<\/h2>\n<p>python\u306f\u5909\u6570\u3092\u5ba3\u8a00\u6642\u306b\u3001\u660e\u793a\u7684\u306b\u578b\u3092\u5ba3\u8a00\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\n\u3053\u308c\u306fphp\u3068\u540c\u3058\u3067\u3059\u304c\u3001\u5909\u6570\u3082\u5909\u6570\u3067\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u3092\u8868\u3059\u3001php\u3067\u3044\u3046\u3068 $ \u306e\u3088\u3046\u306a\u4fee\u98fe\u5b50\u3092\u5909\u6570\u306e\u524d\u306b\u3064\u3051\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u5909\u6570\u306f\u4e88\u7d04\u8a9e\u3067\u306a\u3044\u5834\u5408\u306f\u5909\u6570\u3067\u3042\u308b\u3068\u81ea\u52d5\u7684\u306b\u5224\u65ad\u3057\u3066\u51e6\u7406\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>\u914d\u5217<\/h2>\n<p>python\u3067\u914d\u5217\u3092\u5b9a\u7fa9\u3059\u308b\u5834\u5408\u306f\u3001[]\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>array = []<br \/>\narray = [1,3,4,7]<\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u30b7\u30f3\u30d7\u30eb\u306b\u5b9a\u7fa9\u3067\u304d\u307e\u3059\u3002<br \/>\nphp\u3068\u306e\u9055\u3044\u3068\u3057\u3066\u306f\u3001 array()\u306e\u3088\u3046\u306a\u5b9a\u7fa9\u3092\u3059\u308b\u5fc5\u8981\u304c\u306a\u304f\u3001[]\u3060\u3051\u306a\u306e\u3067\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<p>\u914d\u5217\u3092\u53c2\u7167\u3059\u308b\u5834\u5408\u306f<\/p>\n<p>array[1] #\u4e0a\u8a18\u306e\u914d\u5217\u306e\u5834\u54083\u306b\u306a\u308b<\/p>\n<p>\u306e\u3088\u3046\u306b\u53c2\u7167\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u4ed6\u306e\u8a00\u8a9e\u306e\u4ed5\u69d8\u3068\u5909\u308f\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u914d\u5217\u3078\u306e\u8981\u7d20\u306e\u8ffd\u52a0\u306f<\/p>\n<p>array.append(\u8ffd\u52a0\u3059\u308b\u5024)<\/p>\n<p>\u306e\u3088\u3046\u306b\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>\u914d\u5217\u306e\u9577\u3055\u306f<\/p>\n<p>count = len(array)<\/p>\n<p>\u3067\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30bf\u30d7\u30eb<\/h2>\n<p>\u30bf\u30d7\u30eb\u306f\u914d\u5217\u3068\u4f3c\u3066\u3044\u307e\u3059\u304c\u7570\u306a\u308b\u70b9\u306f\u3001\u4e00\u65e6\u30bf\u30d7\u30eb\u306b\u5024\u304c\u5165\u308b\u3068\u5f8c\u3067\u5909\u66f4\u304c\u3067\u304d\u306a\u3044\u306e\u304c\u7570\u306a\u308b\u70b9\u3067\u3059\u3002<\/p>\n<p>tpl = (1,3,4,7)<\/p>\n<p>\u306e\u3088\u3046\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<br \/>\n\u914d\u5217\u306e[]\u304c()\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u8f9e\u66f8\uff08\u9023\u60f3\u914d\u5217\uff09<\/h2>\n<p>php\u3067\u3044\u3046\u3068\u3053\u308d\u306e\u9023\u60f3\u914d\u5217\u306f\u3001python\u3067\u306f\u8f9e\u66f8\u3068\u547c\u3070\u308c\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306e\u69d8\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n<p>array = {&#8216;apple&#8217;:&#8217;\u308a\u3093\u3054&#8217;, &#8216;orange&#8217;:&#8217;\u307f\u304b\u3093&#8217;, &#8216;lemon&#8217;:&#8217;\u30ec\u30e2\u30f3&#8217;}<\/p>\n<p>dict()\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u914d\u5217\u3084\u30bf\u30d7\u30eb\u306e\u96c6\u5408\u3092\u8f9e\u66f8\u306b\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\uff08\u4f8b\uff09<br \/>\narray = [[apple,\u308a\u3093\u3054][orange,\u307f\u304b\u3093][lemon,\u30ec\u30e2\u30f3]]<br \/>\narray = dict(array)<\/p>\n<p>\u4e0a\u8a18\u306e\u4f8b\u306e\u7d50\u679c\u3001array\u306f\u6700\u521d\u306b\u793a\u3057\u305f\u4f8b\u3068\u540c\u3058\u8f9e\u66f8\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u753b\u9762\u51fa\u529b<\/h2>\n<p>print\u6587\u3067\u753b\u9762\u51fa\u529b\u3092\u884c\u3048\u307e\u3059\u3002<\/p>\n<p>print(\u51fa\u529b\u3057\u305f\u3044\u5024)<\/p>\n<p>\u51fa\u529b\u3057\u305f\u3044\u5024\u306f\u5909\u6570\u3067\u3082\u914d\u5217\u3067\u3082\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<h2>\u30b3\u30e1\u30f3\u30c8<\/h2>\n<p>python\u3067\u306e\u30b3\u30e1\u30f3\u30c8\u306f\u3001<br \/>\n# \u30b3\u30e1\u30f3\u30c8<br \/>\n\u3092\u884c\u982d\u306b\u5165\u308c\u308b\u3053\u3068\u3067\u30b3\u30e1\u30f3\u30c8\u3092\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u306f\u4ed6\u306e\u591a\u304f\u306e\u8a00\u8a9e\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n<p>\u8907\u6570\u884c\u30b3\u30e1\u30f3\u30c8\u3092\u5165\u308c\u308b\u306b\u306f<\/p>\n<p>&#8220;&#8221;&#8221;<br \/>\n\u30b3\u30e1\u30f3\u30c8<br \/>\n\u30b3\u30e1\u30f3\u30c8<br \/>\n\u30b3\u30e1\u30f3\u30c8<br \/>\n&#8220;&#8221;&#8221;<\/p>\n<p>&#8221;&#8217;<br \/>\n\u30b3\u30e1\u30f3\u30c8<br \/>\n\u30b3\u30e1\u30f3\u30c8<br \/>\n&#8221;&#8217;<\/p>\n<p>\u306e\u3088\u3046\u306b\u3001\u30b7\u30f3\u30b0\u30eb\u30af\u30aa\u30c6\u30fc\u30b7\u30e7\u30f3\u304b\u3001\u30c0\u30d6\u30eb\u30af\u30aa\u30c6\u30fc\u30b7\u30e7\u30f3\uff13\u3064\u3067\u884c\u3092\u56f2\u3080\u3053\u3068\u3067\u8907\u6570\u884c\u30b3\u30e1\u30f3\u30c8\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h2>\u753b\u9762\u51fa\u529b<\/h2>\n<p>\u753b\u9762\u51fa\u529b\u306f\u3001print\u6587\u3067\u884c\u306a\u3048\u307e\u3059\u3002<\/p>\n<p>print(\u51fa\u529b\u3059\u308b\u5185\u5bb9)<\/p>\n<h2>\u6587\u5b57\u5217\u306e\u7f6e\u63db<\/h2>\n<p>\u6587\u5b57\u5217\u306e\u7f6e\u63db\u306f\u3001\u4ee5\u4e0b\u306e\u8a18\u8ff0\u3067\u884c\u306a\u3048\u307e\u3059<\/p>\n<p>\u6587\u5b57\u5217 = \u6587\u5b57\u5217.replace(&#8220;\u7f6e\u63db\u5143&#8221;, &#8220;\u7f6e\u63db\u5148&#8221;)<\/p>\n<h2>\u6570\u5024\u306e\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8<\/h2>\n<p>python\u3067\u306f\u3001\u6570\u5024\u306e\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u306f\u4f7f\u7528\u3067\u304d\u306a\u3044\u306e\u3067<\/p>\n<p>\u5909\u6570+=1<br \/>\n\u5909\u6570-=1<\/p>\n<p>\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p>\u5909\u6570++<br \/>\n\u5909\u6570&#8211;<\/p>\n<p>\u3053\u308c\u306f\u4f7f\u3048\u307e\u305b\u3093\u3002<\/p>\n<h2>yield\u6587<\/h2>\n<p>yield\u6587\u306f\u3001\u95a2\u6570\u5b9a\u7fa9\u5185\u3067\u4f7f\u7528\u3057\u3001\u6307\u5b9a\u3055\u308c\u305f\u5024\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3046\u3044\u3046\u610f\u5473\u3067\u306fphp\u306e\u95a2\u6570\u5185\u306ereturn\u6587\u3068\u4f3c\u3066\u3044\u307e\u3059\u304c\u3001\u5fae\u5999\u306b\u9055\u3044\u304c\u3042\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>python\u7248\u306ereturn\u6587\u306b\u8fd1\u3044\u5b58\u5728\u3067\u3059\u304c\u3001\u95a2\u6570\u5185\u306b\u8907\u6570\u306eyield\u6587\u304c\u3042\u308b\u5834\u5408\u5168\u3066\u306eyield\u306e\u5024\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001for\u6587\u5185\u306byield\u304c\u4f7f\u7528\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3001for\u6587\u306e\u30eb\u30fc\u30d7\u304c\u7d42\u4e86\u3059\u308b\u307e\u3067\u5024\u3092\u8fd4\u3057\u7d9a\u3051\u307e\u3059\u3002<\/p>\n<h2>for\u6587<\/h2>\n<p>for \u5909\u6570 in \u914d\u5217<br \/>\n   \u301c\u301c\u301c\u301c\u301c<\/p>\n<p>\u914d\u5217\u3092for\u6587\u3067\u30eb\u30fc\u30d7\u3059\u308b\u5834\u5408\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p>\u30eb\u30fc\u30d7\u6587\u306e\u4e2d\u3067\u5909\u6570\u3092\u4f7f\u7528\u3057\u305f\u308a\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u306f\u3001<\/p>\n<p>for num in range(\u6570\u5024)<br \/>\n\u3000\u301c\u301c\u301c\u301c\u301c<\/p>\n<p>\u3068\u3059\u308b\u3053\u3068\u3067\u3001\u6570\u5024\u306e\u56de\u6570\u7e70\u308a\u8fd4\u3057\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\nnum\u306f 0\u3000\u301c\u3000\u6570\u5024-1\u3000\u306e\u9593\u3067\u51e6\u7406\u3055\u308c\u307e\u3059<\/p>\n<h2>mysql\u306e\u5229\u7528<\/h2>\n<p>python\u3067\u306fmysql\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u63a5\u7d9a\u3059\u308b\u305f\u3081\u306b\u306f\u69d8\u3005\u306a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u4e2d\u3067\u3082\u30dd\u30d4\u30e5\u30e9\u30fc\u306a\u3082\u306e\u306e\u4e00\u3064\u306bmysqlclient\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>pip install mysqlclient<\/p>\n<p>\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>IPython<\/h2>\n<p>Python\u306f\u3001\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3067\u300cpython\u300d\u3068\u30bf\u30a4\u30d7\u3059\u308b\u3053\u3068\u3067\u3001quit()\u3067\u7d42\u4e86\u3059\u308b\u307e\u3067\u306e\u9593\u3001\u5bfe\u8a71\u578b\u306e\u30a4\u30f3\u30bf\u30d7\u30ea\u30bf\u5f62\u5f0f\u3067\u5b9f\u884c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u3055\u3089\u306b\u5f37\u5316\u3057\u305f\u306e\u304cIPython\u3067\u3001IPython\u306f\u3001Python\u306e\u5bfe\u8a71\u578b\u5b9f\u884c\u5f62\u5f0f\u3067\u3057\u304b\u4f7f\u7528\u3067\u304d\u306a\u3044\u3082\u306e\u306e\u3001\u305d\u306e\u90e8\u5206\u3092\u5927\u5e45\u306b\u5f37\u5316\u3057\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>python\u3068\u306f\u5225\u306bipython\u3068\u3057\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3067<\/p>\n<p>ipython<\/p>\n<p>\u3068\u30bf\u30a4\u30d7\u3059\u308b\u3053\u3068\u3067\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u901a\u5e38\u306epython\u306e\u5834\u5408<\/p>\n<p>>><\/p>\n<p>\u3068\u3044\u3063\u305f\u5f62\u5f0f\u3067\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u304c\u3001ipython\u306e\u5834\u5408<\/p>\n<p>In[1]:<br \/>\nIn[2]:<br \/>\nIn[3]:<\/p>\n<p>\u3068\u3044\u3063\u305f\u5f62\u5f0f\u3067\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u4e0a\u306b\u8868\u793a\u3055\u308c\u308b\u3053\u3068\u3082\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u4eba\u6c17\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u300cpython\u300d\u306b\u3064\u3044\u3066\u3001\u52c9\u5f37\u3092\u3057\u305f\u3053\u3068\u3092\u30e1\u30e2\u3057\u3066\u3044\u3063\u3066\u3044\u307e\u3059\u3002 \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u304cphp\u3092\u3053\u308c\u307e\u3067\u30e1\u30a4\u30f3\u306b\u4f7f\u3063\u3066\u3044\u305f\u306e\u3067\u3001python\u306e\u57fa\u672c\u7684\u306a\u3053\u3068\u304c\u7406\u89e3\u3067\u304d\u3066\u3044\u306a\u3044\u305f\u3081\u3001\u500b\u4eba\u7684\u306a\u30e1\u30e2\u3068 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[149,125],"tags":[],"class_list":["post-9622","post","type-post","status-publish","format-standard","hentry","category-python","category-125"],"_links":{"self":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/9622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9622"}],"version-history":[{"count":1,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/9622\/revisions"}],"predecessor-version":[{"id":9623,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/9622\/revisions\/9623"}],"wp:attachment":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}