{"id":1043,"date":"2017-05-01T11:46:34","date_gmt":"2017-05-01T02:46:34","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=1043"},"modified":"2017-04-30T12:37:56","modified_gmt":"2017-04-30T03:37:56","slug":"%e6%96%87%e5%ad%97%e5%88%97%e3%81%ae%e3%82%bc%e3%83%ad%e3%83%91%e3%83%87%e3%82%a3%e3%83%b3%e3%82%b0%ef%bc%88%e3%82%bc%e3%83%ad%e5%9f%8b%e3%82%81%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/1043","title":{"rendered":"\u6587\u5b57\u5217\u306e\u30bc\u30ed\u30d1\u30c7\u30a3\u30f3\u30b0\uff08\u30bc\u30ed\u57cb\u3081\uff09"},"content":{"rendered":"<p>\u306a\u3093\u3089\u304b\u306eID\u3084\u30b3\u30fc\u30c9\u3092\u63a1\u756a\u3059\u308b\u969b\u3001\u6841\u6570\u3092\u5408\u308f\u305b\u308b\u305f\u3081\u6574\u6570\u306e\u6587\u5b57\u5217\u306b\u5bfe\u3057\u3066\u30bc\u30ed\u30d1\u30c7\u30a3\u30f3\u30b0(\u30bc\u30ed\u57cb\u3081)\u3092\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\uff1fpython\u306b\u306f\u8272\u3005\u306a\u65b9\u6cd5\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30bc\u30ed\u30d1\u30c7\u30a3\u30f3\u30b0<\/h2>\n<h3>printf\u5f62\u5f0f<\/h3>\n<p>\u307e\u305a\u306f\u4ee5\u524d\u3054\u7d39\u4ecb\u3057\u305f\u6587\u5b57\u5217\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u5fdc\u7528\u3057\u3066\u30bc\u30ed\u57cb\u3081\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/422#printf\">printf\u5f62\u5f0f<\/a>\u3067\u3059\u304c\u3001\u5909\u63db\u30d5\u30e9\u30b0\u6587\u5b57\u3068\u3044\u3046\u3082\u306e\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002(\u3053\u3053\u3067\u306f\u5909\u63db\u30d5\u30e9\u30b0\u6587\u5b57\u306b\u3064\u3044\u3066\u5168\u3066\u8aac\u660e\u3057\u307e\u305b\u3093\u306e\u3067\u3001\u8208\u5473\u304c\u3042\u308b\u65b9\u306f<a href=\"http:\/\/docs.python.jp\/3.5\/library\/stdtypes.html#printf-style-string-formatting\">\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002)<\/p>\n<p>\u6574\u6570\u5024\u306b\u5bfe\u3057\u30660\u3068\u3044\u3046\u5909\u63db\u30d5\u30e9\u30b0\u6587\u5b57\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30bc\u30ed\u30d1\u30c3\u30c7\u30a3\u30f3\u30b0\u3092\u3057\u3066\u304f\u308c\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u306a\u3093\u3089\u304b\u306eID\u306b\u300citem_4\u6841\u6574\u6570\u300d\u3092\u63a1\u756a\u3057\u305f\u3044\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nid_text = &quot;item_%(number)04d&quot;\r\nitem_id = id_text % {&quot;number&quot; : 3}\r\nprint(item_id) # item_0003\r\n<\/pre>\n<p>\u305f\u3060\u3057\u3001\u3053\u308c\u306f\u5909\u6570\u304c\u6570\u5024\u578b\u3067\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u70b9\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u6587\u5b57\u5217\u578b\u306e\u30e1\u30bd\u30c3\u30c9 zfill<\/h3>\n<p>python\u306e\u6587\u5b57\u5217\u306b\u306f\u69d8\u3005\u306a\u30e1\u30bd\u30c3\u30c9\u304c\u4e88\u3081\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001zfill\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b\u30680\u57cb\u3081\u3092\u3057\u3066\u304f\u308c\u307e\u3059\u3002\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u9577\u3055\u3067'0'\u3067\u5de6\u8a70\u3081\u3057\u305f\u6587\u5b57\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002\u5143\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u5909\u66f4\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nprint(&quot;5&quot;.zfill(4)) # 0005\r\n<\/pre>\n<p>\u3053\u308c\u306f\u308f\u304b\u308a\u3084\u3059\u3044\u3067\u3059\u306d\u3002\u6570\u5024\u3067\u3082printf\u5f62\u5f0f\u3092\u4f7f\u3044\u305f\u304f\u306a\u3044\u5834\u5408\u306fstr\u30e1\u30bd\u30c3\u30c9\u3067\u6587\u5b57\u5217\u306b\u5909\u63db\u3059\u308c\u3070zfill\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>0\u4ee5\u5916\u3067\u30d1\u30c3\u30c7\u30a3\u30f3\u30b0\u3059\u308b\u3001\u53f3\u5bc4\u305b\u5de6\u5bc4\u305b\u4e2d\u592e\u5bc4\u305b\u3092\u3059\u308b<\/h2>\n<p>\u3055\u3089\u306b\u30010\u4ee5\u5916\u3067\u30d1\u30c3\u30c7\u30a3\u30f3\u30b0\u3059\u308b\u5834\u5408\u3001\u53f3\u5bc4\u305b\u3001\u5de6\u5bc4\u305b\u3001\u4e2d\u592e\u5bc4\u305b\u3067\u305d\u308c\u305e\u308crjust\u3001ljust\u3001center\u3068\u3044\u3046\u6587\u5b57\u5217\u578b\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u3061\u3089\u3082\u5143\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u5909\u66f4\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<h3>\u6587\u5b57\u5217\u578b\u306e\u30e1\u30bd\u30c3\u30c9 rjust\u3001ljust\u3001center<\/h3>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntext = &quot;hoge&quot;\r\nprint(text.rjust(8, &quot;*&quot;))  # ****hoge\r\nprint(text.ljust(8, &quot;*&quot;))  # hoge****\r\nprint(text.center(8, &quot;*&quot;)) # **hoge**\r\n<\/pre>\n<p>\u3053\u308c\u3082\u308f\u304b\u308a\u3084\u3059\u3044\u3067\u3059\u306d\u3002<\/p>\n<p>\n\u8272\u3005\u3042\u308a\u307e\u3059\u304c\u3001\u7528\u9014\u306b\u5fdc\u3058\u3066\u4f7f\u3044\u5206\u3051\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u306a\u3093\u3089\u304b\u306eID\u3084\u30b3\u30fc\u30c9\u3092\u63a1\u756a\u3059\u308b\u969b\u3001\u6841\u6570\u3092\u5408\u308f\u305b\u308b\u305f\u3081\u6574\u6570\u306e\u6587\u5b57\u5217\u306b\u5bfe\u3057\u3066\u30bc\u30ed\u30d1\u30c7\u30a3\u30f3\u30b0(\u30bc\u30ed\u57cb\u3081)\u3092\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\uff1fpython\u306b\u306f\u8272\u3005\u306a\u65b9\u6cd5\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u30bc\u30ed\u30d1\u30c7\u30a3\u30f3\u30b0 printf\u5f62\u5f0f...<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1043"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=1043"}],"version-history":[{"count":4,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1043\/revisions"}],"predecessor-version":[{"id":1047,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1043\/revisions\/1047"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=1043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=1043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=1043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}