{"id":235,"date":"2020-03-15T17:28:36","date_gmt":"2020-03-15T08:28:36","guid":{"rendered":"http:\/\/batmask.dothome.co.kr\/?p=235"},"modified":"2026-05-14T14:31:17","modified_gmt":"2026-05-14T05:31:17","slug":"kotlin-vs-python-as-keyword","status":"publish","type":"post","link":"https:\/\/batmask.net\/index.php\/2020\/03\/15\/235\/","title":{"rendered":"Kotlin vs Python : &#8216;as&#8217; keyword"},"content":{"rendered":"\n<p> Kotlin\uacfc Python\uc774 \uac19\uc774 \uac16\uace0 \uc788\ub294 \ud0a4\uc6cc\ub4dc\uc911, &#8216;as&#8217;\uac00 \uc788\ub294\ub370 \uc774\uac83 \ub610\ud55c \ub2e4\ub974\uac8c \uc4f0\uc778\ub2e4.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Kotlin<\/h4>\n\n\n\n<p>Kotlin\uc5d0\uc11c &#8216;as&#8217;\ub294 \uba85\uc2dc\uc801 \uce90\uc2a4\ud305(\ud615\ubcc0\ud658) \uc5f0\uc0b0\uc790\uc774\ub2e4. <a href=\"https:\/\/kotlinlang.org\/docs\/reference\/typecasts.html\">\uacf5\uc2dd \ubb38\uc11c \ucc38\uc870<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 0 16px;font-size:0.8em;width:100%;text-align:left;background-color:#22272e;font-style:italic;color:#adbac7\"><span style=\"border-bottom:1px solid rgba(139, 186, 234, 0.2)\">Kotlin<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>val x: String = y as String<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">val<\/span><span style=\"color: #ADBAC7\"> x: <\/span><span style=\"color: #F69D50\">String<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> y <\/span><span style=\"color: #F47067\">as<\/span><span style=\"color: #ADBAC7\"> String<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\ubb38\uc11c\uc5d0 \ub530\ub974\uba74, \uc774\uacbd\uc6b0 \ud615\ubcc0\ud658\uc5d0 \uc2e4\ud328\ud588\uc744 \ub54c, exception\uc774 \ubc1c\uc0dd\ud55c\ub2e4. \uadf8\ub798\uc11c Unsafe cast operator\ub77c\uace0 \ud55c\ub2e4. \ubc18\uba74\uc5d0, &#8216;as?&#8217;\ub97c \uc0ac\uc6a9\ud558\uba74 \ud615\ubcc0\ud658 \uc2e4\ud328\uc2dc null\uc744 \ubc18\ud658\ud55c\ub2e4. \uadf8\ub798\uc11c Safe cast operator\ub77c\uace0 \ubd80\ub978\ub2e4.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 0 16px;font-size:0.8em;width:100%;text-align:left;background-color:#22272e;font-style:italic;color:#adbac7\"><span style=\"border-bottom:1px solid rgba(139, 186, 234, 0.2)\">Kotlin<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>val x: String? = y as? String<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">val<\/span><span style=\"color: #ADBAC7\"> x: <\/span><span style=\"color: #F69D50\">String<\/span><span style=\"color: #ADBAC7\">? <\/span><span style=\"color: #F47067\">=<\/span><span style=\"color: #ADBAC7\"> y <\/span><span style=\"color: #F47067\">as<\/span><span style=\"color: #ADBAC7\">? String<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Python<\/h4>\n\n\n\n<p>Python\uc5d0\uc11c as \ub294 alias\ub97c \uc758\ubbf8\ud55c\ub2e4. module import\uc640 \ub9ac\uc18c\uc2a4 \uad00\ub9ac\ub97c \uc704\ud55c with \ubb38\uc5d0\uc11c \uc0ac\uc6a9\ub41c\ub2e4.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 0 16px;font-size:0.8em;width:100%;text-align:left;background-color:#22272e;font-style:italic;color:#adbac7\"><span style=\"border-bottom:1px solid rgba(139, 186, 234, 0.2)\">Python<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>import fibo as fib # fibo \ubaa8\ub4c8\uc744 fib \uc774\ub984\uc73c\ub85c \uc0ac\uc6a9\ud55c\ub2e4.\nfib.fib(500)<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">import<\/span><span style=\"color: #ADBAC7\"> fibo <\/span><span style=\"color: #F47067\">as<\/span><span style=\"color: #ADBAC7\"> fib <\/span><span style=\"color: #768390\"># fibo \ubaa8\ub4c8\uc744 fib \uc774\ub984\uc73c\ub85c \uc0ac\uc6a9\ud55c\ub2e4.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">fib.fib(<\/span><span style=\"color: #6CB6FF\">500<\/span><span style=\"color: #ADBAC7\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-Roboto-Mono.ttf\" style=\"font-size:clamp(14px, .875rem, 21px);font-family:Code-Pro-Roboto-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#adbac7;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 0 16px;font-size:0.8em;width:100%;text-align:left;background-color:#22272e;font-style:italic;color:#adbac7\"><span style=\"border-bottom:1px solid rgba(139, 186, 234, 0.2)\">Python<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>with open(\"test.txt\", \"r\") as f: # \ud30c\uc77c\uc744 \uc5f4\uace0 \ud30c\uc77c \ud578\ub4e4\ub7ec\ub85c \"f\"\ub97c \uc0ac\uc6a9\ud55c\ub2e4.\n    ...<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F47067\">with<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">open<\/span><span style=\"color: #ADBAC7\">(<\/span><span style=\"color: #96D0FF\">&quot;test.txt&quot;<\/span><span style=\"color: #ADBAC7\">, <\/span><span style=\"color: #96D0FF\">&quot;r&quot;<\/span><span style=\"color: #ADBAC7\">) <\/span><span style=\"color: #F47067\">as<\/span><span style=\"color: #ADBAC7\"> f: <\/span><span style=\"color: #768390\"># \ud30c\uc77c\uc744 \uc5f4\uace0 \ud30c\uc77c \ud578\ub4e4\ub7ec\ub85c &quot;f&quot;\ub97c \uc0ac\uc6a9\ud55c\ub2e4.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">    <\/span><span style=\"color: #6CB6FF\">...<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kotlin\uacfc Python\uc774 \uac19\uc774 \uac16\uace0 \uc788\ub294 \ud0a4\uc6cc\ub4dc\uc911, &#8216;as&#8217;\uac00 \uc788\ub294\ub370 \uc774\uac83 \ub610\ud55c \ub2e4\ub974\uac8c \uc4f0\uc778\ub2e4. Kotlin Kotlin\uc5d0\uc11c &#8216;as&#8217;\ub294 \uba85\uc2dc\uc801 \uce90\uc2a4\ud305(\ud615\ubcc0\ud658) \uc5f0\uc0b0\uc790\uc774\ub2e4. \uacf5\uc2dd \ubb38\uc11c \ucc38\uc870. \ubb38\uc11c\uc5d0 \ub530\ub974\uba74, \uc774\uacbd\uc6b0 \ud615\ubcc0\ud658\uc5d0 \uc2e4\ud328\ud588\uc744 \ub54c, exception\uc774 \ubc1c\uc0dd\ud55c\ub2e4. \uadf8\ub798\uc11c Unsafe cast operator\ub77c\uace0 \ud55c\ub2e4. \ubc18\uba74\uc5d0, &#8216;as?&#8217;\ub97c \uc0ac\uc6a9\ud558\uba74 \ud615\ubcc0\ud658 \uc2e4\ud328\uc2dc null\uc744 \ubc18\ud658\ud55c\ub2e4. \uadf8\ub798\uc11c Safe cast operator\ub77c\uace0 \ubd80\ub978\ub2e4. Python Python\uc5d0\uc11c as \ub294 <a href=\"https:\/\/batmask.net\/index.php\/2020\/03\/15\/235\/\" class=\"btn btn-link continue-link\">\ub354 \uc77d\uae30<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,33],"tags":[72,85,40,38,35,84,139,41,55],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-kotlin","category-python","tag-as","tag-diffrence","tag-keyword","tag-kotlin","tag-python","tag-vs","tag-difference-kr","tag-kotlin-kr","tag-python-kr"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/comments?post=235"}],"version-history":[{"count":3,"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":5516,"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/posts\/235\/revisions\/5516"}],"wp:attachment":[{"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/batmask.net\/index.php\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}