{"id":127,"date":"2019-11-15T16:02:43","date_gmt":"2019-11-15T07:02:43","guid":{"rendered":"http:\/\/aiacademy.jp\/media\/?p=127"},"modified":"2024-08-08T16:34:44","modified_gmt":"2024-08-08T07:34:44","slug":"%e3%80%90%e5%88%9d%e5%bf%83%e8%80%85%e5%90%91%e3%81%91%e3%80%91%e9%96%a2%e6%95%b0%e3%81%a8%e3%81%af%e4%bd%95%e3%81%8b%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/aiacademy.jp\/media\/?p=127","title":{"rendered":"\u3010\u521d\u5fc3\u8005\u5411\u3051\u3011\u95a2\u6570\u3068\u306f\u4f55\u304b\uff1f"},"content":{"rendered":"<div id=\"sgb-css-id-1\">\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-font-size is-style-fill has-medium-font-size\"><a class=\"wp-block-button__link has-vivid-green-cyan-background-color has-background wp-element-button\" href=\"https:\/\/lin.ee\/3E4GzWk\" rel=\"nofollow noopener\" target=\"_blank\">LINE\u53cb\u3060\u3061\u767b\u9332 \u25b6 Python\u30b3\u30fc\u30b9 \u25b6 \u53d7\u8b1b\u5272\u5f15\u30af\u30fc\u30dd\u30f3 \u7121\u6599\u52d5\u753b<\/a><\/div>\n<\/div>\n<\/div>\n\n<div class=\"toc\">    <div id=\"toc_container\" class=\"sgb-toc--no-bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">\u95a2\u6570\u3068\u306f<\/a>  <\/li>  <li>    <a href=\"#i-1\">\u95a2\u6570\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8\u30fb\u30c7\u30e1\u30ea\u30c3\u30c8<\/a>  <\/li>  <li>    <a href=\"#i-2\">\u95a2\u6570\u306e\u5b9a\u7fa9<\/a>  <\/li>  <li>    <a href=\"#i-3\">\u95a2\u6570\u540d<\/a>  <\/li>  <li>    <a href=\"#i-4\">pass<\/a>  <\/li>  <li>    <a href=\"#i-5\">\u5f15\u6570<\/a>  <\/li>  <li>    <a href=\"#i-6\">\u8fd4\u308a\u5024(\u623b\u308a\u5024)<\/a>  <\/li>  <li>    <a href=\"#i-7\">\u5f15\u6570\u3068return<\/a>  <\/li>  <li>    <a href=\"#i-8\">\u306a\u305creturn\u3092\u4f7f\u3046\u306e\u304b<\/a>  <\/li>  <li>    <a href=\"#i-9\">return\u3092\u5229\u7528\u3057\u305f\u95a2\u6570\u306e\u30b5\u30f3\u30d7\u30eb<\/a>  <\/li>  <li>    <a href=\"#i-10\">\u5f15\u6570\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024<\/a>  <\/li>  <li>    <a href=\"#i-11\">\u95a2\u6570 \u5909\u6570\u306e\u30b9\u30b3\u30fc\u30d7<\/a>  <\/li>  <li>    <a href=\"#i-12\">\u30b0\u30ed\u30fc\u30d0\u30eb(global)\u5ba3\u8a00\u30fb\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570<\/a>  <\/li>  <li class=\"last\">    <a href=\"#i-13\">\u307e\u3068\u3081<\/a>  <\/li><\/ul>\n      \n    <\/div><\/div><div class=\"toc\"><p><\/p>\n<\/div><h2 id=\"i-0\">\u95a2\u6570\u3068\u306f<\/h2>\n<p><strong><em>\u95a2\u6570\u3068\u306f\u3042\u308b\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308a\u3001\u5b9a\u3081\u3089\u308c\u305f\u72ec\u81ea\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3057\u3001\u305d\u306e\u7d50\u679c\u3092\u8fd4\u3059\u547d\u4ee4\u306e\u3053\u3068<\/em><\/strong>\u3067\u3059\u3002<br>\u95a2\u6570\u306b\u306f<strong><em>2\u7a2e\u985e<\/em><\/strong>\u3042\u308a\u30011\u3064\u76ee\u306f<strong><em>\u72ec\u81ea\u95a2\u6570<\/em><\/strong>\u30012\u3064\u76ee\u306f<strong><em>\u6a19\u6e96\u95a2\u6570\uff08\u7d44\u307f\u8fbc\u307f\u95a2\u6570\uff09<\/em><\/strong>\u3067\u3059\u3002<br><strong>\u72ec\u81ea\u95a2\u6570\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u304c\u5909\u6570\u3092\u4f5c\u308b\u306e\u3068\u540c\u3058\u3088\u3046\u306b\u81ea\u7531\u306b\u540d\u524d\u3068\u51e6\u7406\u3092\u8003\u3048\u3001\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u304c\u4f5c\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/strong><br>\u95a2\u6570\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u3053\u3068\u3067\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u52b9\u7387\u7684\u306b\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br><strong>\u6a19\u6e96\u95a2\u6570\u306f\u3001Python\u304c\u6700\u521d\u304b\u3089\u7528\u610f\u3057\u3066\u3042\u308b\u95a2\u6570\u3067\u3059\u3002<\/strong><br>\u6a19\u6e96\u95a2\u6570\u306f\u3001print()\u3084len()\u3001input()\u306a\u3069\u3092\u6307\u3057\u307e\u3059\u3002<br>\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u4e16\u754c\u3067\u306f\u3001\u81ea\u7531\u306b\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u3001\u4f5c\u3063\u305f\u95a2\u6570\u3092\u4f55\u5ea6\u3082\u547c\u3073\u51fa\u3057\u3066\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3068\u3044\u3046\u7279\u5fb4\u304c\u3042\u308a\u307e\u3059\u3002<br>\u3053\u306e\u7ae0\u3067\u306f\u4e3b\u306b<strong>\u72ec\u81ea\u95a2\u6570<\/strong>\u306e\u6587\u6cd5\u306b\u91cd\u70b9\u3092\u7f6e\u304d\u3001\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2 id=\"i-1\">\u95a2\u6570\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8\u30fb\u30c7\u30e1\u30ea\u30c3\u30c8<\/h2>\n<p>\u307e\u305a\u3001<strong><em>\u30e1\u30ea\u30c3\u30c8<\/em><\/strong>\u304b\u3089\u8aac\u660e\u3057\u307e\u3059\u3002<br>\u3053\u3053\u3067\u306f\u5927\u304d\u304f2\u3064\u7d39\u4ecb\u3057\u307e\u3059\u3002<br><strong>\uff11\uff09\u30b3\u30fc\u30c9\u304c\u308f\u304b\u308a\u3084\u3059\u304f\u306a\u308b<\/strong><br>\u95a2\u6570\u3092\u4f7f\u3046\u3053\u3068\u306e\u30e1\u30ea\u30c3\u30c8\u3068\u3057\u3066\u3001\u307e\u305a\u30b3\u30fc\u30c9\u304c\u308f\u304b\u308a\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<br>\u5404\u6a5f\u80fd\u3092\u307e\u3068\u3081\u3066\u304a\u304f\u3053\u3068\u3067\u898b\u3084\u3059\u304f\u306a\u308b\u3060\u3051\u3067\u306f\u306a\u304f\u3001\u30c7\u30d0\u30c3\u30b0\u4f5c\u696d\u3082\u52b9\u7387\u826f\u304f\u306a\u308a\u307e\u3059\u3002<br><strong>\uff12\uff09\u95a2\u6570\u3067\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u3092\u6e1b\u3089\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/strong><br>\u30b3\u30fc\u30c9\u306e\u4fdd\u5b88\u6027\u304c\u4e0a\u304c\u308a\u307e\u3059\u3002<br>\u6b21\u306f\u3001<strong><em>\u30c7\u30e1\u30ea\u30c3\u30c8<\/em><\/strong>\u3067\u3059\u304c\u3001\u7d30\u304b\u3044\u8aac\u660e\u3092\u3059\u308b\u3068\u3044\u304f\u3064\u304b\u30d4\u30c3\u30af\u30a2\u30c3\u30d7\u3067\u304d\u307e\u3059\u304c\u3001<br>\u305d\u3053\u307e\u3067\u30c7\u30e1\u30ea\u30c3\u30c8\u3068\u3044\u3046\u30c7\u30e1\u30ea\u30c3\u30c8\u306f\u3042\u307e\u308a\u3042\u3052\u3089\u308c\u307e\u305b\u3093\u3002<br>\u3067\u3059\u306e\u3067\u3001\u7a4d\u6975\u7684\u306b\u95a2\u6570\u3092\u4f5c\u3063\u3066\u4f7f\u3046\u7fd2\u6163\u3092\u4f5c\u3063\u3066\u9802\u3051\u308b\u3068\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u5e45\u3082\u5e83\u304c\u308a\u307e\u3059\u3002<\/p>\n<h2 id=\"i-2\">\u95a2\u6570\u306e\u5b9a\u7fa9<\/h2>\n<p>\u72ec\u81ea\u95a2\u6570\u306e\u8aac\u660e\u3068\u3057\u3066\u3001\u5b9f\u969b\u306b\u95a2\u6570\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<br>\uff08\u203b\u95a2\u6570\u3092\u4f5c\u308b\u3053\u3068\u3092\u95a2\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u306a\u3069\u3068\u8a00\u3044\u307e\u3059\u3002\uff09<br>\u95a2\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u305f\u3081\u306b\u306f\u3001<strong>def<\/strong>\u3068\u3044\u3046\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\"># \u6ce8) \u3053\u306e\u30b3\u30fc\u30c9\u306f\u69cb\u6587\u306e\u305f\u3081\u52d5\u4f5c\u3057\u307e\u305b\u3093\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\ndef \u95a2\u6570\u540d():\n    # \u30a4\u30f3\u30c7\u30f3\u30c8(\u5b57\u4e0b\u3052\uff09\u3092\u3057\u3063\u304b\u308a\u3059\u308b\u3088\u3046\u306b\uff01\n    # \u51e6\u7406 \n<\/code><\/pre>\n<p>\u305d\u308c\u3067\u306f\u4e0a\u8a18\u57fa\u672c\u69cb\u6587\u3092\u30d9\u30fc\u30b9\u306b\u3001hello!\u3068\u51fa\u529b\u3059\u308b\u3060\u3051\u306e\u95a2\u6570hello\u95a2\u6570\u3092\u4f5c\u3063\u3066\u898b\u307e\u3057\u3087\u3046\u3002<br>hello\u304c\u95a2\u6570\u540d\u3067\u3001\u30a4\u30f3\u30c7\u30f3\u30c8\u3057\u305f\u884c\u304b\u3089\u304c\u3001hello\u95a2\u6570\u306e\u51e6\u7406\u306e\u5b9a\u7fa9\u3092\u8a18\u8ff0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code># \u30a4\u30f3\u30c7\u30f3\u30c8\u306f\u534a\u89d2\u30b9\u30da\u30fc\u30b94\u3064\u5206\u306e\u3053\u3068\u3067\u3059\u3002\n# \u4ee5\u4e0b\u3001hello()\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u305f\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002\n\ndef hello():\n    print(\"hello!\")\n<\/code><\/pre>\n<p><strong><em>\u95a2\u6570\u540d\u306f\u5909\u6570\u540d\u3068\u540c\u69d8\u306b\u3001<a href=\"?id=158&amp;section=\u4e88\u7d04\u8a9e\">\u300c\u4e88\u7d04\u8a9e\u300d<\/a>\u3092\u4f7f\u308f\u306a\u3044\u9650\u308a\u3001\u597d\u304d\u306a\u540d\u524d\u3067\u5b9a\u7fa9\u3067\u304d\u307e\u3059\u3002<\/em><\/strong><br>\u5148\u307b\u3069\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u3001hello\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u305f\u3060\u3051\u3067\u3059\u306e\u3067\u3001\u547c\u3073\u51fa\u3057\u306f\u3057\u3066\u3044\u307e\u305b\u3093\u3002<br>\u95a2\u6570\u306f\u5b9a\u7fa9\u3057\u305f\u3060\u3051\u3067\u306f\u5b9f\u884c\u3055\u308c\u305a\u3001\u5b9f\u969b\u306b\u547c\u3073\u51fa\u3059\u3053\u3068\u3067\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u95a2\u6570\u3092\u5b9f\u884c\uff08\u547c\u3073\u51fa\u3059\uff09\u306b\u306f\u6b21\u306e\u3088\u3046\u306b<strong>\u95a2\u6570\u540d()<\/strong>\u3068\u3059\u308b\u3053\u3068\u3067\u547c\u3073\u51fa\u305b\u307e\u3059\u3002\u4e0b\u8a18\u306e\u4f8b\u3067\u306f\u3001\u72ec\u81ea\u95a2\u6570hello()\u3092\u5b9a\u7fa9\u3057\u3001\u547c\u3073\u51fa\u3059(\u5b9f\u884c\u3059\u308b)\u306b\u306f<strong>hello()<\/strong>\u3068\u3057\u307e\u3059\u3002<\/p>\n<pre><code># hello\u95a2\u6570\u306e\u5b9a\u7fa9\ndef hello():\n    print(\"hello!\")\n\n# \u95a2\u6570\u306e\u547c\u3073\u51fa\u3057(\u5b9f\u884c)\nhello() # hello! \u304c\u51fa\u529b\u3055\u308c\u308b\n<\/code><\/pre>\n<p>\u95a2\u6570\u306e\u5b9a\u7fa9\u3067\u306f\u3001\u3042\u304f\u307e\u3067\u3082\u95a2\u6570\u3092\u5b9a\u7fa9\u3057\u305f\u3060\u3051\u3067\u3059\u306e\u3067\u3001\u51e6\u7406\u306f\u884c\u308f\u308c\u3066\u304a\u308a\u307e\u305b\u3093\u3002<br>\u5b9f\u884c\u3059\u308b\u306b\u306f\u3001<strong>\u95a2\u6570\u540d()<\/strong>\u3068\u3042\u308b\u884c\u3067\u547c\u3073\u51fa\u3057\u51e6\u7406\u304c\u884c\u308f\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2 id=\"i-3\">\u95a2\u6570\u540d<\/h2>\n<p>\u95a2\u6570\u540d\u306f\u3001\u958b\u767a\u8005\u304c\u81ea\u7531\u306b\u540d\u524d\u3092\u3064\u3051\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u304c\u3001\u3044\u304f\u3064\u304b\u6ce8\u610f\u70b9\u304c\u3042\u308a\u307e\u3059\u3002<br>\u6ce8\u610f\u70b9\u3068\u3057\u3066\u95a2\u6570\u540d\u3092\u5b9a\u7fa9\u3059\u308b\u969b\u306b\u3001<strong>\u4e88\u7d04\u8a9e\u306a\u3069\u3067\u95a2\u6570\u540d\u3092\u3064\u3051\u306a\u3044\u3053\u3068<\/strong>\u3067\u3059\u3002<br>\u307e\u305f\u3001Python\u3067\u95a2\u6570\u540d\u3092\u72ec\u81ea\u3067\u5b9a\u7fa9\u3059\u308b\u969b\u306b2\u5358\u8a9e\u4ee5\u4e0a\u306e\u95a2\u6570\u540d\u306b\u3059\u308b\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001\u5c0f\u6587\u5b57\u3067\u4e0b\u7dda(_)\u3092\u631f\u3080\u30b9\u30bf\u30a4\u30eb\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code>def lowercase_underscore:\n    print(\"lowercase_underscore\")\n<\/code><\/pre>\n<h2 id=\"i-4\">pass<\/h2>\n<p>\u307e\u305f\u3001\u95a2\u6570\u306f\u3001\u7a7a\u306e\u30ea\u30b9\u30c8\u578b\u3084\u3001\u7a7a\u306e\u8f9e\u66f8\u578b\u3092\u5b9a\u7fa9\u3059\u308b\u3068\u304d\u306e\u3088\u3046\u306b\u3001\u4e2d\u8eab\u306e\u51e6\u7406\u306e\u306a\u3044\u95a2\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br><strong>\u3068\u308a\u3042\u3048\u305a\u95a2\u6570\u3092\u5ba3\u8a00\u3057\u3066\u304a\u3044\u3066\u3001\u95a2\u6570\u306e\u51e6\u7406\u3068\u3057\u3066\u306f\u4f55\u3082\u3057\u306a\u3044\u6642\u306f\u3001\u300cpass\u300d\u3092\u4f7f\u3044\u307e\u3059\u3002<\/strong><\/p>\n<pre><code># \u4f55\u3082\u51e6\u7406\u306e\u306a\u3044test\u95a2\u6570\u3092\u5b9a\u7fa9\ndef test():\n    pass\n<\/code><\/pre>\n<h2 id=\"i-5\">\u5f15\u6570<\/h2>\n<p>\u5f15\u6570\u3068\u306f\u3001<strong>\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u969b\u306b\u95a2\u6570\u306b\u4e0e\u3048\u308b\u5024\u306e\u3053\u3068<\/strong>\u3067\u3059\u3002<br>\u5927\u304d\u304f2\u7a2e\u985e\u306b\u5206\u3051\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br><strong>1) \u4eee\u5f15\u6570\uff08\u95a2\u6570\u306e\u5b9a\u7fa9\u5074\u3067\u53d7\u3051\u53d6\u308b\u5024\uff09<\/strong><br><strong>2) \u5b9f\u5f15\u6570\uff08\u95a2\u6570\u306e\u547c\u3073\u51fa\u3057\u5074\u3067\u4e0e\u3048\u308b\u5024\uff09<\/strong><br>\u4ee5\u4e0b\u3001\u5f15\u6570\u3092\u7528\u3044\u305f\u95a2\u6570\u306e\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<\/p>\n<pre><code>def say_hello(name):\n    print(\"\u3053\u3093\u306b\u3061\u306f\" + str(name) + \"\u3055\u3093\")\n\nsay_hello(\"\u5c71\u7530\") # \u3053\u3093\u306b\u3061\u306f\u5c71\u7530\u3055\u3093\n<\/code><\/pre>\n<h2 id=\"i-6\">\u8fd4\u308a\u5024(\u623b\u308a\u5024)<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/camo.qiitausercontent.com\/591f54b285d24b3b59e7d6aa40049b6e485622b5\/68747470733a2f2f71696974612d696d6167652d73746f72652e73332e616d617a6f6e6177732e636f6d2f302f3130353838372f31356365303534612d636536632d633364372d656532652d3366383339353033373435332e706e67\" alt=\"\"><\/p>\n<p>\u95a2\u6570\u3067\u51e6\u7406\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u547c\u3073\u51fa\u3057\u5143\u306b\u8fd4\u3057\u307e\u3059\u3002<br>\u5f8c\u307b\u3069\u3001\u300c\u5f15\u6570\u3068return\u300d\u306b\u3066\u8a73\u3057\u304f\u898b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2 id=\"i-7\">\u5f15\u6570\u3068return<\/h2>\n<p>\u5148\u307b\u3069\u3001\u8fd4\u308a\u5024(\u623b\u308a\u5024)\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u305f\u304c\u3001return\u6587\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u95a2\u6570\u3092\u7d42\u4e86\u3057\u547c\u3073\u51fa\u3057\u5143\u306b\u623b\u308a\u307e\u3059\u3002<\/p>\n<p><strong>return \u3010\u8fd4\u308a\u5024(\u623b\u308a\u5024)\u3011<\/strong><br>\u5f15\u6570\u3068\u8fd4\u308a\u5024(\u623b\u308a\u5024)\u304c\u3042\u308b\u5834\u5408\u306e\u95a2\u6570\u306e\u66f8\u5f0f\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<br>\u623b\u308a\u5024\u3092\u7701\u7565\u3057\u305f\u5834\u5408\u306f\u3001None\u304c\u8fd4\u308a\u5024(\u623b\u308a\u5024)\u3068\u306a\u308a\u307e\u3059\u3002<br>\u307e\u305f\u3001\u95a2\u6570\u5185\u3067return\u304c\u5b9f\u884c\u3055\u308c\u305f\u5834\u5408\u3082\u3001\u623b\u308a\u5024\u306fNone\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code>\"\"\"\ndef \u95a2\u6570\u540d(\u5f15\u6570):\n    \u51e6\u7406\n    return \u8fd4\u308a\u5024\n\"\"\"\ndef adder(a, b):\n    return a+b\n\n# \u95a2\u6570\u5185\u90e8\u306e\u51e6\u7406\u3092\u5909\u6570\u306b\u4fdd\u6301\u3057\u3066\u304a\u304d\u305f\u3044\u6642\u306breturn\u306f\u4fbf\u5229\u3067\u3059\u3002\nvalue = adder(5,10) # \u5909\u6570value\u306b15\u304c\u4ee3\u5165\u3055\u308c\u308b\n\n\n\n# \u5148\u307b\u3069\u306elen()\u3092\u7528\u3044\u3066\u8fd4\u308a\u5024\uff08\u623b\u308a\u5024\uff09\u306b\u95a2\u3057\u3066\u8aac\u660e\u3057\u307e\u3059\u3002\n# \u5909\u6570data\u306f\u30011\u301c5\u306e5\u3064\u306e\u8981\u7d20\u3092\u6301\u3063\u305f\u30ea\u30b9\u30c8\u3067\u3059\u3002\ndata = [1,2,3,4,5]\n\n\"\"\"\n\u95a2\u6570len()\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u3001\u30ea\u30b9\u30c8\u3067\u3042\u308bdata\u306e\u8981\u7d205\u304c\u8fd4\u308a\u5024\u306b\u306a\u308a\u307e\u3059\u3002\n\u305d\u306e\u8fd4\u308a\u50245\u304c\u5909\u6570value\u306b\u4ee3\u5165\u3055\u308c\u307e\u3059\u3002\n\"\"\"\nvalue = len(data)\n\nprint(value) # 5\n<\/code><\/pre>\n<p>\u4e0a\u8a18len()\u3092\u56f3\u306b\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6d41\u308c\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/aiacademy.jp\/assets\/images\/return.png\" alt=\"\"><\/p>\n<p>\u307e\u305a\u5909\u6570data\u306b[1,2,3,4,5]\u304c\u4ee3\u5165\u3055\u308c\u3001\u30ea\u30b9\u30c8\u3068\u3057\u3066\u5b9a\u7fa9\u3055\u308c\u307e\u3059\u3002<br>\u6b21\u306b\u3001len()\u95a2\u6570\u306b\u3088\u3063\u3066\u30ea\u30b9\u30c8\u3067\u3042\u308bdata\u306e\u8981\u7d20\u306e\u6570\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<br>\u305d\u306e\u53d6\u5f97\u3057\u305f\u7d50\u679c\u304creturn\u306b\u3088\u3063\u3066\u8fd4\u3055\u308c\u3066\u304a\u308a\u3001\u3053\u306e\u8fd4\u3055\u308c\u305f\u5024\u304c\u8fd4\u308a\u5024\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u306e\u5f8c\u3001\u8fd4\u308a\u50245\u304c\u5909\u6570value\u306b\u4ee3\u5165\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2 id=\"i-8\">\u306a\u305creturn\u3092\u4f7f\u3046\u306e\u304b<\/h2>\n<p>\u306a\u305cprint()\u3067\u306f\u306a\u304f\u3001return\u3092\u4f7f\u3046\u306e\u304b\u3068\u3044\u3046\u70b9\u304c\u3044\u307e\u3044\u3061\u30d4\u30f3\u3068\u6765\u306a\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<br>\u3053\u306e\u7bc0\u3067\u306f\u3001\u591a\u304f\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u521d\u5fc3\u8005\u304c\u3064\u307e\u305a\u304d\u3084\u3059\u3044<br><strong>\u306a\u305c\u95a2\u6570\u5185\u3067\u3001print()\u3067\u306f\u306a\u304freturn\u3092\u4f7f\u3046\u306e\u304b\u3068\u3044\u3046\u9055\u3044\u306b\u8aac\u660e\u3057\u307e\u3059\u3002<\/strong><br><strong><em>\u5927\u524d\u63d0\u3068\u3057\u3066\u3001print()\u3068return\u306f\u5168\u304f\u306e\u5225\u7269\u306a\u305f\u3081\u3001\u3057\u3063\u304b\u308a\u4f7f\u3044\u5206\u3051\u304c\u51fa\u6765\u308b\u3088\u3046\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/em><\/strong><br>\u307e\u305a\u30012\u3064\u306e\u9055\u3044\u3068\u3057\u3066\u306f\u6b21\u306e\u901a\u308a\u3067\u3059\u3002<br><strong>return\u306f\u5024\u3092\u8fd4\u3059\u3053\u3068\u304c\u76ee\u7684<\/strong><br><strong>print()\u306f\u5024\u3092\u51fa\u529b\u3059\u308b\u3053\u3068\u76ee\u7684<\/strong><br><strong><em>\u3064\u307e\u308a\u3001return\u3092\u4f7f\u3046\u3068\u3044\u3046\u3053\u3068\u306f\u5024\u3092\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308b\u6642\u306b\u4f7f\u7528\u3059\u308b<\/em><\/strong>\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<br><strong><em>\u5177\u4f53\u7684\u306breturn\u3092\u4f7f\u3063\u305f\u6b63\u3057\u3044\u4f8b<\/em><\/strong>\u306b\u95a2\u3057\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<br>\u3067\u306f\u3001\u307e\u305a\u4ee5\u4e0b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u898b\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><code>def adder1(a, b):\n    print(a+b)\n\ndef adder2(a, b):\n    return a + b\n\nadder1(2, 4)\nsum = adder2(2, 4)\nprint(sum)\n<\/code><\/pre>\n<p>\u3053\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u3001return\u306e\u826f\u3055\u304c\u4f1d\u308f\u308a\u306b\u304f\u304f\u3001\u30e1\u30ea\u30c3\u30c8\u304c\u611f\u3058\u3089\u308c\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br>\u3068\u3044\u3046\u306e\u3082\u3001adder1\u306e\u307b\u3046\u304c\u95a2\u6570\u306e\u547c\u3073\u51fa\u3057\u304c\u65e9\u304f\u51fa\u529b\u3082\u95a2\u6570\u5185\u90e8\u3067\u884c\u3046\u305f\u3081\u3067\u3059\u3002<br>\u3067\u3059\u304c\u4e00\u822c\u7684\u306b\u4f7f\u308f\u308c\u308b\u95a2\u6570\u306e\u4f7f\u3044\u65b9\u306e1\u3064\u306b\u3001\u3042\u308b\u8a08\u7b97\u7d50\u679c\u3092return\u3067\u53d7\u3051\u53d6\u308a\u518d\u5ea6\u5225\u306e\u95a2\u6570\u306b\u305d\u306e\u5024\u3092\u6e21\u3059\u3068\u3044\u3063\u305f\u3053\u3068\u3092\u884c\u3044\u307e\u3059\u3002<br>\u4e0a\u8a18\u65b9\u6cd5\u3067\u306freturn\u306e\u826f\u3055\u304c\u4f1d\u308f\u308a\u307e\u305b\u3093\u3002<br>\u3067\u306f\u3001\u30a4\u30e1\u30fc\u30b8\u3068\u3057\u3066return\u306e\u4f7f\u3044\u65b9\u3068\u3057\u3066\u6b63\u3057\u3044\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8aac\u660e\u3057\u307e\u3057\u3087\u3046\u3002<br>\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8aad\u3093\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><code>def a(a,b):\n    return a + b\n\ndef b(a,b):\n    return a * b\n\nx = a(2,2) # x\u306b4\u304c\u4ee3\u5165\ny = b(x, x)  # 4 * 4\n\nprint(y) # 16\u304c\u51fa\u529b\n<\/code><\/pre>\n<p>\u95a2\u6570b\u306e\u3088\u3046\u306b\u524d\u306e\u51e6\u7406\u7d50\u679cx\u3092\u307e\u305f\u95a2\u6570b\u306e\u5f15\u6570\u3067\u6e21\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u306e\u3088\u3046\u306b\u3001return\u3092\u884c\u3046\u3053\u3068\u3067\u8a08\u7b97\u7d50\u679c\u3092\u4e00\u65e6\u5909\u6570\u306b\u683c\u7d0d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3001<br>\u3055\u3089\u306b\u305d\u306e\u5024\u3092\u5225\u306e\u95a2\u6570\u306b\u6e21\u3057\u3066\u9055\u3046\u51e6\u7406\u306b\u7e4b\u3052\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br>\u307e\u305f\u3001\u95a2\u6570\u306b\u6e21\u3059\u3068\u3044\u3046\u306e\u306freturn\u3092\u4f7f\u3046\u4e00\u4f8b\u3067\u3059\u304c\u3001<strong><em>\u95a2\u6570\u306b\u6e21\u3055\u305a\u3068\u3082\u8fd4\u308a\u5024(\u623b\u308a\u5024)\u306b\u5bfe\u3057\u3066\u66f4\u306b\u4f55\u304b\u3057\u3089\u306e\u51e6\u7406\u3092\u884c\u3046\u3053\u3068\u304c\u51fa\u6765\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u30dd\u30a4\u30f3\u30c8\u306b\u306a\u308a\u307e\u3059\u3002<\/em><\/strong>\u95a2\u6570\u5185\u90e8\u3067\u51fa\u529b\uff08print\uff09\u3059\u308b\u3060\u3051\u3067\u3042\u308c\u3070print()\u3067\u51fa\u529b\u3059\u308c\u3070\u826f\u3044\u3067\u3059\u304c\u3001\u5185\u90e8\u306bprint\u95a2\u6570\u304c\u7121\u3044\u95a2\u6570\u306f\u3001\u51e6\u7406\u3057\u305f\u7d50\u679c\u3092return(\u8fd4\u308a\u5024\/\u623b\u308a\u5024)\u3067\u53d7\u3051\u53d6\u308a\u3001<br>\u305d\u306e\u5024\u3092\u5909\u6570\u306b\u4ee3\u5165\u3057\u3001\u307e\u305f\u4ed6\u306e\u95a2\u6570\u306b\u305d\u306e\u8fd4\u308a\u5024\u3092\u6e21\u3059\u3053\u3068\u3067\u518d\u5ea6\u5225\u306e\u51e6\u7406\u306b\u3064\u306a\u3052\u308b\u4e8b\u304c\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br>\u524d\u8ff0\u306e\u901a\u308a\u3001<strong><em>return\u306f\u5024\u3092\u8fd4\u3059\u3053\u3068\u304c\u76ee\u7684<\/em><\/strong>\u3068\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u95a2\u6570\u5185\u90e8\u306e\u51e6\u7406\u3092\u3001\u95a2\u6570\u5185\u90e8\u306e\u51e6\u7406\u4ee5\u964d\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3082\u3001\u8fd4\u308a\u5024\u3068\u3057\u3066\u53d7\u3051\u53d6\u3063\u305f\u5024\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u524d\u63d0\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2 id=\"i-9\">return\u3092\u5229\u7528\u3057\u305f\u95a2\u6570\u306e\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>\u305d\u308c\u3067\u306f\u3001\u95a2\u6570\u5185\u90e8\u306bprint()\u3092\u4f7f\u308f\u305areturn\u3092\u4f7f\u3063\u305f\u95a2\u6570\u3092\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u307f\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>def power(x):\n    return x*x\n\ndef absolute(x):\n    if (x &lt; 0):\n        return -x\n    else:\n        return x\n\nprint(power(10)) # 100\nprint(absolute(-10)) # 10\n<\/code><\/pre>\n<h2 id=\"i-10\">\u5f15\u6570\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024<\/h2>\n<p>\u95a2\u6570\u3067\u306f\u3001\u5f15\u6570\u3092\u6307\u5b9a\u3057\u306a\u304b\u3063\u305f\u5834\u5408\u306b\u5f15\u6570\u3092\u8a2d\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>def func(a, b=5):\n    print(a)\n    print(b)\n\nfunc(10,15) # 10\u306815\u304c\u51fa\u529b\u3055\u308c\u308b\nfunc(3) # 3\u30685\u304c\u51fa\u529b\u3055\u308c\u308b\n<\/code><\/pre>\n<p>\u3053\u3053\u3067\u3001\u4e0a\u8a18\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3001b=5\u3068\u306a\u3063\u3066\u304a\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u304c\u5f15\u6570\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3067\u3059\u3002<br>\u5f15\u6570\u306b\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br>\u3053\u306e\u95a2\u6570\u306f\u6574\u6570\u5024\u306e\u5f15\u6570\u30922\u3064\u4e0e\u3048\u308b\u3053\u3068\u3067\u3001\u305d\u306e2\u3064\u3092\u51fa\u529b\u3059\u308b\u3060\u3051\u306e\u95a2\u6570\u3067\u3059\u304c\u3001<br>\u3082\u3057\u5f15\u6570\u30921\u3064\u3057\u304b\u6e21\u3055\u306a\u304b\u3063\u305f\u5834\u5408\u306f\u30012\u3064\u76ee\u306e\u5024\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u5024b\u304c5\u3068\u306a\u3063\u3066\u3044\u308b\u305f\u3081\u306b\u30015\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u3055\u3066\u3001\u4e0b\u8a18\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u95a2\u3057\u3066\u8003\u3048\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br>\u4e0b\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001[\u2018python\u2019, \u2018Python\u2019]\u304c\u6700\u5f8c\u306e\u95a2\u6570\u547c\u3073\u51fa\u3057\u3067\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><code>def sample(arg, arg_list=[]):\n    arg_list.append(arg)\n    print(arg_list)\n\nsample('python')\nsample('Python')\n<\/code><\/pre>\n<p>Q. \u3053\u306e\u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u969b\u306b\u3001\u6bce\u56de\u5f15\u6570\u306b\u6e21\u3057\u305f\u8981\u7d20\u3060\u3051\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u305f\u3044\u3067\u3059\u3002<br>\u5b9f\u969b\u306b\u4fee\u6b63\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u826f\u3044\u3067\u3057\u3087\u3046\u304b\uff1f\uff1f<\/p>\n<p>A. \u3053\u306e\u5834\u5408\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u4fee\u6b63\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre><code>def sample(arg):\n    arg_list = [] # \u30ea\u30b9\u30c8\u306e\u521d\u671f\u5316\n    arg_list.append(arg)\n    print(arg_list)\n\nsample('python') # ['python']\nsample('Python') # ['Python']\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306f\u3001\u6bce\u56de\u30ea\u30b9\u30c8\u3092\u521d\u671f\u5316\u3057\u3066\u3044\u307e\u3059\u3002<br>\u305d\u306e\u5f8c\u306b\u3001\u5f15\u6570\u3067\u6e21\u3055\u308c\u305farg\u3092\u521d\u671f\u5316\u3057\u305f\u7a7a\u306e\u30ea\u30b9\u30c8\u306bappend\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2 id=\"i-11\">\u95a2\u6570 \u5909\u6570\u306e\u30b9\u30b3\u30fc\u30d7<\/h2>\n<p>\u30b9\u30b3\u30fc\u30d7\u306f\u304b\u306a\u308a\u91cd\u8981\u306a\u90e8\u5206\u306b\u306a\u308a\u307e\u3059\u3002<br>\u4eca\u5f8c\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3092\u3057\u3066\u3044\u304f\u4e0a\u3067\u3001\u5927\u4e8b\u306a\u8003\u3048\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u3057\u3063\u304b\u308a\u62bc\u3055\u3048\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<br><strong>\u30dd\u30a4\u30f3\u30c8\u306f\u3001\u5909\u6570\u306f\u3069\u3053\u3067\u4f5c\u6210\u3057\u305f\u304b\u306b\u3088\u3063\u3066\u30b9\u30b3\u30fc\u30d7\uff08\u6709\u52b9\u7bc4\u56f2\uff09\u304c\u9055\u3063\u3066\u304d\u307e\u3059\u3002<\/strong><\/p>\n<p>\u307e\u305a\u306f\u3001\u901a\u5e38\u306e\u95a2\u6570\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>def add(x1):\n    x2 = 10 # \u95a2\u6570\u5185\u3067\u5909\u6570\u3092\u4f5c\u6210(\u30ed\u30fc\u30ab\u30eb\u5909\u6570)\n    result = x1 + x2\n    print(result)\n\nadd(5) # 5 + 10\u306715\u304c\u51fa\u529b\n<\/code><\/pre>\n<p>\u6b21\u306b\u3001\u5909\u6570\u306e\u30b9\u30b3\u30fc\u30d7(\u6709\u52b9\u7bc4\u56f2)\u306b\u95a2\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<\/p>\n<pre><code>def add(x1):\n    x2 = 10 # \u95a2\u6570\u5185\u3067\u5909\u6570\u3092\u4f5c\u6210(\u30ed\u30fc\u30ab\u30eb\u5909\u6570)\n    result = x1 + x2\n    print(result)\n\nadd(5) # 5 + 10\u306715\u304c\u51fa\u529b\nprint(x2) # \u3053\u3053\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001<strong>NameError: name \u2018x2\u2019 is not defined<\/strong>\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<br><strong>\u3053\u308c\u306f\u95a2\u6570\u5185\u3067\u5b9a\u7fa9\u3057\u305f\u5909\u6570x2\u306f\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3067\u3042\u308a\u3001\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u304b\u95a2\u6570\u5185\u90e8\u3060\u3051\u3057\u304b\u6709\u52b9\u3067\u306f\u306a\u3044\u305f\u3081\u3001\u95a2\u6570\u306e\u5916\u5074\u3067x2\u3092\u547c\u3073\u51fa\u3059\u3068\u30a8\u30e9\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/strong><\/p>\n<p>\u6709\u52b9\u306a\u89e3\u6c7a\u624b\u6bb5\u3068\u3057\u3066\u95a2\u6570\u306e\u5916\u306bx2\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u3067\u3059\u3002<br>(\u203b\u5909\u6570\u306e\u30b9\u30b3\u30fc\u30d7\u4ee5\u5916\u306b\u3082\u3001\u95a2\u6570\u5185\u90e8\u51e6\u7406\u306a\u3069\u3082\u308f\u304b\u308a\u3084\u3059\u3044\u3088\u3046\u3001\u4fee\u6b63\u3057\u3066\u3044\u307e\u3059\u3002)<\/p>\n<pre><code>def add(x1,x2):\n    result = x1 + x2\n    return result\n\nx1 = 5\nx2 = 10\nresult = add(x1, x2) # 5 + 10\u306715\u304c\u51fa\u529b\nprint(result)\n<\/code><\/pre>\n<p>\u4ed6\u306b\u3082\u3001<strong>global\u3092\u5229\u7528\u3057\u3066\u95a2\u6570\u5185\u3067\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570<\/strong>\u3092\u5229\u7528\u3059\u308b\u304b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2 id=\"i-12\">\u30b0\u30ed\u30fc\u30d0\u30eb(global)\u5ba3\u8a00\u30fb\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570<\/h2>\n<p>\u95a2\u6570\u5185\u3067\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306e\u5ba3\u8a00\u3067\u3059\u3002<br>\u30ed\u30fc\u30ab\u30eb\u5909\u6570\uff08\u95a2\u6570\u5b9a\u7fa9\u306e\u5185\u90e8\u3067\u5b9a\u7fa9\u3057\u305f\u95a2\u6570\uff09\u3068\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\uff08\u95a2\u6570\u5b9a\u7fa9\u306e\u5916\u5074\u3067\u5b9a\u7fa9\u3057\u305f\u5909\u6570\uff09\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre><code>glb = 0\n\ndef func1():\n    glb = 1\n\ndef func2():\n    global glb\n    glb = 5\n\nprint(glb) # 0\u304c\u51fa\u529b\u3055\u308c\u308b\nfunc1()\nprint(glb) # 0\u304c\u51fa\u529b\u3055\u308c\u308b\nfunc2()\nprint(glb) # 5\u304c\u51fa\u529b\u3055\u308c\u308b\n<\/code><\/pre>\n<p>\u3082\u3046\u4e00\u3064\u4f8b\u984c\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>var1 = '\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570'\n\ndef sample():\n    var2 = '\u30ed\u30fc\u30ab\u30eb\u5909\u6570'\n    return (var1, var2)\n\nprint(sample())\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u4f8b\u306f\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3068\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3092\u305d\u308c\u305e\u308c\u5ba3\u8a00\u3057\u3066\u3044\u307e\u3059\u3002<br>\u6b21\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u3001\u95a2\u6570\u5185\u304b\u3089\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3092\u5909\u66f4\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<\/p>\n<pre><code>var1 = '\u30b0\u30ed\u30fc\u30d0\u30eb'\n\ndef sample():\n    global var1\n\n    var1 = '\u30ed\u30fc\u30ab\u30eb\u306b\u5909\u66f4\u3055\u308c\u307e\u3057\u305f'\n\nsample()    # \u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570var1\u3092\u95a2\u6570\u5185\u90e8\u3067\u5909\u66f4\nprint(var1) # \u30ed\u30fc\u30ab\u30eb\u306b\u5909\u66f4\u3055\u308c\u307e\u3057\u305f\n<\/code><\/pre>\n<h2 id=\"i-13\">\u307e\u3068\u3081<\/h2>\n<p>\u95a2\u6570\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u4f3c\u305f\u3088\u3046\u306a\u51e6\u7406\u3092\u4f55\u56de\u3082\u66f8\u304b\u305a\u306b\u6e08\u307f\u307e\u3059\u3002<br>\u3055\u3089\u306b\u3001\u3042\u308b\u307e\u3068\u307e\u3063\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u95a2\u6570\u3068\u3057\u3066\u30011\u3064\u306e\u51e6\u7406\u3068\u3057\u3066\u307e\u3068\u3081\u3066\u304a\u304f\u3053\u3068\u3067\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u91cd\u8907\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u306e\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u53ef\u8aad\u6027\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002<br>\u95a2\u6570\u306b\u3059\u308b\u3053\u3068\u3067\u3001\u540c\u3058\u51e6\u7406\u3092\u7e70\u308a\u8fd4\u3057\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u306a\u304f\u3001\u5bb9\u6613\u306b\u518d\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br>\u307b\u3068\u3093\u3069\u306e\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u3067\u306f\u3001\u95a2\u6570\u306f\u5f53\u305f\u308a\u524d\u306e\u3088\u3046\u306b\u4f7f\u3046\u3082\u306e\u306a\u306e\u3067\u3001\u4f7f\u3044\u3053\u306a\u305b\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"aiacademy.jp\/bootcamp\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"341\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png\" alt=\"\" class=\"wp-image-691\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-1024x341.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-300x100.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-768x256.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi-940x313.png 940w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2021\/12\/bootcamp_ad_72ppi.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21 \u95a2\u6570\u3068\u306f \u95a2\u6570\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8\u30fb\u30c7\u30e1\u30ea\u30c3\u30c8 \u95a2\u6570\u306e\u5b9a\u7fa9 \u95a2\u6570\u540d pass \u5f15\u6570 \u8fd4\u308a\u5024(\u623b\u308a\u5024) \u5f15\u6570\u3068return \u306a\u305creturn\u3092\u4f7f\u3046\u306e\u304b return\u3092\u5229\u7528\u3057\u305f\u95a2\u6570\u306e\u30b5\u30f3\u30d7\u30eb \u5f15\u6570\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5024 \u95a2\u6570 \u5909\u6570\u306e &#8230; <\/p>\n","protected":false},"author":1,"featured_media":487,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85,90],"tags":[],"class_list":{"0":"post-127","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python","8":"category-90"},"_links":{"self":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127"}],"version-history":[{"count":5,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":4883,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions\/4883"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/media\/487"}],"wp:attachment":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}