{"id":5022,"date":"2014-04-22T05:25:27","date_gmt":"2014-04-21T20:25:27","guid":{"rendered":"https:\/\/mimumimu.net\/blog\/?p=5022"},"modified":"2014-05-04T20:26:31","modified_gmt":"2014-05-04T11:26:31","slug":"python-%e3%81%ae%e5%86%85%e5%8c%85%e8%a1%a8%e7%8f%be%e3%81%a8%e6%bc%94%e7%ae%97%e5%ad%90%e3%81%a8%e3%80%82","status":"publish","type":"post","link":"https:\/\/mimumimu.net\/blog\/2014\/04\/22\/python-%e3%81%ae%e5%86%85%e5%8c%85%e8%a1%a8%e7%8f%be%e3%81%a8%e6%bc%94%e7%ae%97%e5%ad%90%e3%81%a8%e3%80%82\/","title":{"rendered":"Python \u306e\u5185\u5305\u8868\u73fe\u3068\u6f14\u7b97\u5b50\u3068\u3002"},"content":{"rendered":"<p>\u307f\u3080\u3089\u3067\u3059\u3002<\/p>\n<p>\u6700\u8fd1\u3061\u3087\u3063\u3068 Python \u3092\u89e6\u3063\u3066\u307f\u3088\u3046\u304b\u3068\u3068\u3044\u3046\u3053\u3068\u3067\u3001    <br \/>\u3057\u3070\u3089\u304f\u3076\u308a\u306b\u89e6\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3063\u3066\u3053\u3068\u3067\u5fd8\u308c\u305d\u3046\u306a\u3053\u3068\u306e\u30e1\u30e2\u3002<\/p>\n<p>\u30fb\u30fb\u30fbPython \u3092\u3088\u304f\u4f7f\u3063\u3066\u3044\u308b\u4eba\u304b\u3089\u3059\u308b\u3068\u3076\u3093\u6bb4\u3089\u308c\u305d\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u304c\u3001    <br \/>\u3068\u308a\u3042\u3048\u305a\u3001\u52c9\u5f37\u3068\u3044\u3046\u3053\u3068\u3067\u8e93\u3044\u305f\u3068\u3053\u308d\u3092\u30e1\u30e2\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>&#160;<\/p>\n<h4>\u5185\u5305\u8868\u73fe\uff1a<\/h4>\n<p>[<strong>\u8ffd\u52a0\u8981\u7d20<\/strong> for <strong>\u5909\u6570<\/strong> in <strong>\u30ea\u30b9\u30c8<\/strong> if <strong>\u6761\u4ef6<\/strong>]<\/p>\n<p>\u4f7f\u3044\u65b9\u3068\u3057\u3066\u306f\u3001<\/p>\n<div id=\"scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:4b0d0335-9963-4b80-8602-3e6425da4262\" class=\"wlWriterEditableSmartContent\" style=\"float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px\">\n<pre class=\"brush: python;\">l = ((0,1),(2,3),(4,5))\nm = [i for (i,j) in l]\n&gt;&gt; (0,2,4)<\/pre>\n<\/div>\n<p>\u307f\u305f\u3044\u306a\u3002<\/p>\n<p>\u306a\u3093\u3068\u306a\u304f\u3001C# \u3060\u3068\u3001 <\/p>\n<div id=\"scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:fb23bc50-ffa9-427f-bcd7-a8dd75ec5ab9\" class=\"wlWriterEditableSmartContent\" style=\"float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px\">\n<pre class=\"brush: c#;\">var l = new[] { new[] { 0, 1 }, new[] { 2, 3 }, new[] { 4, 5 } };\nvar m = l.Select(i =&gt; i[0]);<\/pre>\n<\/div>\n<p>\u307f\u305f\u3044\u306a\u611f\u3058\u30fb\u30fb\u3067\u3059\u304b\u306d\u3002<\/p>\n<p>\u3042\u3068\u306f\u6761\u4ef6\u5f0f\u3092\u52a0\u3048\u3066\u3001 <\/p>\n<div id=\"scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:22d3c9e1-255c-4700-8f76-fb7186eab72d\" class=\"wlWriterEditableSmartContent\" style=\"float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px\">\n<pre class=\"brush: python;\">[i for (i,j) in l if i &gt; 0]<\/pre>\n<\/div>\n<p>\u307f\u305f\u3044\u306a\u3084\u3064\u306b\u95a2\u3057\u3066\u306f<\/p>\n<div id=\"scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:dd86e3dc-5a8f-411c-a2d3-3acee0e55396\" class=\"wlWriterEditableSmartContent\" style=\"float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px\">\n<pre class=\"brush: c#;\">var l = new[] { new[] { 0, 1 }, new[] { 2, 3 }, new[] { 4, 5 } };\nvar m = l.Where(i =&gt; i[0] &gt; 0).Select(i =&gt; i[0]);<\/pre>\n<\/div>\n<p>\u307f\u305f\u3044\u306a\u611f\u3058\u3002<\/p>\n<p>&#160;<\/p>\n<hr \/>\n<h4>\u6f14\u7b97\u5b50\u306e\u30e1\u30e2\uff1a<\/h4>\n<p>\u5272\u308a\u7b97\u306b\u304a\u3044\u3066 <strong>\u201c\/\u201d \u3068 \u201c\/\/\u201d \u6f14\u7b97\u5b50<\/strong>\u304c\u3042\u3063\u3066\u3001<\/p>\n<p>3.0\/2.0 = 1.5<br \/>\n  <br \/>3.0\/\/2.0 = 1.0<\/p>\n<p>\u3068\u3044\u3046\u3088\u3046\u306b\u3001<strong>\u201d\/\/\u201d \u6f14\u7b97\u5b50\u3060\u3068\u7d50\u679c\u304c\u6574\u6570\u306b\u4e38\u3081\u3089\u308c\u308b\u3002<\/strong><\/p>\n<p>\u4e38\u3081\u65b9\u3068\u3057\u3066\u306f\u3001<br \/>\n  <br \/>math.floor \u3067\u4e38\u3081\u305f\u6642\u3068\u540c\u3058\u52d5\u4f5c\u3068\u306a\u308b\u3063\u307d\u3044\u3002<\/p>\n<p>1.5 \u2192 1.0<br \/>\n  <br \/>-1.5 \u2192 -2.0<\/p>\n<p>\u8003\u3048\u65b9\u3068\u3057\u3066\u306f\u300c\u8ca0\u306e\u7121\u9650\u5927\u300d\u65b9\u5411\u306b\u4e38\u3081\u308b\u3002<br \/>\n  <br \/>\u30c7\u30fc\u30bf\u3068\u3057\u3066\u8003\u3048\u308b\u306a\u3089\u3001 0x0 \u306e\u65b9\u5411\u306b\u4e38\u3081\u308b\u3001\u3068\u8003\u3048\u308b\u3068\u826f\u3044\u306e\u304b\u3082\u3057\u308c\u306a\u3044\u3002 <\/p>\n<p>\uff08\u8ca0\u6570\u306f\uff12\u306e\u88dc\u6570\u8868\u73fe\u3067\u8868\u73fe\u3055\u308c\u308b\u3053\u3068\u3092\u8003\u3048\u3066\u307f\u308b\u3068\u3002\uff09<\/p>\n<p>\u9006\u306b\u3001 \u201c0\u201d \u65b9\u5411\u306b\u4e38\u3081\u308b\u5834\u5408\u306f\u3001 int \u3067\u62ec\u308b\u3068\u826f\u3044\u611f\u3058\u3002<br \/>\n  <br \/>ex. int(1.5 \/ 1.0)<\/p>\n<p>1.5 \u2192 1.0<br \/>\n  <br \/>-1.5 \u2192 \u20131.0<\/p>\n<p>\u3042\u3068\u306f round \u95a2\u6570\u3067\u4e38\u3081\u308b\u65b9\u6cd5\u306a\u3093\u3066\u306e\u3082\u3042\u308a\u307e\u3059\u304c\u3001<br \/>\n  <br \/>\u3053\u308c\u306f\u6614\u66f8\u3044\u305f\u300c<a href=\"https:\/\/mimumimu.net\/blog\/2012\/02\/01\/%e9%8a%80%e8%a1%8c%e4%b8%b8%e3%82%81%e3%81%a8%e5%9b%9b%e6%8d%a8%e4%ba%94%e5%85%a5%e3%80%82\/\">\u9280\u884c\u4e38\u3081\u3068\u56db\u6368\u4e94\u5165\u3002<\/a>\u300d\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>&#160;<\/p>\n<p>\u305d\u308c\u3068\u3001 <strong>\u201c**\u201d \u6f14\u7b97\u5b50<\/strong>\u304c\u5b58\u5728\u3057\u3001 <\/p>\n<p>\u3053\u308c\u306f C# \u3067\u8a00\u3046\u3068\u3053\u308d\u306e Math.Pow \uff08\u3079\u304d\u4e57\u8a08\u7b97\uff09\u306b\u8a72\u5f53\u3002<\/p>\n<p>ex.)<br \/>\n  <br \/>2**10 = 1024<\/p>\n<hr \/>\n<h4>\u8981\u7d20\u6570\u3092\u6570\u3048\u308b\uff1a<\/h4>\n<p>\u79c1\u81ea\u8eab\u3001\u3061\u3087\u3063\u3068\u306f\u307e\u3063\u305f\u306e\u3067\u3059\u304c\u30fb\u30fb(\u6c57<\/p>\n<p>C++ \u3060\u3068 hoge.size() \u3068\u304b\u66f8\u3044\u3066\u3001<br \/>\n  <br \/>C# \u3060\u3068 hoge.Length \u3060\u3063\u305f\u308a\u3001\u52d5\u7684\u306b\u6c42\u3081\u308b\u5fc5\u8981\u304c\u3042\u308b\u7269\u306b\u3064\u3044\u3066\u306f hoge.Length() \u3060\u3063\u305f\u308a\u3002<\/p>\n<p>Python \u306e\u5834\u5408\u306f\u3001 <strong>len(hoge)<\/strong> \u3067\u6c42\u307e\u308b\u3002<\/p>\n<p>\u307e\u305f\u3001 hoge.count() \u3068\u53e9\u304f\u3068\u300c\u5f15\u6570\u304c\u8db3\u308a\u306a\u3044\uff01\u300d\u3068\u6012\u3089\u308c\u308b\u3093\u3067\u3059\u304c\u3001<br \/>\n  <br \/>\u3053\u308c\u306f C# \u306e hoge.Count(1) \u3068\u540c\u3058\u3067\u3001\u8981\u7d20\u5185\u306b\u6307\u5b9a\u3055\u308c\u305f\u3082\u306e\u304c\u3044\u304f\u3064\u5165\u3063\u3066\u3044\u308b\u304b\u3092\u8fd4\u3059\u30e1\u30bd\u30c3\u30c9\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001C# \u306e hoge.Count() \u306e\u3088\u3046\u306b\u3001\u5f15\u6570\u306a\u3057\u3060\u3068\u8981\u7d20\u6570\u304c\u8fd4\u3063\u3066\u304f\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u306a\u304f\u3001<br \/>\n  <br \/>\u300c\u5f15\u6570\u304c\u8db3\u3089\u306a\u3044\uff01\u300d\u3068\u3057\u304b\u3089\u308c\u308b\u3060\u3051\u306a\u306e\u3067\u6ce8\u610f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u307f\u3080\u3089\u3067\u3059\u3002 \u6700\u8fd1\u3061\u3087\u3063\u3068 Python \u3092\u89e6\u3063\u3066\u307f\u3088\u3046\u304b\u3068\u3068\u3044\u3046\u3053\u3068\u3067\u3001 \u3057\u3070\u3089\u304f\u3076\u308a\u306b\u89e6\u3063\u3066\u3044\u307e\u3059\u3002 \u3063\u3066\u3053\u3068\u3067\u5fd8\u308c\u305d\u3046\u306a\u3053\u3068\u306e\u30e1\u30e2\u3002 \u30fb\u30fb\u30fbPython \u3092\u3088\u304f\u4f7f\u3063\u3066\u3044\u308b\u4eba\u304b\u3089\u3059\u308b\u3068\u3076\u3093\u6bb4\u3089\u308c\u305d\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u304c\u3001  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[584,498,497],"class_list":["post-5022","post","type-post","status-publish","format-standard","hentry","category-python","tag-python","tag-498","tag-497"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/posts\/5022","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/comments?post=5022"}],"version-history":[{"count":0,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/posts\/5022\/revisions"}],"wp:attachment":[{"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/media?parent=5022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/categories?post=5022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mimumimu.net\/blog\/wp-json\/wp\/v2\/tags?post=5022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}