{"id":3761,"date":"2022-01-13T22:38:44","date_gmt":"2022-01-13T13:38:44","guid":{"rendered":"https:\/\/www.python.ambitious-engineer.com\/?p=3761"},"modified":"2022-01-13T22:38:44","modified_gmt":"2022-01-13T13:38:44","slug":"%e3%82%bb%e3%82%a4%e3%82%a6%e3%83%81%e6%bc%94%e7%ae%97%e5%ad%90","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/3761","title":{"rendered":"\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50"},"content":{"rendered":"<p>\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u3001Python3.8\u304b\u3089\u767b\u5834\u3057\u305f\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50\uff08\u4ee3\u5165\u5f0f\uff09\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h2>\u4ee3\u5165\u306b\u304a\u3051\u308b\u6587\u3068\u5f0f<\/h2>\n<p>\u666e\u6bb5\u3042\u307e\u308a\u610f\u8b58\u3092\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b3\u30fc\u30c9\u3092\u69cb\u6210\u3059\u308b\u3082\u306e\u306b\u6587\u3068\u5f0f\u304c\u3042\u308a\u307e\u3059\u3002\u304b\u306a\u308a\u96d1\u306a\u8aac\u660e\u3067\u3059\u304c\u3001\u305d\u308c\u305e\u308c\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5f0f\u30fb\u30fb\u30fb\u4f55\u304b\u3057\u3089\u306e\u8a55\u4fa1\u5024\u3092\u6301\u3061\u3001\u305d\u308c\u8fd4\u3059<\/li>\n<li>\u6587\u30fb\u30fb\u30fb\u624b\u7d9a\u304d\u3092\u8868\u3059\uff08\u5024\u3092\u6301\u305f\u306a\u3044\u3001\u8fd4\u3055\u306a\u3044\uff09<\/li>\n<\/ul>\n<p>\u4f8b\u3048\u3070\u3001Python\u306eif\u6587\u81ea\u4f53\u306f\u5024\u3092\u8fd4\u3055\u306a\u3044\u306e\u3067\u305d\u306e\u540d\u306e\u901a\u308a\u6587\u3068\u306a\u308a\u307e\u3059\u3002\u4e00\u65b9\u3001\u6f14\u7b97\u306f\u305d\u306e\u7d50\u679c\u3092\u53d6\u308a\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u5f0f\u3068\u306a\u308a\u307e\u3059\u3002\u6b63\u78ba\u306a\u8aac\u660e\u306fWikipedia\u7b49\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"https:\/\/ja.wikipedia.org\/wiki\/%E5%BC%8F_(%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0)\" title=\"\u5f0f (\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0) - Wikipedia\">\u5f0f (\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0) - Wikipedia<\/a><br \/>\n<a href=\"https:\/\/ja.wikipedia.org\/wiki\/%E6%96%87_(%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0)\" title=\"\u6587 (\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0) - Wikipedia\">\u6587 (\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0) - Wikipedia<\/a><\/p>\n<p>\u3055\u3066\u3001Python\u306b\u304a\u3044\u3066\u4ee3\u5165\u306f\u4ee3\u5165\u6587\u3068\u3082\u547c\u3070\u308c\u5024\u3092\u8fd4\u3057\u307e\u305b\u3093\u3002\u3053\u306e\u305f\u3081\u3001\u5909\u6570\u306b\u306a\u306b\u304b\u5024\u3092\u4ee3\u5165\u3057\u3001\u305d\u308c\u3092\u3055\u3089\u306b\u8a08\u7b97\u3084\u8a55\u4fa1\u306b\u3064\u304b\u3046\u3001\u3068\u3044\u3046\u51e6\u7406\u30921\u884c\u3067\u8a18\u8ff0\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u4f8b\u3048\u3070\u5909\u6570b\u306b2\u3092\u4ee3\u5165\u3057\u3001b\u30683\u306e\u548c\u3092a\u306b\u4ee3\u5165\u3057\u3088\u3046\u3068\u3057\u3066\u3082\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u306f\u30a8\u30e9\u30fc\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\na = (b = 2) + 3\r\n# SyntaxError: invalid syntax\r\n<\/pre>\n<p>\u3053\u306e\u4e00\u65b9\u3001C\u8a00\u8a9e\u3092\u306f\u3058\u3081\u4e00\u90e8\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u306f\u4ee3\u5165\u306f\u4ee3\u5165\u5f0f\u3068\u547c\u3070\u308c\u3001\u4ee3\u5165\u306e\u8a18\u8ff0\u304b\u3089\u3055\u3089\u306b\u5024\u3092\u53d6\u308a\u51fa\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306fC\u8a00\u8a9e\u306e\u30b3\u30fc\u30c9\u3067\u3059\u304c\u3001\u5909\u6570b\u306b2\u3092\u4ee3\u5165\u3057\u3001b\u30683\u306e\u548c\u3092a\u306b\u4ee3\u5165\u3057\u3066\u3044\u307e\u3059\u3002\u4ee3\u5165\u304c\u5f0f\u3068\u3057\u3066\u632f\u308b\u821e\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;stdio.h&gt;\r\n\r\nint main(void)\r\n{\r\n    int a;\r\n    int b;\r\n    a = (b=2) + 3;\r\n    printf(&quot;%d %d\\n&quot;, a, b);\r\n    return 0;\r\n}\r\n<\/pre>\n<h2>\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50\u306b\u3088\u308b\u4ee3\u5165\u5f0f<\/h2>\n<p>\u4ee3\u5165\u306b\u304a\u3051\u308b\u6587\u3068\u5f0f\u306b\u3064\u3044\u3066\u7406\u89e3\u3057\u305f\u3068\u3053\u308d\u3067\u3044\u3088\u3044\u3088\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002Python3.8\u4ee5\u964d\u3001\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50\u3068\u547c\u3070\u308c\u308b\u6f14\u7b97\u5b50\u300c:=\u300d\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067Python\u3067\u3082\u4ee3\u5165\u5f0f\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u7279\u5fb4\u7684\u306a\u540d\u79f0\u3067\u3059\u304c\u3001\u6f14\u7b97\u5b50:=\u304c\u30bb\u30a4\u30a6\u30c1\u306e\u76ee\u3068\u7259\u306b\u4f3c\u3066\u3044\u308b\u305f\u3081\u3053\u306e\u3088\u3046\u306a\u611b\u79f0\u304c\u3064\u3051\u3089\u308c\u307e\u3057\u305f\u3002\u5192\u982d\u306e\u5148\u7a0b\u306e\u30b3\u30fc\u30c9\u304c\u30a8\u30e9\u30fc\u3060\u3063\u305f\u306e\u306fb\u3078\u306e\u4ee3\u5165\u304c\u6587\u3067\u3042\u3063\u305f\u305f\u3081\u3067\u3059\u3002\u3053\u308c\u3092\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50\u306b\u5909\u3048\u308b\u3068\u4ee3\u5165\u306e\u8a18\u8ff0\u304c\u5f0f\u3068\u306a\u308b\u305f\u3081\u52d5\u4f5c\u3059\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\na = (b:=2) + 3\r\nprint(a, b) # 5, 2\r\n<\/pre>\n<h3>\u6761\u4ef6\u5f0f\u3067\u306e\u6d3b\u7528<\/h3>\n<p>\u3088\u304f\u6319\u3052\u3089\u308c\u308b\u4f7f\u3044\u6240\u3068\u3057\u3066if\u6587\u306e\u6761\u4ef6\u5f0f\u306b\u304a\u3044\u3066\u4ee3\u5165\u3068\u8a55\u4fa1\u3092\u540c\u6642\u306b\u884c\u3046\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f1\u884c\u76ee\u3067\u5909\u6570b\u306b5\u3092\u4ee3\u5165\u3057\u3001\u305d\u308c\u304c3\u3088\u308a\u5c0f\u3055\u3044\u304b\u3069\u3046\u304b\u3092\u8a55\u4fa1\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nif (b := 5) &gt; 3:\r\n    print(str(b) + &quot; &gt; 3&quot;)\r\n<\/pre>\n<p>\u3053\u308c\u3060\u3051\u3060\u3068\u30e1\u30ea\u30c3\u30c8\u304c\u5206\u304b\u308a\u3065\u3089\u3044\u305f\u3081\u3082\u30461\u3064\u4f8b\u3067\u3059\u3002\u4f8b\u3048\u3070\u3001\u30ea\u30b9\u30c8\u306e\u9577\u3055\u304c3\u3092\u8d85\u3048\u308b\u5834\u5408\u306b\u305d\u306e\u9577\u3055\u3092print\u51fa\u529b\u3059\u308b\u5834\u5408\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u304c\u8003\u3048\u3089\u308c\u307e\u3059\u304c\u3001len\u95a2\u6570\u304c2\u56de\u547c\u3073\u51fa\u3055\u308c\u3066\u3044\u308b\u306e\u304c\u30a4\u30de\u30a4\u30c1\u3067\u3059\u306d\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nmy_list = [1, 3, 5, 5, 8]\r\nif len(my_list) &gt; 3:\r\n    print(&quot;\u30ea\u30b9\u30c8\u306e\u9577\u3055\uff1a&quot; + str(len(my_list)))\r\n<\/pre>\n<p>\u4ee3\u5165\u5f0f\u3092\u4f7f\u7528\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nmy_list = [1, 3, 5, 5, 8]\r\nif (n := len(my_list)) &gt; 3:\r\n    print(&quot;\u30ea\u30b9\u30c8\u306e\u9577\u3055\uff1a&quot; + str(n))\r\n<\/pre>\n<p>\u3042\u304f\u307e\u3067\u3082\u500b\u4eba\u7684\u306a\u8003\u3048\u306a\u306e\u3067\u3059\u304c\u3001\u5236\u5fa1\u30d6\u30ed\u30c3\u30af\u306e\u5916\u5074\u3067\u3082\u5909\u6570\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u6761\u4ef6\u5f0f\u3067\u4ee3\u5165\u5f0f\u3092\u4f7f\u7528\u3059\u308b\u306e\u306f\u907f\u3051\u305f\u307b\u3046\u304c\u826f\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b3\u30fc\u30c9\u306e\u5834\u5408\u3001\u8aad\u307f\u624b\u306f\u5909\u6570n\u306fif\u6587\u306b\u307e\u3064\u308f\u308b\u3082\u306e\u304b\u3068\u52d8\u9055\u3044\u3057\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u5b9f\u969b\u306f\u30b3\u30fc\u30c9\u5f8c\u65b9\u3067\u3082\u4f7f\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u6df7\u4e71\u3092\u62db\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nmy_list = [1, 3, 5, 5, 8]\r\nif (n := len(my_list)) &gt; 3:\r\n    print(&quot;\u30ea\u30b9\u30c8\u306e\u9577\u3055\uff1a&quot; + str(len(my_list)))\r\n\r\n\uff1a\r\n\uff1a\r\n\r\n# if\u6587\u306e\u5916\u5074\u3067\u3082n\u3092\u4f7f\u3046\r\nm = n + 1     # \u3053\u306en\u306f\u4e00\u4f53\u3069\u3053\u304b\u3089\u51fa\u3066\u304d\u305f\uff1f\uff1f\r\n<\/pre>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b9\u30b3\u30fc\u30d7\u5916\u3067\u5b9a\u7fa9\u3057\u305f\u307b\u3046\u304c\u8aad\u307f\u624b\u306b\u512a\u3057\u3044\u30b3\u30fc\u30c9\u3068\u8a00\u3048\u305d\u3046\u3067\u3059\u3002Python\u306f\u4ed6\u306e\u8a00\u8a9e\u3068\u6bd4\u8f03\u3057\u3066\u5909\u6570\u306e\u30b9\u30b3\u30fc\u30d7\u304c\u7de9\u3044\u305f\u3081\u3053\u3046\u3044\u3063\u305f\u914d\u616e\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nmy_list = [1, 3, 5, 5, 8]\r\nn = len(my_list)\r\nif n &gt; 3:\r\n    print(&quot;\u30ea\u30b9\u30c8\u306e\u9577\u3055\uff1a&quot; + str(len(my_list)))\r\n\r\n\uff1a\r\n\uff1a\r\n\r\n# if\u6587\u306e\u5916\u5074\u3067\u3082n\u3092\u4f7f\u3046\r\nm = n + 1\r\n<\/pre>\n<h3>\u5185\u5305\u8868\u8a18\u3067\u306e\u6d3b\u7528<\/h3>\n<p>\u3082\u30461\u3064\u3001\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50\u304c\u771f\u4fa1\u3092\u767a\u63ee\u3059\u308b\u306e\u304c\u5185\u5305\u8868\u8a18\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5185\u5305\u8868\u8a18\u5185\u90e8\u306eif\u6587\u3067\u306e\u5909\u6570\u3092\u4f7f\u7528\u3057\u305f\u3044\u5834\u5408\u306b\u6d3b\u8e8d\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f\u30010\uff5e9\u306e\u6574\u6570x\u306b\u3064\u3044\u3066\u3001\u95a2\u6570y = x^2 - 1\u306e\u5024y\u304c1\u3092\u8d85\u3048\u308b\u3082\u306e\u306e\u307f\u306e\u30ea\u30b9\u30c8\u3092\u69cb\u7bc9\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndata = range(10)\r\n\r\ndef f(x):\r\n    return x**2 - 1\r\n\r\nnew_list = [y for x in data if (y := f(x)) &gt; 1]\r\n# [3, 8, 15, 24, 35, 48, 63, 80]\r\n<\/pre>\n<p>\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u3001\u305d\u308c\u306a\u308a\u306b\u9762\u5012\u306a\u30b3\u30fc\u30c9\u306b\u306a\u308a\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u8272\u3005\u4f7f\u3044\u6240\u306e\u591a\u305d\u3046\u306a\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50\u3067\u3059\u304c\u3001\u305d\u306e\u4ed6\u306e\u4f8b\u3084\u5b9f\u88c5\u306e\u7d4c\u7def\u304cPEP572\u306b\u307e\u3068\u307e\u3063\u3066\u3044\u308b\u305f\u3081\u3001\u5408\u308f\u305b\u3066\u53c2\u7167\u3059\u308b\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0572\/\" title=\"PEP 572 -- Assignment Expressions\">PEP 572 -- Assignment Expressions<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u3001Python3.8\u304b\u3089\u767b\u5834\u3057\u305f\u30bb\u30a4\u30a6\u30c1\u6f14\u7b97\u5b50\uff08\u4ee3\u5165\u5f0f\uff09\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 \u4ee3\u5165\u306b\u304a\u3051\u308b\u6587\u3068\u5f0f \u666e\u6bb5\u3042\u307e\u308a\u610f\u8b58\u3092\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b3\u30fc\u30c9\u3092\u69cb\u6210\u3059\u308b\u3082\u306e\u306b\u6587\u3068\u5f0f\u304c\u3042\u308a\u307e\u3059\u3002\u304b\u306a\u308a\u96d1\u306a\u8aac\u660e...<\/p>\n","protected":false},"author":1,"featured_media":3766,"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\/3761"}],"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=3761"}],"version-history":[{"count":8,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/3761\/revisions"}],"predecessor-version":[{"id":3770,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/3761\/revisions\/3770"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3766"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=3761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=3761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=3761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}