<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Zero to Expert: [KR] Python: Zero to Expert]]></title><description><![CDATA[Complete Python learning course for Python beginners]]></description><link>https://www.zerotoexpert.blog/s/python-beginners</link><image><url>https://substackcdn.com/image/fetch/$s_!2hjI!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcbf83b9-24f2-4bda-ace7-ea2ba9f53b1d_1024x1024.png</url><title>Zero to Expert: [KR] Python: Zero to Expert</title><link>https://www.zerotoexpert.blog/s/python-beginners</link></image><generator>Substack</generator><lastBuildDate>Wed, 08 Apr 2026 09:22:25 GMT</lastBuildDate><atom:link href="https://www.zerotoexpert.blog/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Gwonsoo Lee]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[zerotoexpert@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[zerotoexpert@substack.com]]></itunes:email><itunes:name><![CDATA[Gwonsoo Lee]]></itunes:name></itunes:owner><itunes:author><![CDATA[Gwonsoo Lee]]></itunes:author><googleplay:owner><![CDATA[zerotoexpert@substack.com]]></googleplay:owner><googleplay:email><![CDATA[zerotoexpert@substack.com]]></googleplay:email><googleplay:author><![CDATA[Gwonsoo Lee]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[47. Context Manager]]></title><description><![CDATA[Context Manager&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/47-context-manager</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/47-context-manager</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sat, 29 Jun 2024 07:48:02 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!BIpg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BIpg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BIpg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!BIpg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!BIpg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!BIpg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BIpg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165070,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BIpg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!BIpg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!BIpg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!BIpg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F462e5ac3-5dff-42d5-a60e-1581ead64bb2_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#52968;&#53581;&#49828;&#53944; &#47588;&#45768;&#51200;&#45716; &#53076;&#46300; &#48660;&#47197;&#51012; &#51652;&#51077;&#54616;&#44256; &#45208;&#50732; &#46412; &#51088;&#46041;&#51004;&#47196; &#49444;&#51221; &#48143; &#51221;&#47532; &#51089;&#50629;&#51012; &#49688;&#54665;&#54616;&#45716; &#45936; &#49324;&#50857;&#46108;&#45796;. &#51068;&#48152;&#51201;&#51004;&#47196; <code>with</code> &#47928;&#44284; &#54632;&#44760; &#49324;&#50857;&#46104;&#47728;, &#51088;&#50896; &#44288;&#47532;(&#54028;&#51068;, &#45348;&#53944;&#50892;&#53356; &#50672;&#44208;, &#46973; &#46321;)&#50640; &#50976;&#50857;&#54616;&#45796;. &#54028;&#51060;&#50028;&#50640;&#49436;&#45716; &#46160; &#44032;&#51648; &#48169;&#48277;&#51004;&#47196; &#52968;&#53581;&#49828;&#53944; &#47588;&#45768;&#51200;&#47484; &#44396;&#54788;&#54624; &#49688; &#51080;&#45796;: <code>__enter__</code> &#48143; <code>__exit__</code> &#47700;&#49436;&#46300;&#47484; &#49324;&#50857;&#54616;&#44144;&#45208;, <code>contextlib</code> &#47784;&#46280;&#51032; &#45936;&#53076;&#47112;&#51060;&#53552;&#47484; &#49324;&#50857;&#54616;&#45716; &#48169;&#48277;&#51060; &#51080;&#45796;.</p><p></p><h3>&#44592;&#48376; &#49324;&#50857;&#48277;</h3><p>&#52968;&#53581;&#49828;&#53944; &#47588;&#45768;&#51200;&#45716; <code>with</code> &#47928;&#51012; &#49324;&#50857;&#54616;&#50668; &#44396;&#54788;&#46108;&#45796;. &#45796;&#51020;&#51008; &#54028;&#51068;&#51012; &#50676;&#44256; &#51088;&#46041;&#51004;&#47196; &#45803;&#45716; &#50696;&#51228;&#51060;&#45796;.</p><pre><code>with open('example.txt', 'w') as file:
    file.write('Hello, World!')</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>with</code> &#47928;&#51060; &#45149;&#45208;&#47732; &#54028;&#51068;&#51060; &#51088;&#46041;&#51004;&#47196; &#45803;&#55180;&#45796;.</p><p></p><h3>__enter__ &#48143; __exit__ &#47700;&#49436;&#46300;&#47484; &#49324;&#50857;&#54620; &#44396;&#54788;</h3><p>&#52968;&#53581;&#49828;&#53944; &#47588;&#45768;&#51200;&#47484; &#51649;&#51217; &#44396;&#54788;&#54616;&#47140;&#47732;, &#53364;&#47000;&#49828;&#50640; <code>__enter__</code>&#50752; <code>__exit__</code> &#47700;&#49436;&#46300;&#47484; &#51221;&#51032;&#54644;&#50556; &#54620;&#45796;.</p><pre><code>class MyContextManager:
    def __enter__(self):
        print("Entering the context")
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("Exiting the context")

# &#49324;&#50857; &#50696;&#49884;
with MyContextManager():
    print("Inside the context")</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>with</code> &#48660;&#47197;&#50640; &#51652;&#51077;&#54616;&#47732; <code>__enter__</code> &#47700;&#49436;&#46300;&#44032; &#54840;&#52636;&#46104;&#44256;, &#48660;&#47197;&#51012; &#48736;&#51256;&#45208;&#50724;&#47732; <code>__exit__</code> &#47700;&#49436;&#46300;&#44032; &#54840;&#52636;&#46108;&#45796;.</p><p></p><h4>__enter__</h4><p><code>__enter__</code> &#47700;&#49436;&#46300;&#45716; <code>with</code> &#48660;&#47197;&#50640; &#51652;&#51077;&#54624; &#46412; &#54840;&#52636;&#46108;&#45796;. &#51060; &#47700;&#49436;&#46300;&#45716; &#49440;&#53469;&#51201;&#51004;&#47196; &#44050;&#51012; &#48152;&#54872;&#54624; &#49688; &#51080;&#51004;&#47728;, <code>with</code> &#47928; &#45236;&#50640;&#49436; &#49324;&#50857;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>class Resource:
    def __enter__(self):
        print("Acquiring resource")
        return self

    def do_something(self):
        print("Using resource")

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("Releasing resource")

# &#49324;&#50857; &#50696;&#49884;
with Resource() as resource:
    resource.do_something()</code></pre><h4>__exit__</h4><p><code>__exit__</code> &#47700;&#49436;&#46300;&#45716; <code>with</code> &#48660;&#47197;&#51012; &#48279;&#50612;&#45216; &#46412; &#54840;&#52636;&#46108;&#45796;. &#51060; &#47700;&#49436;&#46300;&#45716; &#45348; &#44060;&#51032; &#51064;&#51088;&#47484; &#48155;&#51004;&#47728;, &#44033;&#44033; &#50696;&#50808;&#51032; &#53440;&#51077;, &#44050;, &#53944;&#47112;&#51060;&#49828;&#48177;&#51012; &#45208;&#53440;&#45240;&#45796;. &#50696;&#50808;&#44032; &#48156;&#49373;&#54616;&#51648; &#50506;&#51004;&#47732; <code>None</code>&#51060; &#51204;&#45804;&#46108;&#45796;.</p><pre><code>class Resource:
    def __enter__(self):
        print("Acquiring resource")
        return self

    def do_something(self):
        print("Using resource")

    def __exit__(self, exc_type, exc_val, exc_tb):
        if exc_type:
            print(f"Exception: {exc_val}")
        print("Releasing resource")

# &#49324;&#50857; &#50696;&#49884;
with Resource() as resource:
    resource.do_something()
    # &#51068;&#48512;&#47084; &#50696;&#50808; &#48156;&#49373;
    raise ValueError("Something went wrong")</code></pre><p></p><h3>&#51025;&#50857; &#50696;&#51228;</h3><p>&#45796;&#51020;&#51008; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50672;&#44208;&#51012; &#44288;&#47532;&#54616;&#45716; &#52968;&#53581;&#49828;&#53944; &#47588;&#45768;&#51200;&#51032; &#50696;&#51228;&#51060;&#45796;.</p><pre><code>class DatabaseConnection:
    def __enter__(self):
        print("Connecting to the database")
        self.connection = self.connect()
        return self.connection

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.connection.close()
        print("Closing the database connection")

    def connect(self):
        # &#44032;&#49345;&#51032; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50672;&#44208;
        class Connection:
            def close(self):
                print("Connection closed")

        return Connection()

# &#49324;&#50857; &#50696;&#49884;
with DatabaseConnection() as conn:
    print("Using the database connection")</code></pre><p></p><h3>contextlib &#47784;&#46280;&#51012; &#49324;&#50857;&#54620; &#44396;&#54788;</h3><p><code>contextlib</code> &#47784;&#46280;&#51012; &#49324;&#50857;&#54616;&#47732; &#45908; &#44036;&#54200;&#54616;&#44172; &#52968;&#53581;&#49828;&#53944; &#47588;&#45768;&#51200;&#47484; &#44396;&#54788;&#54624; &#49688; &#51080;&#45796;. <code>contextlib.contextmanager</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#47484; &#49324;&#50857;&#54616;&#47732; &#54632;&#49688; &#44592;&#48152;&#51032; &#52968;&#53581;&#49828;&#53944; &#47588;&#45768;&#51200;&#47484; &#47564;&#46308; &#49688; &#51080;&#45796;.</p><pre><code>from contextlib import contextmanager

@contextmanager
def my_context_manager():
    print("Entering the context")
    yield
    print("Exiting the context")

# &#49324;&#50857; &#50696;&#49884;
with my_context_manager():
    print("Inside the context")</code></pre><p></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[46. 파이썬 프로토콜 (Protocol)]]></title><description><![CDATA[&#54028;&#51060;&#50028; &#54532;&#47196;&#53664;&#53084;&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/46-protocol</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/46-protocol</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sat, 29 Jun 2024 06:43:50 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!93L9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!93L9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!93L9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!93L9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!93L9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!93L9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!93L9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:163263,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!93L9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!93L9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!93L9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!93L9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78361d26-ba2b-40ab-b090-b1c5da09b6f8_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#50640;&#49436; &#54532;&#47196;&#53664;&#53084;&#51008; &#51221;&#49885;&#51004;&#47196; &#53364;&#47000;&#49828;&#51032; &#47700;&#49436;&#46300;&#45208; &#49549;&#49457;&#51012; &#51221;&#51032;&#54616;&#51648; &#50506;&#44256;&#46020; &#53945;&#51221; &#46041;&#51089;&#51012; &#46384;&#47476;&#45716; &#44061;&#52404;&#47484; &#47564;&#46308;&#44592; &#50948;&#54620; &#44060;&#45392;&#51060;&#45796;. &#54532;&#47196;&#53664;&#53084;&#51012; &#49324;&#50857;&#54616;&#47732; &#53440;&#51077; &#55180;&#54021;&#44284; &#51221;&#51201; &#53440;&#51077; &#44160;&#49324;&#47484; &#45908; &#54952;&#44284;&#51201;&#51004;&#47196; &#54624; &#49688; &#51080;&#45796;. &#51060;&#45716; &#51452;&#47196; <code>typing</code> &#47784;&#46280;&#51032; <code>Protocol</code> &#53364;&#47000;&#49828;&#47484; &#49324;&#50857;&#54616;&#50668; &#51221;&#51032;&#46108;&#45796;.</p><p></p><h3>&#44592;&#48376; &#49324;&#50857;&#48277;</h3><p>&#45796;&#51020;&#51008; <code>Protocol</code>&#51012; &#49324;&#50857;&#54616;&#50668; &#54532;&#47196;&#53664;&#53084;&#51012; &#51221;&#51032;&#54616;&#44256; &#51060;&#47484; &#44396;&#54788;&#54616;&#45716; &#50696;&#51228;&#51060;&#45796;.</p><pre><code>from typing import Protocol

class Flyer(Protocol):
    def fly(self) -&gt; None:
        ...

class Bird:
    def fly(self) -&gt; None:
        print("Bird is flying")

class Airplane:
    def fly(self) -&gt; None:
        print("Airplane is flying")

# &#49324;&#50857; &#50696;&#49884;
def let_it_fly(flyer: Flyer) -&gt; None:
    flyer.fly()

bird = Bird()
airplane = Airplane()

let_it_fly(bird)      # Bird is flying
let_it_fly(airplane)  # Airplane is flying</code></pre><p></p><h3>&#51088;&#49464;&#54620; &#49444;&#47749;</h3><h4>Protocol &#53364;&#47000;&#49828;</h4><p><code>Protocol</code> &#53364;&#47000;&#49828;&#45716; &#53440;&#51077; &#55180;&#54021;&#44284; &#51221;&#51201; &#53440;&#51077; &#44160;&#49324;&#47484; &#50948;&#54644; &#49324;&#50857;&#46108;&#45796;. <code>Protocol</code>&#51012; &#49345;&#49549;&#48155;&#50500; &#51221;&#51032;&#46108; &#53364;&#47000;&#49828;&#45716; &#51064;&#53552;&#54168;&#51060;&#49828;&#52376;&#47100; &#46041;&#51089;&#54616;&#47728;, &#51060;&#47484; &#44396;&#54788;&#54616;&#45716; &#53364;&#47000;&#49828;&#45716; &#54532;&#47196;&#53664;&#53084;&#50640; &#51221;&#51032;&#46108; &#47700;&#49436;&#46300;&#50752; &#49549;&#49457;&#51012; &#51228;&#44277;&#54644;&#50556; &#54620;&#45796;.</p><pre><code>from typing import Protocol

class ExampleProtocol(Protocol):
    def method(self) -&gt; None:
        ...</code></pre><p>&#51060; &#54532;&#47196;&#53664;&#53084;&#51012; &#44396;&#54788;&#54616;&#45716; &#53364;&#47000;&#49828;&#45716; <code>method</code> &#47700;&#49436;&#46300;&#47484; &#51228;&#44277;&#54644;&#50556; &#54620;&#45796;.</p><h4>&#51221;&#51201; &#53440;&#51077; &#44160;&#49324;</h4><p><code>Protocol</code>&#51012; &#49324;&#50857;&#54616;&#47732; &#53440;&#51077; &#55180;&#54021;&#44284; &#54632;&#44760; &#51221;&#51201; &#53440;&#51077; &#44160;&#49324;&#47484; &#53685;&#54644; &#53076;&#46300;&#51032; &#51068;&#44288;&#49457;&#51012; &#50976;&#51648;&#54624; &#49688; &#51080;&#45796;. &#51060;&#45716; <code>mypy</code>&#50752; &#44057;&#51008; &#53440;&#51077; &#44160;&#49324;&#44592;&#47484; &#53685;&#54644; &#51060;&#47336;&#50612;&#51652;&#45796;.</p><p></p><h3>&#54532;&#47196;&#53664;&#53084;&#44284; &#49345;&#49549;</h3><p>&#54532;&#47196;&#53664;&#53084;&#51008; &#47749;&#49884;&#51201;&#51064; &#49345;&#49549; &#50630;&#51060;&#46020; &#53945;&#51221; &#47700;&#49436;&#46300;&#45208; &#49549;&#49457;&#51012; &#51228;&#44277;&#54616;&#45716; &#47784;&#46304; &#53364;&#47000;&#49828;&#50640; &#51201;&#50857;&#46112; &#49688; &#51080;&#45796;. &#51593;, &#45909; &#53440;&#51060;&#54609;(duck typing)&#51012; &#51060;&#50857;&#54620; &#54805;&#53468;&#47196; &#46041;&#51089;&#54620;&#45796;.</p><pre><code>class Swimmer(Protocol):
    def swim(self) -&gt; None:
        ...

class Fish:
    def swim(self) -&gt; None:
        print("Fish is swimming")

class Human:
    def swim(self) -&gt; None:
        print("Human is swimming")

# &#49324;&#50857; &#50696;&#49884;
def let_it_swim(swimmer: Swimmer) -&gt; None:
    swimmer.swim()

fish = Fish()
human = Human()

let_it_swim(fish)  # Fish is swimming
let_it_swim(human)  # Human is swimming</code></pre><p><code>&#45909; &#53440;&#51060;&#54609;&#51008; &#54028;&#51060;&#50028;&#44284; &#44057;&#51008; &#46041;&#51201; &#53440;&#51060;&#54609; &#50616;&#50612;&#50640;&#49436; &#49324;&#50857;&#46104;&#45716; &#44060;&#45392;&#51004;&#47196;, &#44061;&#52404;&#51032; &#49892;&#51228; &#53440;&#51077;&#48372;&#45796; &#44061;&#52404;&#51032; &#54788;&#51116; &#47700;&#49436;&#46300;&#45208; &#49549;&#49457;&#50640; &#46384;&#46972; &#54665;&#46041;&#51012; &#44208;&#51221;&#54616;&#45716; &#48169;&#49885;&#51060;&#45796;. &#51060;&#45716; "&#50724;&#47532;&#52376;&#47100; &#44151;&#44256; &#50724;&#47532;&#52376;&#47100; &#49548;&#47532;&#45236;&#47732; &#44536;&#44163;&#51008; &#50724;&#47532;&#51068; &#44163;&#51060;&#45796;"&#46972;&#45716; &#52384;&#54617;&#50640; &#44592;&#52488;&#54620;&#45796;. &#51593;, &#44061;&#52404;&#44032; &#53945;&#51221; &#51064;&#53552;&#54168;&#51060;&#49828;&#47484; &#44396;&#54788;&#54664;&#45716;&#51648; &#50668;&#48512;&#47484; &#54869;&#51064;&#54616;&#51648; &#50506;&#44256;, &#54596;&#50836;&#54620; &#47700;&#49436;&#46300;&#45208; &#49549;&#49457;&#51012; &#44032;&#51648;&#44256; &#51080;&#51004;&#47732; &#49324;&#50857;&#54620;&#45796;.</code></p><p></p><h3>&#51025;&#50857; &#50696;&#51228;</h3><p>&#51328; &#45908; &#48373;&#51105;&#54620; &#50696;&#51228;&#47196;, &#54532;&#47196;&#53664;&#53084;&#51012; &#49324;&#50857;&#54616;&#50668; &#45796;&#50577;&#54620; &#54805;&#53468;&#51032; &#45936;&#51060;&#53552;&#47484; &#51069;&#44256; &#50416;&#45716; &#51064;&#53552;&#54168;&#51060;&#49828;&#47484; &#51221;&#51032;&#54644;&#48372;&#51088;.</p><pre><code>from typing import Protocol

class DataReader(Protocol):
    def read(self) -&gt; str:
        ...

class DataWriter(Protocol):
    def write(self, data: str) -&gt; None:
        ...

class FileReader:
    def __init__(self, filename: str):
        self.filename = filename

    def read(self) -&gt; str:
        with open(self.filename, 'r') as file:
            return file.read()

class FileWriter:
    def __init__(self, filename: str):
        self.filename = filename

    def write(self, data: str) -&gt; None:
        with open(self.filename, 'w') as file:
            file.write(data)

# &#49324;&#50857; &#50696;&#49884;
def process_data(reader: DataReader, writer: DataWriter) -&gt; None:
    data = reader.read()
    # &#45936;&#51060;&#53552; &#52376;&#47532; &#47196;&#51649; (&#50696;: &#47784;&#46304; &#53581;&#49828;&#53944;&#47484; &#45824;&#47928;&#51088;&#47196; &#48320;&#54872;)
    processed_data = data.upper()
    writer.write(processed_data)

file_reader = FileReader('input.txt')
file_writer = FileWriter('output.txt')

process_data(file_reader, file_writer)</code></pre><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[45. Abstract Classes]]></title><description><![CDATA[&#52628;&#49345; &#53364;&#47000;&#49828;&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/45-abstract-classes</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/45-abstract-classes</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sat, 29 Jun 2024 06:36:56 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!r50L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r50L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r50L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!r50L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!r50L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!r50L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r50L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:162382,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!r50L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!r50L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!r50L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!r50L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85e721e6-fe8b-4eaa-a1a6-a613ad73edbd_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#50640;&#49436; &#52628;&#49345; &#53364;&#47000;&#49828;&#45716; &#51452;&#47196; <code>abc</code> &#47784;&#46280;&#51012; &#49324;&#50857;&#54616;&#50668; &#51221;&#51032;&#54620;&#45796;. &#52628;&#49345; &#53364;&#47000;&#49828;&#45716; &#54616;&#45208; &#51060;&#49345;&#51032; &#52628;&#49345; &#47700;&#49436;&#46300;&#47484; &#54252;&#54632;&#54616;&#45716; &#53364;&#47000;&#49828;&#47196;, &#51649;&#51217; &#51064;&#49828;&#53556;&#49828;&#54868;&#54624; &#49688; &#50630;&#45796;. &#45824;&#49888;, &#49436;&#48652;&#53364;&#47000;&#49828;&#50640;&#49436; &#52628;&#49345; &#47700;&#49436;&#46300;&#47484; &#48152;&#46300;&#49884; &#44396;&#54788;&#54644;&#50556; &#54620;&#45796;. &#51060;&#45716; &#44277;&#53685; &#51064;&#53552;&#54168;&#51060;&#49828;&#47484; &#44053;&#51228;&#54616;&#44256;, &#53076;&#46300;&#51032; &#44396;&#51312;&#50752; &#51068;&#44288;&#49457;&#51012; &#50976;&#51648;&#54616;&#45716; &#45936; &#50976;&#50857;&#54616;&#45796;.</p><h3>&#44592;&#48376; &#49324;&#50857;&#48277;</h3><p>&#52628;&#49345; &#53364;&#47000;&#49828;&#47484; &#51221;&#51032;&#54616;&#44592; &#50948;&#54644;&#49436;&#45716; <code>abc.ABC</code>&#47484; &#49345;&#49549;&#54616;&#44256;, <code>abc.abstractmethod</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#47484; &#49324;&#50857;&#54616;&#50668; &#52628;&#49345; &#47700;&#49436;&#46300;&#47484; &#51221;&#51032;&#54620;&#45796;.</p><pre><code>from abc import ABC, abstractmethod

class Animal(ABC):
    @abstractmethod
    def sound(self):
        pass

    @abstractmethod
    def move(self):
        pass

# &#49324;&#50857; &#50696;&#49884;
class Dog(Animal):
    def sound(self):
        return "Bark"

    def move(self):
        return "Runs"

class Bird(Animal):
    def sound(self):
        return "Chirp"

    def move(self):
        return "Flies"

# &#51064;&#49828;&#53556;&#49828; &#49373;&#49457;
dog = Dog()
bird = Bird()

print(dog.sound())  # Bark
print(dog.move())   # Runs
print(bird.sound()) # Chirp
print(bird.move())  # Flies

# &#52628;&#49345; &#53364;&#47000;&#49828;&#45716; &#51649;&#51217; &#51064;&#49828;&#53556;&#49828;&#54868;&#54624; &#49688; &#50630;&#45796;.
try:
    animal = Animal()
except TypeError as e:
    print(e)  # "Can't instantiate abstract class Animal with abstract methods move, sound"</code></pre><p></p><h3>&#51088;&#49464;&#54620; &#49444;&#47749;</h3><h4>ABC &#53364;&#47000;&#49828;</h4><p><code>abc.ABC</code>&#45716; &#54028;&#51060;&#50028;&#50640;&#49436; &#52628;&#49345; &#53364;&#47000;&#49828;&#47484; &#51221;&#51032;&#54624; &#46412; &#49324;&#50857;&#54616;&#45716; &#44592;&#48376; &#53364;&#47000;&#49828;&#51060;&#45796;. &#51060;&#47484; &#49345;&#49549;&#48155;&#45716; &#53364;&#47000;&#49828;&#45716; &#52628;&#49345; &#53364;&#47000;&#49828;&#44032; &#46108;&#45796;.</p><pre><code>from abc import ABC

class MyAbstractClass(ABC):
    pass</code></pre><p></p><h4>abstractmethod &#45936;&#53076;&#47112;&#51060;&#53552;</h4><p><code>abc.abstractmethod</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#45716; &#47700;&#49436;&#46300;&#47484; &#52628;&#49345; &#47700;&#49436;&#46300;&#47196; &#51221;&#51032;&#54616;&#45716; &#45936; &#49324;&#50857;&#46108;&#45796;. &#52628;&#49345; &#47700;&#49436;&#46300;&#45716; &#49436;&#48652;&#53364;&#47000;&#49828;&#50640;&#49436; &#48152;&#46300;&#49884; &#44396;&#54788;&#54644;&#50556; &#54616;&#47728;, &#44396;&#54788;&#54616;&#51648; &#50506;&#51012; &#44221;&#50864; &#49436;&#48652;&#53364;&#47000;&#49828;&#46020; &#52628;&#49345; &#53364;&#47000;&#49828;&#44032; &#46108;&#45796;.</p><pre><code>from abc import ABC, abstractmethod

class MyAbstractClass(ABC):
    @abstractmethod
    def my_method(self):
        pass</code></pre><p></p><h3>&#52628;&#49345; &#53364;&#47000;&#49828;&#50752; &#49345;&#49549;</h3><p>&#52628;&#49345; &#53364;&#47000;&#49828;&#45716; &#49436;&#48652;&#53364;&#47000;&#49828;&#50640;&#49436; &#44396;&#54788;&#54644;&#50556; &#54624; &#44277;&#53685; &#51064;&#53552;&#54168;&#51060;&#49828;&#47484; &#51221;&#51032;&#54616;&#45716; &#45936; &#50976;&#50857;&#54616;&#45796;. &#49436;&#48652;&#53364;&#47000;&#49828;&#44032; &#52628;&#49345; &#47700;&#49436;&#46300;&#47484; &#47784;&#46160; &#44396;&#54788;&#54616;&#47732;, &#51064;&#49828;&#53556;&#49828;&#47484; &#49373;&#49457;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>class ConcreteClass(MyAbstractClass):
    def my_method(self):
        print("This is the implementation of the abstract method")

# &#49324;&#50857; &#50696;&#49884;
obj = ConcreteClass()
obj.my_method()  # This is the implementation of the abstract method</code></pre><p></p><h3>&#51025;&#50857; &#50696;&#51228;</h3><p>&#45796;&#51020;&#51008; &#46020;&#54805;&#51032; &#47732;&#51201;&#51012; &#44228;&#49328;&#54616;&#45716; &#52628;&#49345; &#53364;&#47000;&#49828;&#47484; &#51221;&#51032;&#54616;&#44256;, &#51060;&#47484; &#49345;&#49549;&#48155;&#45716; &#49436;&#48652;&#53364;&#47000;&#49828;&#50640;&#49436; &#47732;&#51201;&#51012; &#44228;&#49328;&#54616;&#45716; &#50696;&#51228;&#51060;&#45796;.</p><pre><code>from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self):
        pass

    @abstractmethod
    def perimeter(self):
        pass

class Rectangle(Shape):
    def __init__(self, width, height):
        self.width = width
        self.height = height

    def area(self):
        return self.width * self.height

    def perimeter(self):
        return 2 * (self.width + self.height)

class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return 3.14159 * (self.radius ** 2)

    def perimeter(self):
        return 2 * 3.14159 * self.radius

# &#49324;&#50857; &#50696;&#49884;
rectangle = Rectangle(5, 10)
circle = Circle(7)

print("Rectangle area:", rectangle.area())  # Rectangle area: 50
print("Rectangle perimeter:", rectangle.perimeter())  # Rectangle perimeter: 30
print("Circle area:", circle.area())  # Circle area: 153.93804
print("Circle perimeter:", circle.perimeter())  # Circle perimeter: 43.98226
</code></pre>]]></content:encoded></item><item><title><![CDATA[44. __slots__ 클래스 속성]]></title><description><![CDATA[__slots__ &#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/44-__slots__</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/44-__slots__</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sat, 29 Jun 2024 06:32:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!jbAi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jbAi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jbAi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!jbAi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!jbAi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!jbAi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jbAi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:158613,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jbAi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!jbAi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!jbAi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!jbAi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3265c9d4-e5f4-4049-98a7-06e149e491ec_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#50640;&#49436; <code>__slots__</code>&#45716; &#53364;&#47000;&#49828; &#49549;&#49457;&#51012; &#44256;&#51221;&#54616;&#50668; &#47700;&#47784;&#47532; &#49324;&#50857;&#51012; &#52572;&#51201;&#54868;&#54616;&#44256; &#49457;&#45733;&#51012; &#54693;&#49345;&#49884;&#53412;&#45716; &#45936; &#49324;&#50857;&#46108;&#45796;. &#44592;&#48376;&#51201;&#51004;&#47196; &#54028;&#51060;&#50028; &#44061;&#52404;&#45716; <code>__dict__</code>&#46972;&#45716; &#46357;&#49492;&#45320;&#47532;&#47484; &#49324;&#50857;&#54616;&#50668; &#49549;&#49457;&#51012; &#51200;&#51109;&#54620;&#45796;. &#54616;&#51648;&#47564; <code>__slots__</code>&#47484; &#49324;&#50857;&#54616;&#47732; &#51060; &#46357;&#49492;&#45320;&#47532;&#47484; &#49373;&#47029;&#54616;&#44256;, &#44256;&#51221;&#46108; &#49549;&#49457;&#47564;&#51012; &#44032;&#51652; &#44061;&#52404;&#47484; &#47564;&#46308; &#49688; &#51080;&#45796;.</p><p></p><h3>&#44592;&#48376; &#49324;&#50857;&#48277;</h3><p>&#45796;&#51020;&#51008; <code>__slots__</code>&#51032; &#44592;&#48376;&#51201;&#51064; &#49324;&#50857;&#48277;&#51060;&#45796;.</p><pre><code>class MyClass:
    __slots__ = ['attribute1', 'attribute2']

    def __init__(self, attribute1, attribute2):
        self.attribute1 = attribute1
        self.attribute2 = attribute2

# &#49324;&#50857; &#50696;&#49884;
obj = MyClass(10, 20)
print(obj.attribute1)  # 10
print(obj.attribute2)  # 20

# &#49352;&#47196;&#50868; &#49549;&#49457;&#51012; &#52628;&#44032;&#54616;&#47140;&#44256; &#54616;&#47732; &#50724;&#47448; &#48156;&#49373;
try:
    obj.attribute3 = 30
except AttributeError as e:
    print(e)  # 'MyClass' object has no attribute 'attribute3'</code></pre><p></p><h3>&#51088;&#49464;&#54620; &#49444;&#47749;</h3><h4>__slots__&#51032; &#51109;&#51216;</h4><ol><li><p><strong>&#47700;&#47784;&#47532; &#49324;&#50857; &#44048;&#49548;</strong>: <code>__slots__</code>&#47484; &#49324;&#50857;&#54616;&#47732; &#44061;&#52404;&#44032; <code>__dict__</code>&#47484; &#49324;&#50857;&#54616;&#51648; &#50506;&#44592; &#46412;&#47928;&#50640; &#47700;&#47784;&#47532; &#49324;&#50857;&#47049;&#51060; &#51460;&#50612;&#46304;&#45796;.</p></li><li><p><strong>&#49457;&#45733; &#54693;&#49345;</strong>: &#47700;&#47784;&#47532; &#49324;&#50857;&#51060; &#52572;&#51201;&#54868;&#46104;&#50612; &#44061;&#52404; &#49373;&#49457; &#48143; &#49549;&#49457; &#51217;&#44540; &#49549;&#46020;&#44032; &#48744;&#46972;&#51652;&#45796;.</p></li></ol><h4>__slots__&#51032; &#51228;&#54620;&#49324;&#54637;</h4><ol><li><p><strong>&#44256;&#51221;&#46108; &#49549;&#49457;</strong>: <code>__slots__</code>&#50640; &#47749;&#49884;&#46108; &#49549;&#49457; &#50808;&#50640; &#49352;&#47196;&#50868; &#49549;&#49457;&#51012; &#52628;&#44032;&#54624; &#49688; &#50630;&#45796;.</p></li><li><p><strong>&#49345;&#49549;&#51032; &#51228;&#54620;</strong>: <code>__slots__</code>&#47484; &#49324;&#50857;&#54620; &#53364;&#47000;&#49828;&#47484; &#49345;&#49549;&#54624; &#46412; &#51088;&#49885; &#53364;&#47000;&#49828;&#46020; <code>__slots__</code>&#47484; &#47749;&#49884;&#51201;&#51004;&#47196; &#51221;&#51032;&#54644;&#50556; &#54620;&#45796;.</p></li><li><p><strong>&#54840;&#54872;&#49457; &#47928;&#51228;</strong>: &#51068;&#48512; &#46972;&#51060;&#48652;&#47084;&#47532;&#45208; &#44592;&#45733;&#44284;&#51032; &#54840;&#54872;&#49457;&#50640; &#47928;&#51228;&#44032; &#51080;&#51012; &#49688; &#51080;&#45796;.</p></li></ol><p></p><h3>&#49345;&#49549;&#50640;&#49436;&#51032; __slots__</h3><p><code>__slots__</code>&#47484; &#49324;&#50857;&#54620; &#53364;&#47000;&#49828;&#47484; &#49345;&#49549;&#54624; &#46412; &#51088;&#49885; &#53364;&#47000;&#49828;&#50640;&#49436; <code>__slots__</code>&#47484; &#52628;&#44032;&#47196; &#51221;&#51032;&#54624; &#49688; &#51080;&#45796;. &#51060; &#44221;&#50864;, &#48512;&#47784; &#53364;&#47000;&#49828;&#51032; <code>__slots__</code>&#47484; &#51088;&#49885; &#53364;&#47000;&#49828;&#50640; &#54252;&#54632;&#49884;&#53020;&#50556; &#54620;&#45796;.</p><pre><code>class Parent:
    __slots__ = ['attribute1']

    def __init__(self, attribute1):
        self.attribute1 = attribute1

class Child(Parent):
    __slots__ = ['attribute2']

    def __init__(self, attribute1, attribute2):
        super().__init__(attribute1)
        self.attribute2 = attribute2

# &#49324;&#50857; &#50696;&#49884;
child = Child(10, 20)
print(child.attribute1)  # 10
print(child.attribute2)  # 20

# &#49352;&#47196;&#50868; &#49549;&#49457;&#51012; &#52628;&#44032;&#54616;&#47140;&#44256; &#54616;&#47732; &#50724;&#47448; &#48156;&#49373;
try:
    child.attribute3 = 30
except AttributeError as e:
    print(e)  # 'Child' object has no attribute 'attribute3'</code></pre><p></p><h3>__slots__&#51032; &#51025;&#50857; &#50696;&#51228;</h3><p>&#45796;&#51020;&#51008; <code>__slots__</code>&#47484; &#49324;&#50857;&#54616;&#50668; &#47700;&#47784;&#47532; &#49324;&#50857;&#51012; &#52572;&#51201;&#54868;&#54620; &#44036;&#45800;&#54620; 2D &#51216;(Point) &#53364;&#47000;&#49828;&#47484; &#44396;&#54788;&#54620; &#50696;&#51228;&#51060;&#45796;.</p><pre><code>class Point:
    __slots__ = ['x', 'y']

    def __init__(self, x, y):
        self.x = x
        self.y = y

# &#49324;&#50857; &#50696;&#49884;
p1 = Point(1, 2)
p2 = Point(3, 4)

print(p1.x, p1.y)  # 1 2
print(p2.x, p2.y)  # 3 4

# &#47700;&#47784;&#47532; &#49324;&#50857;&#47049; &#48708;&#44368;
import sys

class PointWithoutSlots:
    def __init__(self, x, y):
        self.x = x
        self.y = y

p3 = PointWithoutSlots(1, 2)
print("With __slots__: ", sys.getsizeof(p1))  # __slots__ &#49324;&#50857; &#49884;
print("Without __slots__: ", sys.getsizeof(p3))  # __slots__ &#48120;&#49324;&#50857; &#49884;</code></pre><p>&#51060; &#50696;&#51228;&#50640;&#49436;&#45716; <code>__slots__</code>&#47484; &#49324;&#50857;&#54616;&#50668; <code>Point</code> &#53364;&#47000;&#49828;&#51032; &#47700;&#47784;&#47532; &#49324;&#50857;&#47049;&#51012; &#52572;&#51201;&#54868;&#54616;&#50688;&#45796;. <code>sys.getsizeof()</code> &#54632;&#49688;&#47484; &#49324;&#50857;&#54616;&#50668; <code>__slots__</code>&#47484; &#49324;&#50857;&#54620; &#44221;&#50864;&#50752; &#49324;&#50857;&#54616;&#51648; &#50506;&#51008; &#44221;&#50864;&#51032; &#47700;&#47784;&#47532; &#49324;&#50857;&#47049;&#51012; &#48708;&#44368;&#54624; &#49688; &#51080;&#45796;.</p><p></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[43. Python Property]]></title><description><![CDATA[&#54028;&#51060;&#50028; Property&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/43-python-property</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/43-python-property</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sat, 29 Jun 2024 06:22:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3lmZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3lmZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3lmZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!3lmZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!3lmZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!3lmZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3lmZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:161280,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3lmZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!3lmZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!3lmZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!3lmZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd982936-133f-4fa7-b9c3-a03d7d662ef3_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#51032; <code>property</code>&#45716; &#44061;&#52404; &#51648;&#54693; &#54532;&#47196;&#44536;&#47000;&#48141;&#50640;&#49436; &#47588;&#50864; &#50976;&#50857;&#54616;&#44172; &#49324;&#50857;&#46104;&#45716; &#44592;&#45733;&#51060;&#45796;. <code>property</code>&#45716; &#53364;&#47000;&#49828;&#51032; &#49549;&#49457;(attribute)&#50640; &#51217;&#44540;&#54624; &#46412;, &#45800;&#49692;&#54620; &#51217;&#44540;&#51012; &#45336;&#50612; &#52628;&#44032;&#51201;&#51064; &#52376;&#47532;&#47484; &#44032;&#45733;&#54616;&#44172; &#54644;&#51456;&#45796;. &#51593;, &#49549;&#49457;&#50640; &#51217;&#44540;&#54624; &#46412;&#47560;&#45796; &#53945;&#51221; &#47700;&#49436;&#46300;&#47484; &#54840;&#52636;&#54616;&#46020;&#47197; &#54624; &#49688; &#51080;&#50612; &#49549;&#49457; &#44050;&#51012; &#51069;&#44144;&#45208; &#50424; &#46412; &#53945;&#51221; &#47196;&#51649;&#51012; &#49892;&#54665;&#54624; &#49688; &#51080;&#45796;.</p><p></p><h3>&#44592;&#48376; &#49324;&#50857;&#48277;</h3><p><code>property</code> &#54632;&#49688;&#45716; &#51060;&#47484; &#50948;&#54644; &#51316;&#51116;&#54616;&#47728;, &#45796;&#51020;&#44284; &#44057;&#51008; &#45348; &#44032;&#51648; &#51064;&#51088;&#47484; &#48155;&#51012; &#49688; &#51080;&#45796;.</p><ol><li><p><code>fget</code>: &#49549;&#49457; &#44050;&#51012; &#51069;&#51012; &#46412; &#54840;&#52636;&#46104;&#45716; &#54632;&#49688;(getter)</p></li><li><p><code>fset</code>: &#49549;&#49457; &#44050;&#51012; &#49444;&#51221;&#54624; &#46412; &#54840;&#52636;&#46104;&#45716; &#54632;&#49688;(setter)</p></li><li><p><code>fdel</code>: &#49549;&#49457; &#44050;&#51012; &#49325;&#51228;&#54624; &#46412; &#54840;&#52636;&#46104;&#45716; &#54632;&#49688;(deleter)</p></li><li><p><code>doc</code>: &#49549;&#49457;&#50640; &#45824;&#54620; &#47928;&#49436;&#54868; &#47928;&#51088;&#50676;</p></li></ol><p>&#45796;&#51020; &#50696;&#51228;&#47484; &#53685;&#54644; &#45936;&#53076;&#47112;&#51060;&#53552; &#50630;&#51060; <code>property</code>&#47484; &#51221;&#51032;&#54616;&#45716; &#48169;&#48277;&#51012; &#49332;&#54196;&#48372;&#51088;.</p><pre><code>class Circle:
    def __init__(self, radius):
        self._radius = radius

    def get_radius(self):
        return self._radius

    def set_radius(self, value):
        if value &lt; 0:
            raise ValueError("&#48152;&#51648;&#47492;&#51008; 0&#48372;&#45796; &#52964;&#50556; &#54633;&#45768;&#45796;.")
        self._radius = value

    def del_radius(self):
        del self._radius

    radius = property(get_radius, set_radius, del_radius, "&#50896;&#51032; &#48152;&#51648;&#47492;&#51012; &#45208;&#53440;&#45236;&#45716; &#49549;&#49457;")

# &#49324;&#50857; &#50696;&#49884;
circle = Circle(5)
print(circle.radius)  # 5

circle.radius = 10
print(circle.radius)  # 10

try:
    circle.radius = -3  # ValueError &#48156;&#49373;
except ValueError as e:
    print(e)

del circle.radius
try:
    print(circle.radius)  # AttributeError &#48156;&#49373;
except AttributeError as e:
    print(e)</code></pre><ul><li><p><code>fget</code>: &#49549;&#49457; &#44050;&#51012; &#51069;&#51012; &#46412; &#54840;&#52636;&#46104;&#45716; &#54632;&#49688;. &#50696;&#51228;&#50640;&#49436;&#45716; <code>get_radius</code> &#54632;&#49688;&#44032; &#54644;&#45817;&#46108;&#45796;.</p></li><li><p><code>fset</code>: &#49549;&#49457; &#44050;&#51012; &#49444;&#51221;&#54624; &#46412; &#54840;&#52636;&#46104;&#45716; &#54632;&#49688;. &#50696;&#51228;&#50640;&#49436;&#45716; <code>set_radius</code> &#54632;&#49688;&#44032; &#54644;&#45817;&#46108;&#45796;.</p></li><li><p><code>fdel</code>: &#49549;&#49457; &#44050;&#51012; &#49325;&#51228;&#54624; &#46412; &#54840;&#52636;&#46104;&#45716; &#54632;&#49688;. &#50696;&#51228;&#50640;&#49436;&#45716; <code>del_radius</code> &#54632;&#49688;&#44032; &#54644;&#45817;&#46108;&#45796;.</p></li><li><p><code>doc</code>: &#49549;&#49457;&#50640; &#45824;&#54620; &#47928;&#49436;&#54868; &#47928;&#51088;&#50676;. &#50696;&#51228;&#50640;&#49436;&#45716; <code>"&#50896;&#51032; &#48152;&#51648;&#47492;&#51012; &#45208;&#53440;&#45236;&#45716; &#49549;&#49457;"</code>&#44032; &#54644;&#45817;&#46108;&#45796;.</p></li></ul><p></p><h4>@property</h4><p><code>@property</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#45716; &#47700;&#49436;&#46300;&#47484; &#49549;&#49457;&#52376;&#47100; &#49324;&#50857;&#54624; &#49688; &#51080;&#44172; &#54620;&#45796;. &#51060;&#45716; <code>getter</code> &#47700;&#49436;&#46300;&#47484; &#51221;&#51032;&#54624; &#46412; &#49324;&#50857;&#46108;&#45796;.</p><pre><code>class MyClass:
    def __init__(self, value):
        self._value = value

    @property
    def value(self):
        return self._value</code></pre><p>&#51060;&#47111;&#44172; &#54616;&#47732; <code>value</code> &#49549;&#49457;&#50640; &#51217;&#44540;&#54624; &#46412;&#47560;&#45796; <code>self._value</code> &#44050;&#51012; &#48152;&#54872;&#54616;&#45716; <code>value</code> &#47700;&#49436;&#46300;&#44032; &#54840;&#52636;&#46108;&#45796;.</p><p></p><h4>@property.setter</h4><p><code>@property.setter</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#45716; &#49549;&#49457;&#50640; &#44050;&#51012; &#49444;&#51221;&#54624; &#46412; &#54840;&#52636;&#46104;&#45716; <code>setter</code> &#47700;&#49436;&#46300;&#47484; &#51221;&#51032;&#54620;&#45796;.</p><pre><code>class MyClass:
    def __init__(self, value):
        self._value = value

    @property
    def value(self):
        return self._value

    @value.setter
    def value(self, new_value):
        self._value = new_value</code></pre><p>&#51060;&#47111;&#44172; &#54616;&#47732; <code>value</code> &#49549;&#49457;&#50640; &#44050;&#51012; &#49444;&#51221;&#54624; &#46412; <code>value</code> &#47700;&#49436;&#46300;&#44032; &#54840;&#52636;&#46104;&#50612; <code>_value</code> &#49549;&#49457; &#44050;&#51012; &#44081;&#49888;&#54616;&#44172; &#46108;&#45796;.</p><p></p><h4>@property.deleter</h4><p><code>@property.deleter</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#45716; &#49549;&#49457;&#51012; &#49325;&#51228;&#54624; &#46412; &#54840;&#52636;&#46104;&#45716; <code>deleter</code> &#47700;&#49436;&#46300;&#47484; &#51221;&#51032;&#54620;&#45796;.</p><pre><code>class MyClass:
    def __init__(self, value):
        self._value = value

    @property
    def value(self):
        return self._value

    @value.setter
    def value(self, new_value):
        self._value = new_value

    @value.deleter
    def value(self):
        del self._value</code></pre><p>&#51060;&#47111;&#44172; &#54616;&#47732; <code>value</code> &#49549;&#49457;&#51012; &#49325;&#51228;&#54624; &#46412; <code>value</code> &#47700;&#49436;&#46300;&#44032; &#54840;&#52636;&#46104;&#50612; <code>_value</code> &#49549;&#49457;&#51012; &#49325;&#51228;&#54616;&#44172; &#46108;&#45796;.</p><p></p><h3>&#51025;&#50857; &#50696;&#51228;</h3><p>&#51060;&#51228; <code>property</code>&#51032; &#51328; &#45908; &#49892;&#50857;&#51201;&#51064; &#51025;&#50857; &#50696;&#51228;&#47484; &#49332;&#54196;&#48372;&#51088;. &#50696;&#47484; &#46308;&#50612;, &#50728;&#46020;&#47484; &#49453;&#50472;&#50752; &#54868;&#50472;&#47196; &#48320;&#54872;&#54616;&#45716; &#53364;&#47000;&#49828;&#47484; &#47564;&#46308;&#50612; &#48372;&#51088;.</p><pre><code>class Temperature:
    def __init__(self, celsius):
        self._celsius = celsius

    @property
    def celsius(self):
        return self._celsius

    @celsius.setter
    def celsius(self, value):
        self._celsius = value

    @property
    def fahrenheit(self):
        return (self._celsius * 9/5) + 32

    @fahrenheit.setter
    def fahrenheit(self, value):
        self._celsius = (value - 32) * 5/9

# &#49324;&#50857; &#50696;&#49884;
temp = Temperature(25)
print(temp.celsius)  # 25
print(temp.fahrenheit)  # 77.0

temp.fahrenheit = 98.6
print(temp.celsius)  # 37.0
print(temp.fahrenheit)  # 98.6</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>fahrenheit</code> &#49549;&#49457;&#51008; <code>getter</code>&#50752; <code>setter</code> &#47700;&#49436;&#46300;&#47484; &#53685;&#54644; &#51088;&#46041;&#51004;&#47196; &#49453;&#50472;&#50752; &#54868;&#50472; &#44050;&#51012; &#48320;&#54872;&#54644;&#51456;&#45796;. &#51060;&#52376;&#47100; <code>property</code>&#47484; &#49324;&#50857;&#54616;&#47732; &#53076;&#46300;&#51032; &#44032;&#46021;&#49457;&#44284; &#50976;&#51648;&#48372;&#49688;&#49457;&#51012; &#53356;&#44172; &#54693;&#49345;&#49884;&#53420; &#49688; &#51080;&#45796;.</p><p></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[42. 파이썬 상속(Inheritance)]]></title><description><![CDATA[&#54028;&#51060;&#50028; &#49345;&#49549;&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/42-inheritance</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/42-inheritance</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Fri, 28 Jun 2024 14:16:30 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!fTqQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fTqQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fTqQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!fTqQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!fTqQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!fTqQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fTqQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:167187,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fTqQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!fTqQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!fTqQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!fTqQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91e659ab-e99f-4806-a5d9-8d7447dd945a_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#49345;&#49549;&#51008; &#44061;&#52404; &#51648;&#54693; &#54532;&#47196;&#44536;&#47000;&#48141;&#50640;&#49436; &#51473;&#50836;&#54620; &#44060;&#45392; &#51473; &#54616;&#45208;&#47196;, &#44592;&#51316; &#53364;&#47000;&#49828;(&#48512;&#47784; &#53364;&#47000;&#49828; &#46608;&#45716; &#49800;&#54140; &#53364;&#47000;&#49828;)&#51032; &#49549;&#49457;&#44284; &#47700;&#49436;&#46300;&#47484; &#49352;&#47196;&#50868; &#53364;&#47000;&#49828;(&#51088;&#49885; &#53364;&#47000;&#49828; &#46608;&#45716; &#49436;&#48652; &#53364;&#47000;&#49828;)&#44032; &#47932;&#47140;&#48155;&#50500; &#49324;&#50857;&#54616;&#45716; &#44163;&#51012; &#47568;&#54620;&#45796;. &#51060;&#47484; &#53685;&#54644; &#53076;&#46300;&#51032; &#51116;&#49324;&#50857;&#49457;&#51012; &#45458;&#51060;&#44256;, &#50976;&#51648;&#48372;&#49688;&#47484; &#50857;&#51060;&#54616;&#44172; &#54620;&#45796;.</p><p></p><h3>&#44592;&#48376; &#44060;&#45392;</h3><p>&#49345;&#49549;&#51008; &#45796;&#51020;&#44284; &#44057;&#51008; &#44592;&#48376; &#44060;&#45392;&#51012; &#54252;&#54632;&#54620;&#45796;:</p><ul><li><p><strong>&#48512;&#47784; &#53364;&#47000;&#49828; (Parent Class)</strong>: &#45796;&#47480; &#53364;&#47000;&#49828;&#50640;&#44172; &#49549;&#49457;&#44284; &#47700;&#49436;&#46300;&#47484; &#47932;&#47140;&#51452;&#45716; &#53364;&#47000;&#49828;.</p></li><li><p><strong>&#51088;&#49885; &#53364;&#47000;&#49828; (Child Class)</strong>: &#48512;&#47784; &#53364;&#47000;&#49828;&#47196;&#48512;&#53552; &#49549;&#49457;&#44284; &#47700;&#49436;&#46300;&#47484; &#47932;&#47140;&#48155;&#45716; &#53364;&#47000;&#49828;.</p></li></ul><p></p><h3>&#50696;&#51228; &#53076;&#46300;</h3><h4>&#48512;&#47784; &#53364;&#47000;&#49828; &#51221;&#51032;</h4><pre><code>class Animal:
    def __init__(self, name):
        self.name = name
    
    def speak(self):
        print(f"{self.name}&#44032; &#49548;&#47532;&#47484; &#45240;&#45796;.")</code></pre><h4>&#51088;&#49885; &#53364;&#47000;&#49828; &#51221;&#51032;</h4><p>&#48512;&#47784; &#53364;&#47000;&#49828; <code>Animal</code>&#51012; &#49345;&#49549;&#48155;&#45716; &#51088;&#49885; &#53364;&#47000;&#49828; <code>Dog</code>&#50752; <code>Cat</code>&#51012; &#51221;&#51032;&#54644;&#48372;&#51088;.</p><pre><code>class Dog(Animal):
    def speak(self):
        print(f"{self.name}&#44032; &#47693;&#47693; &#51670;&#45716;&#45796;.")

class Cat(Animal):
    def speak(self):
        print(f"{self.name}&#44032; &#50556;&#50745; &#50556;&#50745; &#50868;&#45796;.")</code></pre><p>&#44061;&#52404; &#49373;&#49457; &#48143; &#47700;&#49436;&#46300; &#54840;&#52636;</p><pre><code>dog = Dog("&#48148;&#46161;&#51060;")
cat = Cat("&#45208;&#48708;")

dog.speak()  # &#52636;&#47141;: &#48148;&#46161;&#51060;&#44032; &#47693;&#47693; &#51670;&#45716;&#45796;.
cat.speak()  # &#52636;&#47141;: &#45208;&#48708;&#44032; &#50556;&#50745; &#50556;&#50745; &#50868;&#45796;.</code></pre><p></p><h3>&#49345;&#49549;&#51032; &#51109;&#51216;</h3><ol><li><p><strong>&#53076;&#46300; &#51116;&#49324;&#50857;</strong>: &#48512;&#47784; &#53364;&#47000;&#49828;&#50640;&#49436; &#51221;&#51032;&#54620; &#49549;&#49457;&#44284; &#47700;&#49436;&#46300;&#47484; &#51088;&#49885; &#53364;&#47000;&#49828;&#50640;&#49436; &#45796;&#49884; &#51221;&#51032;&#54624; &#54596;&#50836; &#50630;&#51060; &#49324;&#50857;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>&#50976;&#51648;&#48372;&#49688; &#50857;&#51060;</strong>: &#44277;&#53685;&#46108; &#44592;&#45733;&#51012; &#48512;&#47784; &#53364;&#47000;&#49828;&#50640; &#46160;&#44256;, &#44033; &#53364;&#47000;&#49828;&#45716; &#44256;&#50976;&#54620; &#44592;&#45733;&#47564; &#52628;&#44032;&#47196; &#44396;&#54788;&#54616;&#47732; &#46104;&#48064;&#47196; &#50976;&#51648;&#48372;&#49688;&#44032; &#49789;&#45796;.</p></li><li><p><strong>&#44228;&#52789; &#44396;&#51312; &#54364;&#54788;</strong>: &#49345;&#49549;&#51012; &#53685;&#54644; &#53364;&#47000;&#49828; &#44036;&#51032; &#44228;&#52789; &#44396;&#51312;&#47484; &#47749;&#54869;&#55176; &#54364;&#54788;&#54624; &#49688; &#51080;&#45796;.</p></li></ol><p></p><p></p><h3>&#49345;&#49549;&#51032; &#51333;&#47448;</h3><p><strong>&#45800;&#51068; &#49345;&#49549; (Single Inheritance)</strong>: &#45800;&#51068; &#49345;&#49549;&#51008; &#54616;&#45208;&#51032; &#48512;&#47784; &#53364;&#47000;&#49828;&#47564;&#51012; &#49345;&#49549;&#48155;&#45716; &#48169;&#49885;&#51060;&#45796;. &#50948;&#51032; &#50696;&#51228;&#45716; &#45800;&#51068; &#49345;&#49549;&#51032; &#50696;&#51060;&#45796;.</p><p><strong>&#45796;&#51473; &#49345;&#49549; (Multiple Inheritance)</strong>: &#45796;&#51473; &#49345;&#49549;&#51008; &#46160; &#44060; &#51060;&#49345;&#51032; &#48512;&#47784; &#53364;&#47000;&#49828;&#47484; &#49345;&#49549;&#48155;&#45716; &#48169;&#49885;&#51060;&#45796;. &#54028;&#51060;&#50028;&#51008; &#45796;&#51473; &#49345;&#49549;&#51012; &#51648;&#50896;&#54620;&#45796;.</p><p></p><pre><code>class Animal:
    def __init__(self, name):
        self.name = name
    
    def move(self):
        print(f"{self.name}&#44032; &#50880;&#51649;&#51064;&#45796;.")

class Pet:
    def __init__(self, owner):
        self.owner = owner

    def show_owner(self):
        print(f"&#51452;&#51064;&#51008; {self.owner}&#51060;&#45796;.")

class Dog(Animal, Pet):
    def __init__(self, name, owner):
        Animal.__init__(self, name)
        Pet.__init__(self, owner)
    
    def speak(self):
        print(f"{self.name}&#44032; &#47693;&#47693; &#51670;&#45716;&#45796;.")

dog = Dog("&#48148;&#46161;&#51060;", "&#52384;&#49688;")
dog.speak()        # &#52636;&#47141;: &#48148;&#46161;&#51060;&#44032; &#47693;&#47693; &#51670;&#45716;&#45796;.
dog.move()         # &#52636;&#47141;: &#48148;&#46161;&#51060;&#44032; &#50880;&#51649;&#51064;&#45796;.
dog.show_owner()   # &#52636;&#47141;: &#51452;&#51064;&#51008; &#52384;&#49688;&#51060;&#45796;.</code></pre><p></p><h3>&#47700;&#49436;&#46300; &#50724;&#48260;&#46972;&#51060;&#46377; (Method Overriding)</h3><p>&#51088;&#49885; &#53364;&#47000;&#49828;&#50640;&#49436; &#48512;&#47784; &#53364;&#47000;&#49828;&#51032; &#47700;&#49436;&#46300;&#47484; &#51116;&#51221;&#51032;(&#50724;&#48260;&#46972;&#51060;&#46377;)&#54624; &#49688; &#51080;&#45796;. &#50724;&#48260;&#46972;&#51060;&#46377;&#46108; &#47700;&#49436;&#46300;&#45716; &#48512;&#47784; &#53364;&#47000;&#49828;&#51032; &#47700;&#49436;&#46300; &#45824;&#49888; &#54840;&#52636;&#46108;&#45796;.</p><pre><code>class Animal:
    def speak(self):
        print("&#46041;&#47932;&#51060; &#49548;&#47532;&#47484; &#45240;&#45796;.")

class Dog(Animal):
    def speak(self):
        print("&#44053;&#50500;&#51648;&#44032; &#47693;&#47693; &#51670;&#45716;&#45796;.")

dog = Dog()
dog.speak()  # &#52636;&#47141;: &#44053;&#50500;&#51648;&#44032; &#47693;&#47693; &#51670;&#45716;&#45796;.</code></pre><p></p><h3>super() &#54632;&#49688;</h3><p><code>super()</code> &#54632;&#49688;&#45716; &#48512;&#47784; &#53364;&#47000;&#49828;&#51032; &#47700;&#49436;&#46300;&#47484; &#54840;&#52636;&#54624; &#46412; &#49324;&#50857;&#46108;&#45796;. &#51060;&#47484; &#53685;&#54644; &#51088;&#49885; &#53364;&#47000;&#49828;&#50640;&#49436; &#48512;&#47784; &#53364;&#47000;&#49828;&#51032; &#47700;&#49436;&#46300;&#47484; &#54869;&#51109;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>class Animal:
    def speak(self):
        print("&#46041;&#47932;&#51060; &#49548;&#47532;&#47484; &#45240;&#45796;.")

class Dog(Animal):
    def speak(self):
        super().speak()  # &#48512;&#47784; &#53364;&#47000;&#49828;&#51032; speak() &#54840;&#52636;
        print("&#44053;&#50500;&#51648;&#44032; &#47693;&#47693; &#51670;&#45716;&#45796;.")

dog = Dog()
dog.speak()
# &#52636;&#47141;:
# &#46041;&#47932;&#51060; &#49548;&#47532;&#47484; &#45240;&#45796;.
# &#44053;&#50500;&#51648;&#44032; &#47693;&#47693; &#51670;&#45716;&#45796;.</code></pre>]]></content:encoded></item><item><title><![CDATA[41. 열거형 (Enumeration)이란?]]></title><description><![CDATA[&#50676;&#44144;&#54805; (Enumeration)&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/41-enumeration</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/41-enumeration</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 23 Jun 2024 07:02:12 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!vEPE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vEPE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vEPE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!vEPE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!vEPE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!vEPE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vEPE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:169527,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vEPE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!vEPE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!vEPE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!vEPE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F630daa51-2f06-4967-8c90-4ff1afa2893e_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#50640;&#49436; &#50676;&#44144;&#54805;(Enumeration) &#46608;&#45716; &#51460;&#50668;&#49436; &#50676;&#44144;&#54805;&#51008; &#47749;&#47749;&#46108; &#49345;&#49688;&#46308;&#51032; &#51665;&#54633;&#51012; &#51221;&#51032;&#54616;&#45716; &#53364;&#47000;&#49828;&#51060;&#45796;. &#50676;&#44144;&#54805;&#51012; &#49324;&#50857;&#54616;&#47732; &#53076;&#46300;&#51032; &#44032;&#46021;&#49457;&#44284; &#50976;&#51648;&#48372;&#49688;&#49457;&#51012; &#45458;&#51068; &#49688; &#51080;&#51004;&#47728;, &#51032;&#48120; &#51080;&#45716; &#51060;&#47492;&#51012; &#53685;&#54644; &#44050;&#46308;&#51012; &#44536;&#47353;&#54868;&#54624; &#49688; &#51080;&#45796;. &#54028;&#51060;&#50028;&#50640;&#49436;&#45716; <code>enum</code> &#47784;&#46280;&#51012; &#49324;&#50857;&#54616;&#50668; &#50676;&#44144;&#54805;&#51012; &#51221;&#51032;&#54624; &#49688; &#51080;&#45796;.</p><p></p><h4><code>enum</code> &#47784;&#46280;</h4><p><code>enum</code> &#47784;&#46280;&#51008; &#50676;&#44144;&#54805;&#51012; &#51221;&#51032;&#54616;&#44592; &#50948;&#54644; &#51228;&#44277;&#46104;&#47728;, <code>Enum</code> &#53364;&#47000;&#49828;&#47484; &#49324;&#50857;&#54616;&#50668; &#50676;&#44144;&#54805;&#51012; &#51221;&#51032;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>from enum import Enum

class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>Color</code>&#45716; <code>Enum</code> &#53364;&#47000;&#49828;&#47484; &#49345;&#49549;&#48155;&#50500; &#51221;&#51032;&#46108; &#50676;&#44144;&#54805;&#51060;&#45796;. <code>RED</code>, <code>GREEN</code>, <code>BLUE</code>&#45716; &#50676;&#44144;&#54805;&#51032; &#47716;&#48260;&#51060;&#47728;, &#44033;&#44033; <code>1</code>, <code>2</code>, <code>3</code>&#51032; &#44050;&#51012; &#44032;&#51652;&#45796;.</p><p></p><h4>&#50676;&#44144;&#54805;&#51032; &#47716;&#48260; &#51217;&#44540;</h4><p>&#50676;&#44144;&#54805;&#51032; &#47716;&#48260;&#45716; &#51216; &#54364;&#44592;&#48277;&#51012; &#49324;&#50857;&#54616;&#50668; &#51217;&#44540;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>print(Color.RED)  # Color.RED &#52636;&#47141;
print(Color.GREEN)  # Color.GREEN &#52636;&#47141;
print(Color.BLUE)  # Color.BLUE &#52636;&#47141;

print(Color.RED.name)  # RED &#52636;&#47141;
print(Color.RED.value)  # 1 &#52636;&#47141;</code></pre><ul><li><p><code>Color.RED</code>: &#50676;&#44144;&#54805; &#47716;&#48260; &#51088;&#52404;&#47484; &#45208;&#53440;&#45240;&#45796;.</p></li><li><p><code>Color.RED.name</code>: &#50676;&#44144;&#54805; &#47716;&#48260;&#51032; &#51060;&#47492;&#51012; &#47928;&#51088;&#50676;&#47196; &#48152;&#54872;&#54620;&#45796;.</p></li><li><p><code>Color.RED.value</code>: &#50676;&#44144;&#54805; &#47716;&#48260;&#51032; &#44050;&#51012; &#48152;&#54872;&#54620;&#45796;.</p></li></ul><p></p><h4>&#50676;&#44144;&#54805;&#51032; &#51060;&#53552;&#47112;&#51060;&#49496;</h4><p>&#50676;&#44144;&#54805;&#51008; &#51060;&#53552;&#47084;&#48660;(iterable)&#51060;&#45796;. &#51060;&#47484; &#53685;&#54644; &#50676;&#44144;&#54805;&#51032; &#47784;&#46304; &#47716;&#48260;&#47484; &#48152;&#48373;(iterate)&#54624; &#49688; &#51080;&#45796;.</p><pre><code>for color in Color:
    print(color)</code></pre><p>&#50948; &#53076;&#46300;&#45716; <code>Color</code> &#50676;&#44144;&#54805;&#51032; &#47784;&#46304; &#47716;&#48260;&#47484; &#49692;&#54924;&#54616;&#47728; &#44033;&#44033;&#51012; &#52636;&#47141;&#54620;&#45796;.</p><p></p><h4>&#50676;&#44144;&#54805;&#51032; &#48708;&#44368;</h4><p>&#50676;&#44144;&#54805; &#47716;&#48260;&#45716; &#46041;&#51068;&#54620; &#50676;&#44144;&#54805; &#45236;&#50640;&#49436; &#48708;&#44368;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>print(Color.RED == Color.RED)  # True &#52636;&#47141;
print(Color.RED == Color.BLUE)  # False &#52636;&#47141;
print(Color.RED is Color.RED)  # True &#52636;&#47141;
print(Color.RED is Color.BLUE)  # False &#52636;&#47141;</code></pre><p></p><h4>&#50676;&#44144;&#54805;&#51032; &#54876;&#50857;</h4><p>&#50676;&#44144;&#54805;&#51008; &#53076;&#46300;&#50640;&#49436; &#51032;&#48120; &#51080;&#45716; &#49345;&#49688; &#44050;&#51012; &#51221;&#51032;&#54624; &#46412; &#50976;&#50857;&#54616;&#45796;. &#50696;&#47484; &#46308;&#50612;, &#49345;&#53468; &#53076;&#46300;, &#48169;&#54693;, &#50741;&#49496; &#46321;&#51012; &#51221;&#51032;&#54616;&#45716; &#45936; &#49324;&#50857;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>from enum import Enum, auto

class Status(Enum):
    NEW = auto()
    IN_PROGRESS = auto()
    COMPLETED = auto()
    FAILED = auto()

# &#49345;&#53468; &#54869;&#51064;
print(Status.NEW)  # Status.NEW &#52636;&#47141;
print(Status.IN_PROGRESS)  # Status.IN_PROGRESS &#52636;&#47141;

# &#50676;&#44144;&#54805;&#51032; &#51060;&#47492;&#44284; &#44050;
print(Status.NEW.name)  # NEW &#52636;&#47141;
print(Status.NEW.value)  # 1 &#52636;&#47141;

# &#49345;&#53468; &#48708;&#44368;
current_status = Status.IN_PROGRESS
if current_status == Status.IN_PROGRESS:
    print("&#54788;&#51116; &#51089;&#50629;&#51060; &#51652;&#54665; &#51473;&#51077;&#45768;&#45796;.")</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>Status</code> &#50676;&#44144;&#54805;&#51008; &#51089;&#50629;&#51032; &#49345;&#53468;&#47484; &#45208;&#53440;&#45236;&#47728;, <code>auto()</code>&#47484; &#49324;&#50857;&#54616;&#50668; &#51088;&#46041;&#51004;&#47196; &#44050;&#51012; &#54624;&#45817;&#54620;&#45796;. &#51060;&#45716; &#44050;&#51060; &#51473;&#50836;&#54620; &#44163;&#51060; &#50500;&#45768;&#46972; &#49345;&#53468;&#47484; &#51032;&#48120; &#51080;&#45716; &#51060;&#47492;&#51004;&#47196; &#44396;&#48516;&#54616;&#45716; &#44163;&#51060; &#51473;&#50836;&#54624; &#46412; &#50976;&#50857;&#54616;&#45796;.</p><p></p><h4>&#50676;&#44144;&#54805; &#47716;&#48260;&#51032; &#49549;&#49457;&#44284; &#47700;&#49436;&#46300;</h4><p>&#50676;&#44144;&#54805; &#47716;&#48260;&#45716; &#45796;&#50577;&#54620; &#49549;&#49457;&#44284; &#47700;&#49436;&#46300;&#47484; &#51228;&#44277;&#54620;&#45796;.</p><ul><li><p><code>name</code>: &#50676;&#44144;&#54805; &#47716;&#48260;&#51032; &#51060;&#47492;&#51012; &#48152;&#54872;&#54620;&#45796;.</p></li><li><p><code>value</code>: &#50676;&#44144;&#54805; &#47716;&#48260;&#51032; &#44050;&#51012; &#48152;&#54872;&#54620;&#45796;.</p></li><li><p><code>__members__</code>: &#50676;&#44144;&#54805;&#51032; &#47784;&#46304; &#47716;&#48260;&#47484; &#49324;&#51204;(dictionary) &#54805;&#53468;&#47196; &#48152;&#54872;&#54620;&#45796;.</p></li></ul><pre><code># &#47784;&#46304; &#47716;&#48260; &#54869;&#51064;
print(Status.__members__)  # {'NEW': &lt;Status.NEW: 1&gt;, 'IN_PROGRESS': &lt;Status.IN_PROGRESS: 2&gt;, 'COMPLETED': &lt;Status.COMPLETED: 3&gt;, 'FAILED': &lt;Status.FAILED: 4&gt;} &#52636;&#47141;</code></pre>]]></content:encoded></item><item><title><![CDATA[40. 스페셜 메서드 (Special Methods)]]></title><description><![CDATA[Special Methods&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/40-special-methods</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/40-special-methods</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 23 Jun 2024 06:54:59 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!8g8Q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8g8Q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8g8Q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!8g8Q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!8g8Q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!8g8Q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8g8Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:175219,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8g8Q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!8g8Q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!8g8Q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!8g8Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9e5e19a4-05af-4f9d-a636-e56194e024e9_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028; &#53364;&#47000;&#49828;&#50640;&#49436; &#49828;&#54168;&#49500; &#47700;&#49436;&#46300;(Special Methods) &#46608;&#45716; &#47588;&#51649; &#47700;&#49436;&#46300;(Magic Methods)&#45716; &#53945;&#51221; &#49345;&#54889;&#50640;&#49436; &#51088;&#46041;&#51004;&#47196; &#54840;&#52636;&#46104;&#45716; &#53945;&#48324;&#54620; &#47700;&#49436;&#46300;&#46308;&#51060;&#45796;. &#51060;&#47084;&#54620; &#47700;&#49436;&#46300;&#45716; &#51060;&#51473; &#48145;&#51460;(<code>__</code>)&#47196; &#49884;&#51089;&#54616;&#44256; &#45149;&#45208;&#47728;, &#44061;&#52404;&#51032; &#53945;&#49688;&#54620; &#46041;&#51089;&#51012; &#51221;&#51032;&#54616;&#45716; &#45936; &#49324;&#50857;&#46108;&#45796;. &#49828;&#54168;&#49500; &#47700;&#49436;&#46300;&#45716; &#53364;&#47000;&#49828;&#51032; &#51064;&#49828;&#53556;&#49828;&#44032; &#44592;&#48376; &#45936;&#51060;&#53552; &#53440;&#51077;&#52376;&#47100; &#46041;&#51089;&#54624; &#49688; &#51080;&#44172; &#54644;&#51456;&#45796;.</p><p></p><h3>&#51452;&#50836; &#49828;&#54168;&#49500; &#47700;&#49436;&#46300;</h3><h4><code>__init__(self, ...)</code> - &#52488;&#44592;&#54868; &#47700;&#49436;&#46300;</h4><ul><li><p>&#44061;&#52404;&#44032; &#49373;&#49457;&#46112; &#46412; &#54840;&#52636;&#46104;&#50612; &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;&#47484; &#52488;&#44592;&#54868;&#54620;&#45796;.</p></li></ul><pre><code>class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age</code></pre><p></p><h4><code>__str__(self)</code> - &#47928;&#51088;&#50676; &#54364;&#54788;</h4><ul><li><p><code>print()</code> &#54632;&#49688;&#47196; &#44061;&#52404;&#47484; &#52636;&#47141;&#54624; &#46412; &#54840;&#52636;&#46104;&#50612; &#49324;&#46988;&#51060; &#51069;&#44592; &#49772;&#50868; &#54805;&#53468;&#47196; &#48152;&#54872;&#54620;&#45796;.</p></li></ul><pre><code>class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __str__(self):
        return f"{self.name}, {self.age}&#49332;"

person = Person("&#54861;&#44600;&#46041;", 30)
print(person)  # &#54861;&#44600;&#46041;, 30&#49332; &#52636;&#47141;</code></pre><p></p><h4><code>__repr__(self)</code> - &#44277;&#49885; &#47928;&#51088;&#50676; &#54364;&#54788;</h4><ul><li><p>&#44061;&#52404;&#51032; &#8220;&#44277;&#49885;&#51201;&#51064;&#8221; &#47928;&#51088;&#50676; &#54364;&#54788;&#51012; &#48152;&#54872;&#54616;&#47728;, &#51452;&#47196; &#46356;&#48260;&#44613;&#51012; &#50948;&#54644; &#49324;&#50857;&#46108;&#45796;. <code>repr()</code> &#54632;&#49688;&#45208; &#51064;&#53552;&#54532;&#47532;&#53552;&#50640;&#49436; &#44061;&#52404;&#47484; &#52636;&#47141;&#54624; &#46412; &#54840;&#52636;&#46108;&#45796;.</p></li></ul><pre><code>class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __repr__(self):
        return f"Person(name={self.name}, age={self.age})"

person = Person("&#54861;&#44600;&#46041;", 30)
print(repr(person))  # Person(name=&#54861;&#44600;&#46041;, age=30) &#52636;&#47141;</code></pre><p></p><h4><code>__len__(self)</code> - &#44600;&#51060; &#48152;&#54872;</h4><ul><li><p><code>len()</code> &#54632;&#49688;&#44032; &#54840;&#52636;&#46112; &#46412; &#44061;&#52404;&#51032; &#44600;&#51060;&#47484; &#48152;&#54872;&#54620;&#45796;.</p></li></ul><pre><code>class CustomList:
    def __init__(self, items):
        self.items = items

    def __len__(self):
        return len(self.items)

custom_list = CustomList([1, 2, 3, 4, 5])
print(len(custom_list))  # 5 &#52636;&#47141;</code></pre><p></p><h4><code>__getitem__(self, key)</code> - &#51064;&#45937;&#49905;</h4><ul><li><p>&#44061;&#52404;&#44032; &#51064;&#45937;&#49905;&#46112; &#46412; &#54840;&#52636;&#46104;&#50612; &#54644;&#45817; &#53412;&#50640; &#54644;&#45817;&#54616;&#45716; &#44050;&#51012; &#48152;&#54872;&#54620;&#45796;.</p></li></ul><pre><code>class CustomList:
    def __init__(self, items):
        self.items = items

    def __getitem__(self, index):
        return self.items[index]

custom_list = CustomList([1, 2, 3, 4, 5])
print(custom_list[2])  # 3 &#52636;&#47141;</code></pre><p></p><h4><code>__setitem__(self, key, value)</code> - &#51064;&#45937;&#49905;&#51012; &#53685;&#54620; &#44050; &#49444;&#51221;</h4><ul><li><p>&#44061;&#52404;&#51032; &#53945;&#51221; &#53412;&#50640; &#44050;&#51012; &#49444;&#51221;&#54624; &#46412; &#54840;&#52636;&#46108;&#45796;.</p></li></ul><pre><code>class CustomList:
    def __init__(self, items):
        self.items = items

    def __getitem__(self, index):
        return self.items[index]

    def __setitem__(self, index, value):
        self.items[index] = value

custom_list = CustomList([1, 2, 3, 4, 5])
custom_list[2] = 10
print(custom_list[2])  # 10 &#52636;&#47141;</code></pre><p></p><h4><code>__delitem__(self, key)</code> - &#51064;&#45937;&#49905;&#51012; &#53685;&#54620; &#44050; &#49325;&#51228;</h4><ul><li><p>&#44061;&#52404;&#51032; &#53945;&#51221; &#53412;&#50640; &#54644;&#45817;&#54616;&#45716; &#44050;&#51012; &#49325;&#51228;&#54624; &#46412; &#54840;&#52636;&#46108;&#45796;.</p></li></ul><pre><code>class CustomList:
    def __init__(self, items):
        self.items = items

    def __delitem__(self, index):
        del self.items[index]

custom_list = CustomList([1, 2, 3, 4, 5])
del custom_list[2]
print(custom_list.items)  # [1, 2, 4, 5] &#52636;&#47141;</code></pre><h4></h4><h4><code>__call__(self, ...)</code> - &#54632;&#49688;&#52376;&#47100; &#54840;&#52636;</h4><ul><li><p>&#44061;&#52404;&#44032; &#54632;&#49688;&#52376;&#47100; &#54840;&#52636;&#46112; &#46412; &#49892;&#54665;&#46108;&#45796;.</p></li></ul><pre><code>class Adder:
    def __init__(self, value):
        self.value = value

    def __call__(self, x):
        return self.value + x

adder = Adder(10)
print(adder(5))  # 15 &#52636;&#47141;</code></pre><p></p><h4><code>__eq__</code> &#47700;&#49436;&#46300; - &#46041;&#46321;&#49457; &#48708;&#44368;</h4><p><code>__eq__</code> &#47700;&#49436;&#46300;&#45716; &#46160; &#44061;&#52404;&#51032; &#46041;&#46321;&#49457;&#51012; &#48708;&#44368;&#54616;&#44592; &#50948;&#54644; &#49324;&#50857;&#46108;&#45796;. &#51060; &#47700;&#49436;&#46300;&#45716; <code>==</code> &#50672;&#49328;&#51088;&#44032; &#49324;&#50857;&#46112; &#46412; &#54840;&#52636;&#46108;&#45796;.</p><pre><code>class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __eq__(self, other):
        if isinstance(other, Person):
            return self.name == other.name and self.age == other.age
        return False

# &#44061;&#52404; &#49373;&#49457;
person1 = Person("&#54861;&#44600;&#46041;", 30)
person2 = Person("&#54861;&#44600;&#46041;", 30)
person3 = Person("&#44608;&#52384;&#49688;", 25)

# &#46041;&#46321;&#49457; &#48708;&#44368;
print(person1 == person2)  # True &#52636;&#47141;
print(person1 == person3)  # False &#52636;&#47141;</code></pre><p></p><h4><code>__hash__</code> &#47700;&#49436;&#46300; - &#54644;&#49884; &#48152;&#54872;</h4><p><code>__hash__</code> &#47700;&#49436;&#46300;&#45716; &#44061;&#52404;&#51032; &#54644;&#49884; &#44050;&#51012; &#48152;&#54872;&#54616;&#47728;, &#54644;&#49884; &#53580;&#51060;&#48660;&#50640;&#49436; &#44061;&#52404;&#47484; &#49324;&#50857;&#54624; &#49688; &#51080;&#46020;&#47197; &#54620;&#45796;. &#54644;&#49884; &#44050;&#51008; <code>set</code>&#44284; <code>dict</code>&#50752; &#44057;&#51008; &#54644;&#49884; &#44592;&#48152; &#52972;&#47113;&#49496;&#50640;&#49436; &#44061;&#52404;&#47484; &#53412;&#47196; &#49324;&#50857;&#54624; &#46412; &#54596;&#50836;&#54616;&#45796;.</p><pre><code>class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __eq__(self, other):
        if isinstance(other, Person):
            return self.name == other.name and self.age == other.age
        return False

    def __hash__(self):
        return hash((self.name, self.age))

# &#44061;&#52404; &#49373;&#49457;
person1 = Person("&#54861;&#44600;&#46041;", 30)
person2 = Person("&#54861;&#44600;&#46041;", 30)

# &#54644;&#49884; &#44050; &#54869;&#51064;
print(hash(person1))  # &#54644;&#49884; &#44050; &#52636;&#47141;
print(hash(person2))  # &#46041;&#51068;&#54620; &#54644;&#49884; &#44050; &#52636;&#47141;

# &#51665;&#54633;&#50640; &#44061;&#52404; &#52628;&#44032;
people = {person1, person2}
print(len(people))  # 1 &#52636;&#47141;, &#46041;&#46321;&#54620; &#44061;&#52404;&#45716; &#54616;&#45208;&#47196; &#44036;&#51452;</code></pre><p></p>]]></content:encoded></item><item><title><![CDATA[39. 인스턴스 Private Variable란?]]></title><description><![CDATA[&#51064;&#49828;&#53556;&#49828; Private Variable&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/39-private-variable</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/39-private-variable</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 23 Jun 2024 06:41:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!jiRt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jiRt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jiRt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!jiRt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!jiRt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!jiRt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jiRt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:175218,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jiRt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!jiRt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!jiRt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!jiRt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58871310-c6d7-49e8-8cfe-2fada8081d0f_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#51064;&#49828;&#53556;&#49828; &#54532;&#46972;&#51060;&#48727; &#48320;&#49688;&#45716; &#53364;&#47000;&#49828; &#45236;&#48512;&#50640;&#49436;&#47564; &#51217;&#44540;&#54624; &#49688; &#51080;&#46020;&#47197; &#49444;&#44228;&#46108; &#48320;&#49688;&#47196;, &#50808;&#48512;&#50640;&#49436; &#51649;&#51217; &#51217;&#44540;&#54624; &#49688; &#50630;&#46020;&#47197; &#48372;&#54840;&#46108; &#48320;&#49688;&#51060;&#45796;. &#51060;&#47084;&#54620; &#48320;&#49688;&#45716; &#48320;&#49688; &#51060;&#47492; &#50526;&#50640; &#48145;&#51460; &#46160; &#44060;(<code>__</code>)&#47484; &#48537;&#50668; &#51221;&#51032;&#46108;&#45796;. &#51060;&#47484; &#53685;&#54644; &#48320;&#49688;&#51032; &#51060;&#47492;&#51060; &#48320;&#44221;(name mangling)&#46104;&#50612; &#50808;&#48512;&#50640;&#49436;&#51032; &#51217;&#44540;&#51060; &#51228;&#54620;&#46108;&#45796;.</p><h4>&#54532;&#46972;&#51060;&#48727; &#48320;&#49688; &#51221;&#51032; &#48143; &#49324;&#50857;</h4><p>&#54532;&#46972;&#51060;&#48727; &#48320;&#49688;&#45716; &#53364;&#47000;&#49828; &#45236;&#48512;&#50640;&#49436; &#51221;&#51032;&#46104;&#47728;, &#53364;&#47000;&#49828; &#45236;&#48512;&#51032; &#47700;&#49436;&#46300;&#47484; &#53685;&#54644; &#51217;&#44540;&#54616;&#44256; &#51312;&#51089;&#54624; &#49688; &#51080;&#45796;. &#50808;&#48512;&#50640;&#49436; &#51649;&#51217; &#51217;&#44540;&#54616;&#47140;&#44256; &#54616;&#47732; <code>AttributeError</code>&#44032; &#48156;&#49373;&#54620;&#45796;.</p><pre><code>class Person:
    def __init__(self, name, age):
        self.__name = name  # &#54532;&#46972;&#51060;&#48727; &#48320;&#49688;
        self.__age = age  # &#54532;&#46972;&#51060;&#48727; &#48320;&#49688;

    def get_name(self):
        return self.__name

    def set_name(self, name):
        self.__name = name

    def get_age(self):
        return self.__age

    def set_age(self, age):
        if age &gt; 0:
            self.__age = age
        else:
            raise ValueError("&#45208;&#51060;&#45716; &#50577;&#49688;&#50668;&#50556; &#54633;&#45768;&#45796;.")

# &#44061;&#52404; &#49373;&#49457;
person = Person("&#54861;&#44600;&#46041;", 30)

# &#53364;&#47000;&#49828; &#45236;&#48512; &#47700;&#49436;&#46300;&#47484; &#53685;&#54644; &#51217;&#44540;
print(person.get_name())  # &#54861;&#44600;&#46041; &#52636;&#47141;
print(person.get_age())  # 30 &#52636;&#47141;

# &#54532;&#46972;&#51060;&#48727; &#48320;&#49688; &#51649;&#51217; &#51217;&#44540; &#49884;&#46020;
try:
    print(person.__name)
except AttributeError as e:
    print(e)  # 'Person' object has no attribute '__name' &#52636;&#47141;</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>__name</code>&#44284; <code>__age</code>&#45716; &#54532;&#46972;&#51060;&#48727; &#48320;&#49688;&#47196; &#51221;&#51032;&#46104;&#50632;&#51004;&#47728;, &#50808;&#48512;&#50640;&#49436;&#45716; &#51649;&#51217; &#51217;&#44540;&#54624; &#49688; &#50630;&#45796;. &#45824;&#49888; <code>get_name</code>, <code>set_name</code>, <code>get_age</code>, <code>set_age</code> &#47700;&#49436;&#46300;&#47484; &#53685;&#54644; &#51217;&#44540;&#54616;&#44256; &#44050;&#51012; &#48320;&#44221;&#54624; &#49688; &#51080;&#45796;.</p><p></p><h4>&#51060;&#47492; &#51109;&#49885; (Name Mangling)</h4><p>&#54028;&#51060;&#50028;&#51008; &#54532;&#46972;&#51060;&#48727; &#48320;&#49688;&#50640; &#51217;&#44540;&#51012; &#51228;&#54620;&#54616;&#44592; &#50948;&#54644; &#51060;&#47492; &#51109;&#49885;(name mangling)&#51012; &#49324;&#50857;&#54620;&#45796;. &#51060;&#45716; &#48320;&#49688; &#51060;&#47492;&#51012; &#53364;&#47000;&#49828; &#51060;&#47492;&#44284; &#44208;&#54633;&#54616;&#50668; &#48320;&#44221;&#54616;&#45716; &#48169;&#49885;&#51060;&#45796;. &#50696;&#47484; &#46308;&#50612;, <code>__name</code>&#51060;&#46972;&#45716; &#54532;&#46972;&#51060;&#48727; &#48320;&#49688;&#45716; <code>_Person__name</code>&#51004;&#47196; &#48320;&#44221;&#46108;&#45796;. &#51060;&#47484; &#53685;&#54644; &#53364;&#47000;&#49828; &#50808;&#48512;&#50640;&#49436; &#50864;&#50672;&#55176; &#51217;&#44540;&#54616;&#45716; &#44163;&#51012; &#48169;&#51648;&#54620;&#45796;.</p><pre><code># &#51060;&#47492; &#51109;&#49885;&#51012; &#53685;&#54620; &#54532;&#46972;&#51060;&#48727; &#48320;&#49688; &#51217;&#44540;
print(person._Person__name)  # &#54861;&#44600;&#46041; &#52636;&#47141;</code></pre><p>&#50948;&#50752; &#44057;&#51060; &#53364;&#47000;&#49828; &#51060;&#47492;&#51012; &#51060;&#50857;&#54644; &#54532;&#46972;&#51060;&#48727; &#48320;&#49688;&#50640; &#51217;&#44540;&#54624; &#49688; &#51080;&#51648;&#47564;, &#51060;&#45716; &#51068;&#48152;&#51201;&#51004;&#47196; &#44428;&#51109;&#46104;&#51648; &#50506;&#45716; &#48169;&#48277;&#51060;&#45796;.</p><h4>&#54532;&#46972;&#51060;&#48727; &#48320;&#49688;&#47484; &#49324;&#50857;&#54616;&#45716; &#51060;&#50976;</h4><ol><li><p><strong>&#52897;&#49808;&#54868;(Encapsulation)</strong>: &#54532;&#46972;&#51060;&#48727; &#48320;&#49688;&#45716; &#53364;&#47000;&#49828; &#45236;&#48512;&#51032; &#44396;&#54788; &#49464;&#48512; &#49324;&#54637;&#51012; &#49704;&#44592;&#44256;, &#50808;&#48512;&#47196;&#48512;&#53552; &#45936;&#51060;&#53552;&#47484; &#48372;&#54840;&#54616;&#50668; &#53364;&#47000;&#49828;&#51032; &#51068;&#44288;&#49457;&#51012; &#50976;&#51648;&#54620;&#45796;.</p></li><li><p><strong>&#45936;&#51060;&#53552; &#48372;&#54840;</strong>: &#51473;&#50836;&#54620; &#45936;&#51060;&#53552;&#45208; &#45236;&#48512; &#49345;&#53468;&#47484; &#48372;&#54840;&#54616;&#50668; &#47924;&#48516;&#48324;&#54620; &#51217;&#44540;&#44284; &#49688;&#51221;&#51004;&#47196;&#48512;&#53552; &#44061;&#52404;&#47484; &#48372;&#54840;&#54620;&#45796;.</p></li><li><p><strong>&#50976;&#51648;&#48372;&#49688; &#50857;&#51060;&#49457;</strong>: &#53364;&#47000;&#49828;&#51032; &#45236;&#48512; &#44396;&#54788;&#51060; &#48320;&#44221;&#46104;&#45908;&#46972;&#46020; &#50808;&#48512; &#53076;&#46300;&#50640; &#50689;&#54693;&#51012; &#48120;&#52824;&#51648; &#50506;&#46020;&#47197; &#54616;&#50668; &#53076;&#46300;&#51032; &#50976;&#51648;&#48372;&#49688;&#47484; &#49789;&#44172; &#54620;&#45796;.</p></li></ol><p></p>]]></content:encoded></item><item><title><![CDATA[38. __init__ 함수]]></title><description><![CDATA[__init__ &#54632;&#49688;&#50640; &#45824;&#54644;&#49436;]]></description><link>https://www.zerotoexpert.blog/p/38-__init__</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/38-__init__</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 23 Jun 2024 06:35:01 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!8FS3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8FS3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8FS3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!8FS3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!8FS3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!8FS3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8FS3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:148913,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8FS3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!8FS3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!8FS3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!8FS3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feee9cd57-6a18-45d9-8884-30927cb5bbdd_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><code>__init__</code> &#54632;&#49688;&#45716; &#54028;&#51060;&#50028; &#53364;&#47000;&#49828;&#50640;&#49436; &#44061;&#52404;&#44032; &#49373;&#49457;&#46112; &#46412; &#51088;&#46041;&#51004;&#47196; &#54840;&#52636;&#46104;&#45716; &#52488;&#44592;&#54868; &#47700;&#49436;&#46300;&#51060;&#45796;. &#51060; &#47700;&#49436;&#46300;&#45716; &#44061;&#52404;&#51032; &#49549;&#49457;&#51012; &#52488;&#44592;&#54868;&#54616;&#44256;, &#44061;&#52404; &#49373;&#49457; &#49884; &#54596;&#50836;&#54620; &#52488;&#44592; &#49444;&#51221;&#51012; &#49688;&#54665;&#54620;&#45796;. <code>__init__</code> &#47700;&#49436;&#46300;&#45716; &#49373;&#49457;&#51088;(constructor)&#46972;&#44256;&#46020; &#54620;&#45796;.</p><p></p><h4><code>__init__</code> &#54632;&#49688;&#51032; &#51221;&#51032;&#50752; &#54840;&#52636;</h4><p><code>__init__</code> &#54632;&#49688;&#45716; &#45796;&#51020;&#44284; &#44057;&#51008; &#54805;&#53468;&#47196; &#51221;&#51032;&#46108;&#45796;.</p><pre><code>class ClassName:
    def __init__(self, parameters):
        self.attribute = parameters</code></pre><ul><li><p><code>self</code>&#45716; &#49373;&#49457;&#46108; &#51064;&#49828;&#53556;&#49828;&#47484; &#52280;&#51312;&#54616;&#47728;, &#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300;&#50640;&#49436; &#54637;&#49345; &#52395; &#48264;&#51704; &#47588;&#44060;&#48320;&#49688;&#47196; &#49324;&#50857;&#46108;&#45796;.</p></li><li><p><code>parameters</code>&#45716; &#44061;&#52404;&#47484; &#49373;&#49457;&#54624; &#46412; &#54596;&#50836;&#54620; &#44050;&#51012; &#51204;&#45804;&#48155;&#45716;&#45796;.</p></li></ul><p></p><p>&#44061;&#52404;&#47484; &#49373;&#49457;&#54624; &#46412;, <code>__init__</code> &#54632;&#49688;&#45716; &#51088;&#46041;&#51004;&#47196; &#54840;&#52636;&#46104;&#47728;, &#51204;&#45804;&#46108; &#51064;&#49688;&#46308;&#51008; <code>self</code>&#47484; &#53685;&#54644; &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;&#47196; &#51200;&#51109;&#46108;&#45796;.</p><p></p><p>&#50696;&#51228;: <code>__init__</code> &#54632;&#49688; &#49324;&#50857;</p><pre><code>class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        return f"&#50504;&#45397;&#54616;&#49464;&#50836;, &#51228; &#51060;&#47492;&#51008; {self.name}&#51060;&#44256;, &#51200;&#45716; {self.age}&#49332;&#51077;&#45768;&#45796;."

# &#44061;&#52404; &#49373;&#49457;
person1 = Person("&#54861;&#44600;&#46041;", 30)
person2 = Person("&#44608;&#52384;&#49688;", 25)

# &#47700;&#49436;&#46300; &#54840;&#52636;
print(person1.greet())  # &#50504;&#45397;&#54616;&#49464;&#50836;, &#51228; &#51060;&#47492;&#51008; &#54861;&#44600;&#46041;&#51060;&#44256;, &#51200;&#45716; 30&#49332;&#51077;&#45768;&#45796;. &#52636;&#47141;
print(person2.greet())  # &#50504;&#45397;&#54616;&#49464;&#50836;, &#51228; &#51060;&#47492;&#51008; &#44608;&#52384;&#49688;&#51060;&#44256;, &#51200;&#45716; 25&#49332;&#51077;&#45768;&#45796;. &#52636;&#47141;</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>Person</code> &#53364;&#47000;&#49828;&#45716; <code>__init__</code> &#47700;&#49436;&#46300;&#47484; &#49324;&#50857;&#54616;&#50668; &#44061;&#52404; &#49373;&#49457; &#49884; &#51060;&#47492;&#44284; &#45208;&#51060;&#47484; &#52488;&#44592;&#54868;&#54620;&#45796;.</p><h4><code>__init__</code> &#54632;&#49688;&#51032; &#50669;&#54624;</h4><ol><li><p><strong>&#44061;&#52404; &#52488;&#44592;&#54868;</strong>: <code>__init__</code> &#54632;&#49688;&#45716; &#44061;&#52404;&#44032; &#49373;&#49457;&#46112; &#46412; &#52488;&#44592;&#54868; &#51089;&#50629;&#51012; &#49688;&#54665;&#54620;&#45796;.</p></li><li><p><strong>&#51064;&#49828;&#53556;&#49828; &#48320;&#49688; &#49444;&#51221;</strong>: &#44061;&#52404;&#51032; &#49549;&#49457;&#51012; &#51221;&#51032;&#54616;&#44256; &#52488;&#44592;&#44050;&#51012; &#49444;&#51221;&#54620;&#45796;.</p></li><li><p><strong>&#52488;&#44592; &#49444;&#51221;</strong>: &#44061;&#52404; &#49373;&#49457; &#49884; &#54596;&#50836;&#54620; &#52488;&#44592; &#49444;&#51221;&#51012; &#49688;&#54665;&#54620;&#45796;.</p></li></ol><p></p><h4><code>__init__</code> &#54632;&#49688;&#50752; <code>__new__</code> &#54632;&#49688;&#51032; &#52264;&#51060;</h4><ul><li><p><code>__new__</code> &#54632;&#49688;&#45716; &#44061;&#52404;&#51032; &#51064;&#49828;&#53556;&#49828;&#47484; &#49373;&#49457;&#54616;&#45716; &#50669;&#54624;&#51012; &#54616;&#47728;, &#53364;&#47000;&#49828; &#51088;&#52404;&#50640;&#49436; &#54840;&#52636;&#46108;&#45796;. <code>__new__</code> &#54632;&#49688;&#45716; &#47588;&#50864; &#46300;&#47932;&#44172; &#49324;&#50857;&#46104;&#47728;, &#51452;&#47196; &#48520;&#48320; &#44061;&#52404;(immutable object)&#47484; &#49373;&#49457;&#54624; &#46412; &#49324;&#50857;&#46108;&#45796;.</p></li><li><p><code>__init__</code> &#54632;&#49688;&#45716; &#49373;&#49457;&#46108; &#44061;&#52404;&#47484; &#52488;&#44592;&#54868;&#54616;&#45716; &#50669;&#54624;&#51012; &#54616;&#47728;, <code>self</code>&#47484; &#53685;&#54644; &#51064;&#49828;&#53556;&#49828;&#47484; &#52280;&#51312;&#54620;&#45796;.</p></li></ul><pre><code>class Example:
    def __new__(cls, *args, **kwargs):
        print("Creating instance")
        instance = super().__new__(cls)
        return instance

    def __init__(self, value):
        print("Initializing instance")
        self.value = value

# &#44061;&#52404; &#49373;&#49457;
example = Example(42)</code></pre><p></p>]]></content:encoded></item><item><title><![CDATA[37. Method와 Function의 차이]]></title><description><![CDATA[Method&#50752; Function&#51032; &#52264;&#51060;]]></description><link>https://www.zerotoexpert.blog/p/37-method-function</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/37-method-function</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 23 Jun 2024 04:39:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!PyT3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!PyT3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!PyT3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!PyT3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!PyT3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!PyT3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!PyT3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:167483,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!PyT3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!PyT3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!PyT3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!PyT3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5407e641-bdfc-4e1a-a1b0-6fadece27335_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#50640;&#49436; &#47700;&#49436;&#46300;(Method)&#50752; &#54632;&#49688;(Function)&#45716; &#51473;&#50836;&#54620; &#44060;&#45392;&#51004;&#47196;, &#46168; &#45796; &#53076;&#46300;&#51032; &#51116;&#49324;&#50857;&#49457;&#44284; &#44396;&#51312;&#54868;&#47484; &#46037;&#45716;&#45796;. &#54616;&#51648;&#47564; &#51060; &#46168;&#51008; &#49324;&#50857;&#54616;&#45716; &#47589;&#46973;&#44284; &#46041;&#51089; &#48169;&#49885;&#50640;&#49436; &#52264;&#51060;&#44032; &#51080;&#45796;.</p><p></p><h3>&#47700;&#49436;&#46300; (Method)</h3><p>&#47700;&#49436;&#46300;&#45716; &#53364;&#47000;&#49828; &#45236;&#48512;&#50640; &#51221;&#51032;&#46108; &#54632;&#49688;&#47196;, &#53364;&#47000;&#49828;&#51032; &#51064;&#49828;&#53556;&#49828;&#45208; &#53364;&#47000;&#49828; &#51088;&#52404;&#50752; &#50672;&#44288;&#46108; &#46041;&#51089;&#51012; &#51221;&#51032;&#54620;&#45796;. &#47700;&#49436;&#46300;&#45716; &#53364;&#47000;&#49828;&#51032; &#51064;&#49828;&#53556;&#49828;&#50640; &#48148;&#51064;&#46377;&#46104;&#47728;, &#52395; &#48264;&#51704; &#47588;&#44060;&#48320;&#49688;&#47196; &#54637;&#49345; <code>self</code> (&#46608;&#45716; &#53364;&#47000;&#49828; &#47700;&#49436;&#46300;&#51032; &#44221;&#50864; <code>cls</code>)&#47484; &#48155;&#45716;&#45796;.</p><p></p><p><strong>&#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300; (Instance Method)</strong></p><ul><li><p>&#53364;&#47000;&#49828;&#51032; &#51064;&#49828;&#53556;&#49828;&#50752; &#44288;&#47144;&#46108; &#46041;&#51089;&#51012; &#51221;&#51032;&#54620;&#45796;.</p></li><li><p>&#52395; &#48264;&#51704; &#47588;&#44060;&#48320;&#49688;&#47196; <code>self</code>&#47484; &#48155;&#45716;&#45796;.</p></li><li><p>&#51064;&#49828;&#53556;&#49828; &#48320;&#49688;&#50752; &#47700;&#49436;&#46300;&#50640; &#51217;&#44540;&#54624; &#49688; &#51080;&#45796;.</p></li></ul><pre><code>class Person:
    def __init__(self, name):
        self.name = name
    
    def greet(self):
        return f"&#50504;&#45397;&#54616;&#49464;&#50836;, {self.name}&#45784;!"

# &#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;
person = Person("&#54861;&#44600;&#46041;")
print(person.greet())  # &#50504;&#45397;&#54616;&#49464;&#50836;, &#54861;&#44600;&#46041;&#45784;! &#52636;&#47141;</code></pre><p><br><strong>&#53364;&#47000;&#49828; &#47700;&#49436;&#46300; (Class Method)</strong></p><ul><li><p>&#53364;&#47000;&#49828; &#51088;&#52404;&#50752; &#44288;&#47144;&#46108; &#46041;&#51089;&#51012; &#51221;&#51032;&#54620;&#45796;.</p></li><li><p>&#52395; &#48264;&#51704; &#47588;&#44060;&#48320;&#49688;&#47196; <code>cls</code>&#47484; &#48155;&#45716;&#45796;.</p></li><li><p>&#53364;&#47000;&#49828; &#48320;&#49688;&#50752; &#53364;&#47000;&#49828; &#47700;&#49436;&#46300;&#50640; &#51217;&#44540;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><code>@classmethod</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#47484; &#49324;&#50857;&#54616;&#50668; &#51221;&#51032;&#54620;&#45796;.</p></li></ul><pre><code>class Person:
    population = 0

    def __init__(self, name):
        self.name = name
        Person.population += 1

    @classmethod
    def get_population(cls):
        return f"&#52509; &#51064;&#44396;&#49688;&#45716; {cls.population}&#47749;&#51077;&#45768;&#45796;."

# &#53364;&#47000;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;
print(Person.get_population())  # &#52509; &#51064;&#44396;&#49688;&#45716; 0&#47749;&#51077;&#45768;&#45796;. &#52636;&#47141;</code></pre><p></p><p><strong>&#51221;&#51201; &#47700;&#49436;&#46300; (Static Method)</strong></p><ul><li><p>&#53364;&#47000;&#49828;&#45208; &#51064;&#49828;&#53556;&#49828;&#50752; &#46021;&#47549;&#51201;&#51004;&#47196; &#46041;&#51089;&#54620;&#45796;.</p></li><li><p>&#52395; &#48264;&#51704; &#47588;&#44060;&#48320;&#49688;&#47196; <code>self</code>&#45208; <code>cls</code>&#47484; &#48155;&#51648; &#50506;&#45716;&#45796;.</p></li><li><p><code>@staticmethod</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#47484; &#49324;&#50857;&#54616;&#50668; &#51221;&#51032;&#54620;&#45796;.</p></li></ul><pre><code>class Math:
    @staticmethod
    def add(a, b):
        return a + b

# &#51221;&#51201; &#47700;&#49436;&#46300; &#54840;&#52636;
print(Math.add(3, 5))  # 8 &#52636;&#47141;</code></pre><h3><br>&#54632;&#49688; (Function)</h3><p>&#53364;&#47000;&#49828; &#45236;&#48512;&#50640; &#51221;&#51032;&#46108; &#51068;&#48152; &#54632;&#49688;&#45716; &#53945;&#51221; &#51064;&#49828;&#53556;&#49828;&#45208; &#53364;&#47000;&#49828;&#50752; &#51649;&#51217; &#50672;&#44288;&#46104;&#51648; &#50506;&#51004;&#47728;, &#46021;&#47549;&#51201;&#51064; &#51089;&#50629;&#51012; &#49688;&#54665;&#54616;&#44592; &#50948;&#54644; &#51221;&#51032;&#46112; &#49688; &#51080;&#45796;. &#44536;&#47084;&#45208; &#51068;&#48152;&#51201;&#51004;&#47196; &#53364;&#47000;&#49828; &#45236;&#48512;&#50640;&#45716; &#47700;&#49436;&#46300;&#47564; &#51221;&#51032;&#54616;&#44256;, &#54632;&#49688;&#45716; &#53364;&#47000;&#49828; &#50808;&#48512;&#50640; &#51221;&#51032;&#54620;&#45796;.</p><p>&#53364;&#47000;&#49828; &#45236;&#48512;&#50640; &#51221;&#51032;&#46108; &#54632;&#49688;&#45716; &#53364;&#47000;&#49828;&#45208; &#51064;&#49828;&#53556;&#49828;&#51032; &#47589;&#46973;&#50640;&#49436; &#46041;&#51089;&#54616;&#51648; &#50506;&#44592; &#46412;&#47928;&#50640; &#51068;&#48152;&#51201;&#51004;&#47196; &#53364;&#47000;&#49828; &#50808;&#48512;&#50640; &#46160;&#45716; &#44163;&#51060; &#51339;&#45796;.</p><pre><code>class Example:
    def instance_method(self):
        return "&#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;&#46120;"

    @classmethod
    def class_method(cls):
        return "&#53364;&#47000;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;&#46120;"

    @staticmethod
    def static_method():
        return "&#51221;&#51201; &#47700;&#49436;&#46300; &#54840;&#52636;&#46120;"

    def regular_function():
        return "&#51060;&#44163;&#51008; &#54632;&#49688;&#51060;&#47728;, &#53364;&#47000;&#49828;&#45208; &#51064;&#49828;&#53556;&#49828;&#50752; &#50672;&#44288;&#46104;&#51648; &#50506;&#51020;"

# &#44061;&#52404; &#49373;&#49457;
example = Example()

# &#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;
print(example.instance_method())  # &#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;&#46120; &#52636;&#47141;

# &#53364;&#47000;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;
print(Example.class_method())  # &#53364;&#47000;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;&#46120; &#52636;&#47141;

# &#51221;&#51201; &#47700;&#49436;&#46300; &#54840;&#52636;
print(Example.static_method())  # &#51221;&#51201; &#47700;&#49436;&#46300; &#54840;&#52636;&#46120; &#52636;&#47141;

# &#53364;&#47000;&#49828; &#45236;&#48512;&#50640; &#51221;&#51032;&#46108; &#54632;&#49688;&#45716; &#54840;&#52636; &#48520;&#44032;
try:
    print(example.regular_function())
except TypeError as e:
    print(e)  # TypeError: regular_function() takes 0 positional arguments but 1 was given &#52636;&#47141;</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>regular_function</code>&#51008; &#53364;&#47000;&#49828; &#45236;&#48512;&#50640; &#51221;&#51032;&#46104;&#50632;&#51648;&#47564; &#51064;&#49828;&#53556;&#49828;&#45208; &#53364;&#47000;&#49828;&#50752; &#50672;&#44208;&#46104;&#51648; &#50506;&#44592; &#46412;&#47928;&#50640; &#54840;&#52636; &#49884; &#50640;&#47084;&#44032; &#48156;&#49373;&#54620;&#45796;. &#51060; &#54632;&#49688;&#45716; &#53364;&#47000;&#49828; &#45236;&#48512;&#50640;&#49436; &#51096;&#47803;&#46108; &#50948;&#52824;&#50640; &#51221;&#51032;&#46108; &#44163;&#51004;&#47196; &#48380; &#49688; &#51080;&#51004;&#47728;, &#53364;&#47000;&#49828; &#50808;&#48512;&#50640; &#51221;&#51032;&#54616;&#45716; &#44163;&#51060; &#45908; &#51201;&#51208;&#54616;&#45796;.</p><p></p><h3>&#51221;&#47532;</h3><ul><li><p><strong>&#47700;&#49436;&#46300;(Method)</strong>: &#53364;&#47000;&#49828; &#45236;&#48512;&#50640; &#51221;&#51032;&#46104;&#47728;, &#51064;&#49828;&#53556;&#49828; &#46608;&#45716; &#53364;&#47000;&#49828;&#50752; &#44288;&#47144;&#46108; &#46041;&#51089;&#51012; &#51221;&#51032;&#54620;&#45796;. &#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300;, &#53364;&#47000;&#49828; &#47700;&#49436;&#46300;, &#51221;&#51201; &#47700;&#49436;&#46300;&#47196; &#44396;&#48516;&#46108;&#45796;.</p></li><li><p><strong>&#54632;&#49688;(Function)</strong>: &#51068;&#48152;&#51201;&#51004;&#47196; &#53364;&#47000;&#49828; &#50808;&#48512;&#50640; &#51221;&#51032;&#46104;&#47728;, &#53945;&#51221; &#51089;&#50629;&#51012; &#49688;&#54665;&#54616;&#44592; &#50948;&#54620; &#46021;&#47549;&#51201;&#51064; &#53076;&#46300; &#48660;&#47197;&#51060;&#45796;. &#53364;&#47000;&#49828; &#45236;&#48512;&#50640;&#49436; &#51221;&#51032;&#46108; &#51068;&#48152; &#54632;&#49688;&#45716; &#47700;&#49436;&#46300;&#50752; &#45804;&#47532; &#53364;&#47000;&#49828;&#45208; &#51064;&#49828;&#53556;&#49828;&#50752; &#44288;&#47144;&#51060; &#50630;&#45796;.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[36. 메서드(Method)란]]></title><description><![CDATA[&#47700;&#49436;&#46300;&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/method</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/method</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 23 Jun 2024 04:30:48 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!kUZd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kUZd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kUZd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!kUZd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!kUZd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!kUZd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kUZd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:154195,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kUZd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!kUZd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!kUZd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!kUZd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fc7c172-3788-49d5-8fde-972d9b46d316_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#50640;&#49436; &#53364;&#47000;&#49828; &#45236;&#48512;&#50640; &#51221;&#51032;&#46108; &#54632;&#49688;&#50752; &#47700;&#49436;&#46300;&#45716; &#44061;&#52404; &#51648;&#54693; &#54532;&#47196;&#44536;&#47000;&#48141;(OOP)&#51032; &#51473;&#50836;&#54620; &#48512;&#48516;&#51060;&#45796;. &#53364;&#47000;&#49828; &#45236;&#48512;&#50640;&#49436; &#51221;&#51032;&#46108; &#54632;&#49688;&#45716; &#53364;&#47000;&#49828;&#50752; &#51064;&#49828;&#53556;&#49828;&#51032; &#54665;&#46041;&#51012; &#51221;&#51032;&#54616;&#45716; &#45936; &#49324;&#50857;&#46108;&#45796;. </p><p></p><h4>1. &#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300; (Instance Method)</h4><p>&#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300;&#45716; &#53364;&#47000;&#49828;&#51032; &#51064;&#49828;&#53556;&#49828;&#50640; &#45824;&#54644; &#46041;&#51089;&#54616;&#47728;, &#52395; &#48264;&#51704; &#47588;&#44060;&#48320;&#49688;&#47196; &#54637;&#49345; <code>self</code>&#47484; &#48155;&#45716;&#45796;. <code>self</code>&#45716; &#54644;&#45817; &#47700;&#49436;&#46300;&#44032; &#54840;&#52636;&#46108; &#51064;&#49828;&#53556;&#49828;&#47484; &#52280;&#51312;&#54620;&#45796;.</p><pre><code>class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        return f"&#50504;&#45397;&#54616;&#49464;&#50836;, {self.name}&#45784;! &#51200;&#45716; {self.age}&#49332;&#51077;&#45768;&#45796;."

# &#44061;&#52404; &#49373;&#49457; &#48143; &#47700;&#49436;&#46300; &#54840;&#52636;
person = Person("&#54861;&#44600;&#46041;", 30)
print(person.greet())  # &#50504;&#45397;&#54616;&#49464;&#50836;, &#54861;&#44600;&#46041;&#45784;! &#51200;&#45716; 30&#49332;&#51077;&#45768;&#45796;. &#52636;&#47141;</code></pre><p></p><h4>2. &#53364;&#47000;&#49828; &#47700;&#49436;&#46300; (Class Method)</h4><p>&#53364;&#47000;&#49828; &#47700;&#49436;&#46300;&#45716; &#53364;&#47000;&#49828; &#51088;&#52404;&#47484; &#45824;&#49345;&#51004;&#47196; &#46041;&#51089;&#54616;&#47728;, &#52395; &#48264;&#51704; &#47588;&#44060;&#48320;&#49688;&#47196; <code>cls</code>&#47484; &#48155;&#45716;&#45796;. <code>cls</code>&#45716; &#54644;&#45817; &#47700;&#49436;&#46300;&#44032; &#54840;&#52636;&#46108; &#53364;&#47000;&#49828;&#47484; &#52280;&#51312;&#54620;&#45796;. &#53364;&#47000;&#49828; &#47700;&#49436;&#46300;&#45716; <code>@classmethod</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#47196; &#51221;&#51032;&#46108;&#45796;.</p><pre><code>class Person:
    population = 0  # &#53364;&#47000;&#49828; &#48320;&#49688;

    def __init__(self, name, age):
        self.name = name
        self.age = age
        Person.population += 1

    @classmethod
    def get_population(cls):
        return f"&#52509; &#51064;&#44396;&#49688;&#45716; {cls.population}&#47749;&#51077;&#45768;&#45796;."

# &#44061;&#52404; &#49373;&#49457;
person1 = Person("&#54861;&#44600;&#46041;", 30)
person2 = Person("&#44608;&#52384;&#49688;", 25)

# &#53364;&#47000;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;
print(Person.get_population())  # &#52509; &#51064;&#44396;&#49688;&#45716; 2&#47749;&#51077;&#45768;&#45796;. &#52636;&#47141;</code></pre><p></p><h4>3. &#51221;&#51201; &#47700;&#49436;&#46300; (Static Method)</h4><p>&#51221;&#51201; &#47700;&#49436;&#46300;&#45716; &#53364;&#47000;&#49828;&#45208; &#51064;&#49828;&#53556;&#49828;&#50752; &#44288;&#44228;&#50630;&#51060; &#46021;&#47549;&#51201;&#51004;&#47196; &#46041;&#51089;&#54620;&#45796;. &#52395; &#48264;&#51704; &#47588;&#44060;&#48320;&#49688;&#47196; <code>self</code>&#45208; <code>cls</code>&#47484; &#48155;&#51648; &#50506;&#45716;&#45796;. &#51221;&#51201; &#47700;&#49436;&#46300;&#45716; <code>@staticmethod</code> &#45936;&#53076;&#47112;&#51060;&#53552;&#47196; &#51221;&#51032;&#46108;&#45796;.</p><pre><code>class Circle:
    pi = 3.14159  # &#53364;&#47000;&#49828; &#48320;&#49688;

    def __init__(self, radius):
        self.radius = radius  # &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;

    def area(self):
        return Circle.pi * (self.radius ** 2)  # &#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300;

    @classmethod
    def change_pi(cls, new_pi):
        cls.pi = new_pi  # &#53364;&#47000;&#49828; &#47700;&#49436;&#46300;

    @staticmethod
    def describe():
        return "&#51060; &#53364;&#47000;&#49828;&#45716; &#50896;&#51032; &#45331;&#51060;&#50752; &#44288;&#47144;&#46108; &#47700;&#49436;&#46300;&#47484; &#54252;&#54632;&#54633;&#45768;&#45796;."  # &#51221;&#51201; &#47700;&#49436;&#46300;

# &#44061;&#52404; &#49373;&#49457;
circle = Circle(5)

# &#51064;&#49828;&#53556;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;
print(circle.area())  # 78.53975 &#52636;&#47141;

# &#53364;&#47000;&#49828; &#47700;&#49436;&#46300; &#54840;&#52636;
Circle.change_pi(3.14)
print(circle.area())  # 78.5 &#52636;&#47141;

# &#51221;&#51201; &#47700;&#49436;&#46300; &#54840;&#52636;
print(Circle.describe())  # &#51060; &#53364;&#47000;&#49828;&#45716; &#50896;&#51032; &#45331;&#51060;&#50752; &#44288;&#47144;&#46108; &#47700;&#49436;&#46300;&#47484; &#54252;&#54632;&#54633;&#45768;&#45796;. &#52636;&#47141;
</code></pre>]]></content:encoded></item><item><title><![CDATA[35. 클래스 변수 (Class Variable)란?]]></title><description><![CDATA[&#53364;&#47000;&#49828; &#48320;&#49688;&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/35-class-variable</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/35-class-variable</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 23 Jun 2024 04:24:13 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!nrIL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nrIL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nrIL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!nrIL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!nrIL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!nrIL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nrIL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:170892,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nrIL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!nrIL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!nrIL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!nrIL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12281921-df2b-44e7-b2bc-acc1d8e6057d_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#53364;&#47000;&#49828; &#48320;&#49688;&#45716; &#53364;&#47000;&#49828;&#51032; &#47784;&#46304; &#51064;&#49828;&#53556;&#49828;(instance)&#46308;&#51060; &#44277;&#50976;&#54616;&#45716; &#48320;&#49688;&#51060;&#45796;. &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;&#50752; &#45804;&#47532;, &#53364;&#47000;&#49828; &#48320;&#49688;&#45716; &#53364;&#47000;&#49828; &#51088;&#52404;&#50640; &#49549;&#54616;&#47728;, &#47784;&#46304; &#51064;&#49828;&#53556;&#49828;&#44032; &#46041;&#51068;&#54620; &#44050;&#51012; &#44032;&#51652;&#45796;.</p><p></p><h4>&#53364;&#47000;&#49828; &#48320;&#49688; &#51221;&#51032; &#48143; &#49324;&#50857;</h4><p>&#53364;&#47000;&#49828; &#48320;&#49688;&#45716; &#53364;&#47000;&#49828; &#48660;&#47197; &#50504;&#50640; &#51649;&#51217; &#51221;&#51032;&#46108;&#45796;. &#53364;&#47000;&#49828; &#48320;&#49688;&#47484; &#51221;&#51032;&#54620; &#54980;&#50640;&#45716; &#53364;&#47000;&#49828; &#51060;&#47492;&#51012; &#53685;&#54644; &#51217;&#44540;&#54616;&#44144;&#45208;, &#51064;&#49828;&#53556;&#49828; &#51060;&#47492;&#51012; &#53685;&#54644; &#51217;&#44540;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>class Person:
    species = "Homo sapiens"  # &#53364;&#47000;&#49828; &#48320;&#49688;

    def __init__(self, name, age):
        self.name = name  # &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;
        self.age = age  # &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;

# &#53364;&#47000;&#49828; &#48320;&#49688;&#47484; &#53364;&#47000;&#49828; &#51060;&#47492;&#51012; &#53685;&#54644; &#51217;&#44540;
print(Person.species)  # Homo sapiens &#52636;&#47141;

# &#44061;&#52404; &#49373;&#49457;
person1 = Person("&#54861;&#44600;&#46041;", 30)
person2 = Person("&#44608;&#52384;&#49688;", 25)

# &#53364;&#47000;&#49828; &#48320;&#49688;&#47484; &#51064;&#49828;&#53556;&#49828;&#47484; &#53685;&#54644; &#51217;&#44540;
print(person1.species)  # Homo sapiens &#52636;&#47141;
print(person2.species)  # Homo sapiens &#52636;&#47141;

# &#53364;&#47000;&#49828; &#48320;&#49688;&#51032; &#44050; &#48320;&#44221;
Person.species = "Human"

# &#48320;&#44221;&#46108; &#53364;&#47000;&#49828; &#48320;&#49688; &#44050; &#54869;&#51064;
print(person1.species)  # Human &#52636;&#47141;
print(person2.species)  # Human &#52636;&#47141;
print(Person.species)  # Human &#52636;&#47141;</code></pre><p><br>&#53364;&#47000;&#49828; &#48320;&#49688;&#50752; &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;&#51032; &#52264;&#51060;</p><ul><li><p><strong>&#53364;&#47000;&#49828; &#48320;&#49688;</strong>: &#53364;&#47000;&#49828; &#51088;&#52404;&#50640; &#49549;&#54616;&#47728;, &#47784;&#46304; &#51064;&#49828;&#53556;&#49828;&#44032; &#44277;&#50976;&#54620;&#45796;.</p></li><li><p><strong>&#51064;&#49828;&#53556;&#49828; &#48320;&#49688;</strong>: &#44060;&#48324; &#51064;&#49828;&#53556;&#49828;&#50640; &#49549;&#54616;&#47728;, &#44033; &#51064;&#49828;&#53556;&#49828;&#47560;&#45796; &#44256;&#50976;&#54620; &#44050;&#51012; &#44032;&#51652;&#45796;.</p></li></ul><pre><code>class Dog:
    species = "Canis lupus"  # &#53364;&#47000;&#49828; &#48320;&#49688;

    def __init__(self, name):
        self.name = name  # &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;

dog1 = Dog("Max")
dog2 = Dog("Buddy")

# &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;&#45716; &#44033; &#51064;&#49828;&#53556;&#49828;&#47560;&#45796; &#45796;&#47484; &#49688; &#51080;&#45796;.
print(dog1.name)  # Max &#52636;&#47141;
print(dog2.name)  # Buddy &#52636;&#47141;

# &#53364;&#47000;&#49828; &#48320;&#49688;&#45716; &#47784;&#46304; &#51064;&#49828;&#53556;&#49828;&#44032; &#44277;&#50976;&#54620;&#45796;.
print(dog1.species)  # Canis lupus &#52636;&#47141;
print(dog2.species)  # Canis lupus &#52636;&#47141;

# &#53364;&#47000;&#49828; &#48320;&#49688; &#44050; &#48320;&#44221;
Dog.species = "Canis familiaris"
print(dog1.species)  # Canis familiaris &#52636;&#47141;
print(dog2.species)  # Canis familiaris &#52636;&#47141;</code></pre><p></p><h4><code>getattr</code> &#54632;&#49688;</h4><p><code>getattr</code> &#54632;&#49688;&#45716; &#44061;&#52404;&#50640;&#49436; &#49549;&#49457;&#51032; &#44050;&#51012; &#48152;&#54872;&#54620;&#45796;. &#47564;&#50557; &#49549;&#49457;&#51060; &#51316;&#51116;&#54616;&#51648; &#50506;&#51004;&#47732; <code>AttributeError</code>&#47484; &#48156;&#49373;&#49884;&#53412;&#44144;&#45208;, &#44592;&#48376;&#44050;&#51012; &#48152;&#54872;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>class Car:
    brand = "Toyota"  # &#53364;&#47000;&#49828; &#48320;&#49688;

# &#53364;&#47000;&#49828; &#48320;&#49688; &#51312;&#54924;
print(getattr(Car, 'brand'))  # Toyota &#52636;&#47141;

# &#51316;&#51116;&#54616;&#51648; &#50506;&#45716; &#49549;&#49457; &#51312;&#54924;
print(getattr(Car, 'model', 'Unknown'))  # Unknown &#52636;&#47141;</code></pre><p></p><h4><code>setattr</code> &#54632;&#49688;</h4><p><code>setattr</code> &#54632;&#49688;&#45716; &#44061;&#52404;&#50640; &#49549;&#49457;&#51012; &#49444;&#51221;&#54620;&#45796;. &#49549;&#49457;&#51060; &#51316;&#51116;&#54616;&#51648; &#50506;&#51004;&#47732; &#49352;&#47196;&#50868; &#49549;&#49457;&#51012; &#52628;&#44032;&#54620;&#45796;.</p><pre><code>class Car:
    brand = "Toyota"  # &#53364;&#47000;&#49828; &#48320;&#49688;

# &#53364;&#47000;&#49828; &#48320;&#49688; &#49444;&#51221;
setattr(Car, 'brand', 'Honda')
print(Car.brand)  # Honda &#52636;&#47141;

# &#49352;&#47196;&#50868; &#53364;&#47000;&#49828; &#48320;&#49688; &#52628;&#44032;
setattr(Car, 'model', 'Civic')
print(Car.model)  # Civic &#52636;&#47141;</code></pre><h4><br><code>delattr</code> &#54632;&#49688;</h4><p><code>delattr</code> &#54632;&#49688;&#45716; &#44061;&#52404;&#50640;&#49436; &#49549;&#49457;&#51012; &#49325;&#51228;&#54620;&#45796;. &#47564;&#50557; &#49549;&#49457;&#51060; &#51316;&#51116;&#54616;&#51648; &#50506;&#51004;&#47732; <code>AttributeError</code>&#47484; &#48156;&#49373;&#49884;&#53416;&#45796;.</p><pre><code>class Car:
    brand = "Toyota"  # &#53364;&#47000;&#49828; &#48320;&#49688;

# &#53364;&#47000;&#49828; &#48320;&#49688; &#49325;&#51228;
delattr(Car, 'brand')

# &#49325;&#51228;&#46108; &#49549;&#49457; &#51217;&#44540; &#49884;&#46020;
try:
    print(Car.brand)
except AttributeError as e:
    print(e)  # type object 'Car' has no attribute 'brand' &#52636;&#47141;</code></pre><p></p><h3>&#53364;&#47000;&#49828; &#48143; &#51064;&#49828;&#53556;&#49828;&#51032; <code>__dict__</code> &#49549;&#49457;</h3><p><code>__dict__</code> &#49549;&#49457;&#51008; &#44061;&#52404;&#51032; &#47784;&#46304; &#49549;&#49457;&#44284; &#44536; &#44050;&#51012; &#54252;&#54632;&#54616;&#45716; &#46357;&#49492;&#45320;&#47532;&#47484; &#48152;&#54872;&#54620;&#45796;. &#51060;&#47484; &#53685;&#54644; &#53364;&#47000;&#49828; &#48320;&#49688;&#50752; &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;&#47484; &#49789;&#44172; &#54869;&#51064;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>class Animal:
    kingdom = "Animalia"  # &#53364;&#47000;&#49828; &#48320;&#49688;

    def __init__(self, name):
        self.name = name  # &#51064;&#49828;&#53556;&#49828; &#48320;&#49688;

# &#53364;&#47000;&#49828;&#51032; __dict__ &#51312;&#54924;
print(Animal.__dict__)

# &#51064;&#49828;&#53556;&#49828;&#51032; __dict__ &#51312;&#54924;
animal1 = Animal("Tiger")
print(animal1.__dict__)</code></pre><p></p>]]></content:encoded></item><item><title><![CDATA[34. 파이썬 클래스(Class)]]></title><description><![CDATA[Class&#50640; &#45824;&#54644;&#49436; &#49345;&#49464;&#54616;&#44172; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/34-class</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/34-class</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 23 Jun 2024 04:20:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!KGiB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KGiB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KGiB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!KGiB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!KGiB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!KGiB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KGiB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/db92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:162207,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KGiB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!KGiB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!KGiB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!KGiB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb92afec-6615-4816-9995-a8d1dd1e2e95_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#53364;&#47000;&#49828;(Class)&#45716; &#44061;&#52404; &#51648;&#54693; &#54532;&#47196;&#44536;&#47000;&#48141;(OOP)&#51032; &#44592;&#48376; &#44060;&#45392; &#51473; &#54616;&#45208;&#47196;, &#44061;&#52404;&#47484; &#49373;&#49457;&#54616;&#44592; &#50948;&#54620; &#49444;&#44228;&#46020;&#51060;&#45796;. &#44061;&#52404;&#45716; &#53364;&#47000;&#49828;&#51032; &#51064;&#49828;&#53556;&#49828;(instance)&#46972;&#44256;&#46020; &#54620;&#45796;. &#53364;&#47000;&#49828;&#45716; &#45936;&#51060;&#53552; &#49549;&#49457;(attribute)&#44284; &#47700;&#49436;&#46300;(method)&#47484; &#54252;&#54632;&#54624; &#49688; &#51080;&#51004;&#47728;, &#51060;&#47484; &#53685;&#54644; &#44061;&#52404;&#51032; &#49345;&#53468;(state)&#50752; &#54665;&#46041;(behavior)&#51012; &#51221;&#51032;&#54620;&#45796;.</p><p></p><h4>&#53364;&#47000;&#49828; &#51221;&#51032;&#54616;&#44592;</h4><p>&#53364;&#47000;&#49828;&#47484; &#51221;&#51032;&#54616;&#47140;&#47732; <code>class</code> &#53412;&#50892;&#46300;&#47484; &#49324;&#50857;&#54620;&#45796;. &#53364;&#47000;&#49828;&#51032; &#51060;&#47492;&#51008; &#51068;&#48152;&#51201;&#51004;&#47196; &#45824;&#47928;&#51088;&#47196; &#49884;&#51089;&#54620;&#45796;.</p><pre><code>class Person:
    pass</code></pre><p>&#50948; &#50696;&#51228;&#45716; <code>Person</code>&#51060;&#46972;&#45716; &#48712; &#53364;&#47000;&#49828;&#47484; &#51221;&#51032;&#54620; &#44163;&#51060;&#45796;. <code>pass</code> &#53412;&#50892;&#46300;&#45716; &#50500;&#47924;&#44163;&#46020; &#54616;&#51648; &#50506;&#45716; &#47928;&#51109;&#51012; &#51032;&#48120;&#54620;&#45796;.</p><p></p><h4>&#49549;&#49457;&#44284; &#47700;&#49436;&#46300; &#52628;&#44032;&#54616;&#44592;</h4><p>&#53364;&#47000;&#49828;&#50640; &#49549;&#49457;&#44284; &#47700;&#49436;&#46300;&#47484; &#52628;&#44032;&#54616;&#50668; &#44061;&#52404;&#51032; &#49345;&#53468;&#50752; &#54665;&#46041;&#51012; &#51221;&#51032;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        return f"&#50504;&#45397;&#54616;&#49464;&#50836;, &#51228; &#51060;&#47492;&#51008; {self.name}&#51060;&#44256;, &#51200;&#45716; {self.age}&#49332;&#51077;&#45768;&#45796;."</code></pre><ul><li><p><code>__init__</code> &#47700;&#49436;&#46300;&#45716; &#49373;&#49457;&#51088;(constructor)&#47196;, &#44061;&#52404;&#44032; &#49373;&#49457;&#46112; &#46412; &#54840;&#52636;&#46108;&#45796;. &#50668;&#44592;&#49436; <code>self</code>&#45716; &#49373;&#49457;&#46108; &#44061;&#52404;&#47484; &#52280;&#51312;&#54620;&#45796;.</p></li><li><p><code>self.name</code>&#44284; <code>self.age</code>&#45716; &#51064;&#49828;&#53556;&#49828; &#49549;&#49457;(instance attribute)&#51060;&#45796;.</p></li><li><p><code>greet</code> &#47700;&#49436;&#46300;&#45716; &#51064;&#49324;&#47568;&#51012; &#48152;&#54872;&#54620;&#45796;.</p></li></ul><p></p><h4>&#44061;&#52404; &#49373;&#49457;&#54616;&#44592;</h4><p>&#53364;&#47000;&#49828;&#47196;&#48512;&#53552; &#44061;&#52404;&#47484; &#49373;&#49457;&#54616;&#47140;&#47732; &#53364;&#47000;&#49828; &#51060;&#47492;&#51012; &#54632;&#49688;&#52376;&#47100; &#54840;&#52636;&#54616;&#47732; &#46108;&#45796;.</p><pre><code>person1 = Person("&#54861;&#44600;&#46041;", 30)
print(person1.greet())</code></pre><p>&#50948; &#53076;&#46300;&#45716; <code>&#54861;&#44600;&#46041;</code>&#51060;&#46972;&#45716; &#51060;&#47492;&#44284; <code>30</code>&#49332;&#51032; &#45208;&#51060;&#47484; &#44032;&#51652; <code>Person</code> &#44061;&#52404;&#47484; &#49373;&#49457;&#54616;&#44256;, <code>greet</code> &#47700;&#49436;&#46300;&#47484; &#54840;&#52636;&#54616;&#50668; &#51064;&#49324;&#47568;&#51012; &#52636;&#47141;&#54620;&#45796;.</p><p></p><h4>&#49549;&#49457; &#51217;&#44540; &#48143; &#49688;&#51221;</h4><p>&#44061;&#52404;&#51032; &#49549;&#49457;&#50640; &#51217;&#44540;&#54616;&#44144;&#45208; &#49549;&#49457;&#51012; &#49688;&#51221;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>print(person1.name)  # &#54861;&#44600;&#46041; &#52636;&#47141;
person1.age = 31
print(person1.greet())  # "&#50504;&#45397;&#54616;&#49464;&#50836;, &#51228; &#51060;&#47492;&#51008; &#54861;&#44600;&#46041;&#51060;&#44256;, &#51200;&#45716; 31&#49332;&#51077;&#45768;&#45796;." &#52636;&#47141;</code></pre><p></p><h4>&#50696;&#51228;: &#51008;&#54665; &#44228;&#51340; &#53364;&#47000;&#49828;</h4><p>&#45796;&#51020;&#51008; &#51008;&#54665; &#44228;&#51340;&#47484; &#47784;&#45944;&#47553;&#54620; &#53364;&#47000;&#49828; &#50696;&#51228;&#51060;&#45796;.</p><pre><code>class BankAccount:
    def __init__(self, owner, balance=0):
        self.owner = owner
        self.balance = balance

    def deposit(self, amount):
        if amount &gt; 0:
            self.balance += amount
            return f"{amount}&#50896;&#51060; &#51077;&#44552;&#46104;&#50632;&#49845;&#45768;&#45796;. &#54788;&#51116; &#51092;&#50529;: {self.balance}&#50896;"
        return "&#51077;&#44552;&#54624; &#44552;&#50529;&#51060; &#50976;&#54952;&#54616;&#51648; &#50506;&#49845;&#45768;&#45796;."

    def withdraw(self, amount):
        if 0 &lt; amount &lt;= self.balance:
            self.balance -= amount
            return f"{amount}&#50896;&#51060; &#52636;&#44552;&#46104;&#50632;&#49845;&#45768;&#45796;. &#54788;&#51116; &#51092;&#50529;: {self.balance}&#50896;"
        return "&#52636;&#44552;&#54624; &#44552;&#50529;&#51060; &#50976;&#54952;&#54616;&#51648; &#50506;&#44144;&#45208; &#51092;&#50529;&#51060; &#48512;&#51313;&#54633;&#45768;&#45796;."

# &#44061;&#52404; &#49373;&#49457; &#48143; &#47700;&#49436;&#46300; &#54840;&#52636;
account = BankAccount("&#44608;&#52384;&#49688;", 1000)
print(account.deposit(500))  # 500&#50896;&#51060; &#51077;&#44552;&#46104;&#50632;&#49845;&#45768;&#45796;. &#54788;&#51116; &#51092;&#50529;: 1500&#50896; &#52636;&#47141;
print(account.withdraw(200))  # 200&#50896;&#51060; &#52636;&#44552;&#46104;&#50632;&#49845;&#45768;&#45796;. &#54788;&#51116; &#51092;&#50529;: 1300&#50896; &#52636;&#47141;
print(account.withdraw(2000))  # &#52636;&#44552;&#54624; &#44552;&#50529;&#51060; &#50976;&#54952;&#54616;&#51648; &#50506;&#44144;&#45208; &#51092;&#50529;&#51060; &#48512;&#51313;&#54633;&#45768;&#45796;. &#52636;&#47141;</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>BankAccount</code> &#53364;&#47000;&#49828;&#45716; &#51008;&#54665; &#44228;&#51340;&#51032; &#49548;&#50976;&#51088;&#50752; &#51092;&#50529;&#51012; &#49549;&#49457;&#51004;&#47196; &#44032;&#51648;&#47728;, &#51077;&#44552;&#44284; &#52636;&#44552;&#51012; &#52376;&#47532;&#54616;&#45716; &#47700;&#49436;&#46300;&#47484; &#51228;&#44277;&#54620;&#45796;.</p><p></p>]]></content:encoded></item><item><title><![CDATA[33. 객체지향 프로그래밍 (OOP)]]></title><description><![CDATA[&#44061;&#52404;&#51648;&#54693; &#54532;&#47196;&#44536;&#47000;&#48141;&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/oop</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/oop</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 23 Jun 2024 04:07:44 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ewM4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ewM4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ewM4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!ewM4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!ewM4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!ewM4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ewM4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:162995,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ewM4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!ewM4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!ewM4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!ewM4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5148f87d-67d2-4c1e-a0fa-8dce49bcdcf6_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#44061;&#52404;&#51648;&#54693; &#54532;&#47196;&#44536;&#47000;&#48141;(Object-Oriented Programming, OOP)&#51008; &#54532;&#47196;&#44536;&#47000;&#48141; &#54056;&#47084;&#45796;&#51076; &#51473; &#54616;&#45208;&#47196;, &#45936;&#51060;&#53552;&#47484; &#44061;&#52404;&#47196; &#47784;&#45944;&#47553;&#54616;&#44256; &#51060; &#44061;&#52404;&#46308;&#51060; &#49436;&#47196; &#49345;&#54840;&#51089;&#50857;&#54616;&#47728; &#54532;&#47196;&#44536;&#47016;&#51060; &#46041;&#51089;&#54616;&#46020;&#47197; &#44396;&#49457;&#54616;&#45716; &#48169;&#49885;&#51060;&#45796;. Python&#51008; &#44061;&#52404;&#51648;&#54693; &#54532;&#47196;&#44536;&#47000;&#48141;&#51012; &#44053;&#47141;&#54616;&#44172; &#51648;&#50896;&#54616;&#47728;, &#51060;&#47484; &#53685;&#54644; &#53076;&#46300;&#51032; &#51116;&#49324;&#50857;&#49457;&#44284; &#50976;&#51648;&#48372;&#49688;&#49457;&#51012; &#45458;&#51068; &#49688; &#51080;&#45796;.</p><p></p><h4>&#44061;&#52404;&#50752; &#53364;&#47000;&#49828;</h4><ul><li><p><strong>&#44061;&#52404;(Object)</strong>: &#49892;&#51228;&#47196; &#51316;&#51116;&#54616;&#45716; &#44396;&#52404;&#51201;&#51064; &#49892;&#52404;&#47484; &#47568;&#54620;&#45796;. &#50696;&#47484; &#46308;&#50612;, '&#44256;&#50577;&#51060;'&#45716; &#54616;&#45208;&#51032; &#44061;&#52404;&#44032; &#46112; &#49688; &#51080;&#45796;.</p></li><li><p><strong>&#53364;&#47000;&#49828;(Class)</strong>: &#44061;&#52404;&#47484; &#47564;&#46308;&#44592; &#50948;&#54620; &#49444;&#44228;&#46020;&#45208; &#53952;&#51012; &#51032;&#48120;&#54620;&#45796;. &#51593;, &#44061;&#52404;&#51032; &#49549;&#49457;&#44284; &#54665;&#46041;&#51012; &#51221;&#51032;&#54616;&#45716; &#52397;&#49324;&#51652;&#51060;&#45796;.</p></li></ul><p></p><h4>&#53364;&#47000;&#49828; &#51221;&#51032;&#50752; &#44061;&#52404; &#49373;&#49457;</h4><p>&#53364;&#47000;&#49828;&#47484; &#51221;&#51032;&#54616;&#44256; &#51060;&#47484; &#53685;&#54644; &#44061;&#52404;&#47484; &#49373;&#49457;&#54616;&#45716; &#44592;&#48376;&#51201;&#51064; &#48169;&#48277;&#51012; &#49332;&#54196;&#48372;&#51088;.</p><pre><code>class Dog:
    def __init__(self, name, breed):
        self.name = name
        self.breed = breed

    def bark(self):
        print(f"{self.name}&#44032; &#51670;&#45716;&#45796;: &#47693;&#47693;!")

# &#44061;&#52404; &#49373;&#49457;
my_dog = Dog("&#48148;&#46161;&#51060;", "&#51652;&#46039;&#44060;")
my_dog.bark()</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>Dog</code> &#53364;&#47000;&#49828;&#45716; <code>name</code>&#44284; <code>breed</code>&#46972;&#45716; &#46160; &#44060;&#51032; &#49549;&#49457;&#51012; &#44032;&#51648;&#44256; &#51080;&#51004;&#47728;, <code>bark</code>&#46972;&#45716; &#47700;&#49436;&#46300;&#47484; &#44032;&#51648;&#44256; &#51080;&#45796;. <code>__init__</code> &#47700;&#49436;&#46300;&#45716; &#49373;&#49457;&#51088;&#47196;, &#44061;&#52404;&#44032; &#49373;&#49457;&#46112; &#46412; &#54840;&#52636;&#46104;&#50612; &#44061;&#52404;&#51032; &#52488;&#44592; &#49345;&#53468;&#47484; &#49444;&#51221;&#54620;&#45796;.</p><p></p><h4>&#49892;&#49373;&#54876; &#50696;&#51228;: &#46020;&#49436;&#44288; &#49884;&#49828;&#53596;</h4><p>&#49892;&#49373;&#54876;&#50640; &#51201;&#54633;&#54620; &#50696;&#51228;&#47196; &#46020;&#49436;&#44288; &#49884;&#49828;&#53596;&#51012; &#47784;&#45944;&#47553;&#54644;&#48372;&#51088;. &#46020;&#49436;&#44288;&#50640;&#45716; &#52293;, &#54924;&#50896;, &#45824;&#52636; &#46321;&#51060; &#51080;&#51012; &#49688; &#51080;&#45796;.</p><pre><code>class Book:
    def __init__(self, title, author):
        self.title = title
        self.author = author
        self.is_checked_out = False

    def check_out(self):
        if not self.is_checked_out:
            self.is_checked_out = True
            print(f"{self.title}&#51060;(&#44032;) &#45824;&#52636;&#46104;&#50632;&#49845;&#45768;&#45796;.")
        else:
            print(f"{self.title}&#51008;(&#45716;) &#51060;&#48120; &#45824;&#52636; &#51473;&#51077;&#45768;&#45796;.")

    def return_book(self):
        if self.is_checked_out:
            self.is_checked_out = False
            print(f"{self.title}&#51060;(&#44032;) &#48152;&#45225;&#46104;&#50632;&#49845;&#45768;&#45796;.")
        else:
            print(f"{self.title}&#51008;(&#45716;) &#45824;&#52636;&#46104;&#51648; &#50506;&#50520;&#49845;&#45768;&#45796;.")

class Member:
    def __init__(self, name):
        self.name = name
        self.borrowed_books = []

    def borrow_book(self, book):
        if book not in self.borrowed_books:
            book.check_out()
            self.borrowed_books.append(book)
        else:
            print(f"{self.name}&#51008;(&#45716;) &#51060;&#48120; {book.title}&#51012;(&#47484;) &#45824;&#52636;&#54664;&#49845;&#45768;&#45796;.")

    def return_book(self, book):
        if book in self.borrowed_books:
            book.return_book()
            self.borrowed_books.remove(book)
        else:
            print(f"{self.name}&#51008;(&#45716;) {book.title}&#51012;(&#47484;) &#45824;&#52636;&#54616;&#51648; &#50506;&#50520;&#49845;&#45768;&#45796;.")

# &#44061;&#52404; &#49373;&#49457; &#48143; &#49324;&#50857; &#50696;&#51228;
book1 = Book("&#54028;&#51060;&#50028; &#47560;&#49828;&#53552;&#54616;&#44592;", "&#54861;&#44600;&#46041;")
member1 = Member("&#44608;&#52384;&#49688;")

member1.borrow_book(book1)
member1.return_book(book1)</code></pre><p>&#51060; &#50696;&#51228;&#50640;&#49436;&#45716; <code>Book</code> &#53364;&#47000;&#49828;&#50752; <code>Member</code> &#53364;&#47000;&#49828;&#47484; &#51221;&#51032;&#54616;&#50688;&#45796;. <code>Book</code> &#53364;&#47000;&#49828;&#45716; &#52293;&#51032; &#51228;&#47785;&#44284; &#51200;&#51088;, &#45824;&#52636; &#49345;&#53468;&#47484; &#49549;&#49457;&#51004;&#47196; &#44032;&#51648;&#47728;, &#45824;&#52636; &#48143; &#48152;&#45225; &#44592;&#45733;&#51012; &#47700;&#49436;&#46300;&#47196; &#51228;&#44277;&#54620;&#45796;. <code>Member</code> &#53364;&#47000;&#49828;&#45716; &#54924;&#50896;&#51032; &#51060;&#47492;&#44284; &#45824;&#52636;&#54620; &#52293; &#47785;&#47197;&#51012; &#49549;&#49457;&#51004;&#47196; &#44032;&#51648;&#47728;, &#52293;&#51012; &#45824;&#52636;&#54616;&#44256; &#48152;&#45225;&#54616;&#45716; &#44592;&#45733;&#51012; &#47700;&#49436;&#46300;&#47196; &#51228;&#44277;&#54620;&#45796;.</p><p></p><h4>&#49345;&#49549;</h4><p>&#49345;&#49549;&#51008; &#44061;&#52404;&#51648;&#54693; &#54532;&#47196;&#44536;&#47000;&#48141;&#51032; &#51473;&#50836;&#54620; &#53945;&#51669; &#51473; &#54616;&#45208;&#47196;, &#44592;&#51316; &#53364;&#47000;&#49828;(&#48512;&#47784; &#53364;&#47000;&#49828;)&#47484; &#44592;&#48152;&#51004;&#47196; &#49352;&#47196;&#50868; &#53364;&#47000;&#49828;(&#51088;&#49885; &#53364;&#47000;&#49828;)&#47484; &#47564;&#46308; &#49688; &#51080;&#44172; &#54620;&#45796;. &#51060;&#47484; &#53685;&#54644; &#53076;&#46300;&#51032; &#51116;&#49324;&#50857;&#49457;&#51012; &#45458;&#51068; &#49688; &#51080;&#45796;.</p><pre><code>class Librarian(Member):
    def __init__(self, name, employee_id):
        super().__init__(name)
        self.employee_id = employee_id

    def manage_books(self, book, action):
        if action == "check_out":
            book.check_out()
        elif action == "return":
            book.return_book()

# &#49324;&#49436; &#44061;&#52404; &#49373;&#49457; &#48143; &#49324;&#50857; &#50696;&#51228;
librarian = Librarian("&#51060;&#49324;&#49436;", 1001)
librarian.manage_books(book1, "check_out")
librarian.manage_books(book1, "return")</code></pre><h4><br>&#45796;&#54805;&#49457;</h4><p>&#45796;&#54805;&#49457;&#51008; &#46041;&#51068;&#54620; &#51064;&#53552;&#54168;&#51060;&#49828;&#47484; &#53685;&#54644; &#45796;&#50577;&#54620; &#44061;&#52404;&#47484; &#52376;&#47532;&#54624; &#49688; &#51080;&#44172; &#54616;&#45716; &#44061;&#52404;&#51648;&#54693; &#54532;&#47196;&#44536;&#47000;&#48141;&#51032; &#53945;&#51669;&#51060;&#45796;.</p><pre><code>class EBook(Book):
    def __init__(self, title, author, file_size):
        super().__init__(title, author)
        self.file_size = file_size

    def display_file_size(self):
        print(f"&#54028;&#51068; &#53356;&#44592;: {self.file_size}MB")

# &#51204;&#51088;&#52293; &#44061;&#52404; &#49373;&#49457; &#48143; &#49324;&#50857; &#50696;&#51228;
ebook = EBook("&#54028;&#51060;&#50028; &#54532;&#47196;&#44536;&#47000;&#48141;", "&#51060;&#47805;&#47329;", 5)
ebook.check_out()
ebook.display_file_size()</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; <code>EBook</code> &#53364;&#47000;&#49828;&#45716; <code>Book</code> &#53364;&#47000;&#49828;&#47484; &#49345;&#49549;&#48155;&#50500; &#51221;&#51032;&#46104;&#50632;&#51004;&#47728;, &#52628;&#44032;&#47196; &#54028;&#51068; &#53356;&#44592; &#49549;&#49457;&#51012; &#44032;&#51648;&#44256; &#51080;&#45796;. <code>EBook</code> &#44061;&#52404;&#45716; <code>Book</code> &#44061;&#52404;&#50752; &#46041;&#51068;&#54620; &#51064;&#53552;&#54168;&#51060;&#49828;&#47484; &#53685;&#54644; &#49324;&#50857;&#46112; &#49688; &#51080;&#45796;.<br></p>]]></content:encoded></item><item><title><![CDATA[32. __all__ 변수]]></title><description><![CDATA[__all__ &#48320;&#49688;&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/32-__all__</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/32-__all__</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Tue, 18 Jun 2024 18:22:30 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ASso!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ASso!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ASso!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!ASso!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!ASso!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!ASso!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ASso!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:149295,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ASso!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!ASso!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!ASso!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!ASso!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F497e0fea-7c0a-44be-988a-cfecb65f5d6b_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#50640;&#49436; __all__&#51008; &#47784;&#46280;&#51060; from module import * &#44396;&#47928;&#51012; &#49324;&#50857;&#54624; &#46412;, &#50808;&#48512;&#50640; &#44277;&#44060;&#54624; &#44061;&#52404;&#51032; &#47532;&#49828;&#53944;&#47484; &#51221;&#51032;&#54616;&#45716; &#53945;&#48324;&#54620; &#48320;&#49688;&#51060;&#45796;. &#51060;&#47484; &#53685;&#54644; &#47784;&#46280;&#51060; &#50808;&#48512;&#50640; &#45432;&#52636;&#54616;&#45716; &#51064;&#53552;&#54168;&#51060;&#49828;&#47484; &#47749;&#54869;&#55176; &#54624; &#49688; &#51080;&#45796;. __all__&#50640; &#51221;&#51032;&#46104;&#51648; &#50506;&#51008; &#44061;&#52404;&#45716; from module import * &#44396;&#47928;&#51004;&#47196; &#51076;&#54252;&#53944;&#46104;&#51648; &#50506;&#45716;&#45796;.</p><p></p><h3><strong>&#44592;&#48376; &#44060;&#45392;</strong></h3><p>__all__ &#48320;&#49688;&#45716; &#47784;&#46280;&#51032; &#45348;&#51076;&#49828;&#54168;&#51060;&#49828;&#50640; &#51221;&#51032;&#46108; &#44277;&#44060; &#44061;&#52404;&#51032; &#51060;&#47492;&#51012; &#47928;&#51088;&#50676;&#47196; &#54252;&#54632;&#54616;&#45716; &#47532;&#49828;&#53944;&#51060;&#45796;. &#51060;&#47484; &#53685;&#54644; &#47784;&#46280;&#51060; &#44277;&#44060;&#54624; &#44061;&#52404;&#47484; &#47749;&#49884;&#51201;&#51004;&#47196; &#51221;&#51032;&#54624; &#49688; &#51080;&#45796;.</p><p></p><p>&#45796;&#51020;&#51008; __all__&#51032; &#44592;&#48376; &#49324;&#50857; &#50696;&#51228;&#51060;&#45796;.</p><p>mymodule.py</p><pre><code>__all__ = ['public_function']

def public_function():
    print("This is a public function.")

def _private_function():
    print("This is a private function.")</code></pre><p></p><p>main.py</p><pre><code>from mymodule import *

public_function()  # This is a public function.
# _private_function()  # NameError: name '_private_function' is not defined</code></pre><ul><li><p>__all__ &#47532;&#49828;&#53944;&#50640; public_function&#47564; &#54252;&#54632;&#46104;&#50612; &#51080;&#44592; &#46412;&#47928;&#50640;, from mymodule import * &#44396;&#47928;&#51008; &#54616;&#45208;&#51032; &#44061;&#52404;&#47564; &#51076;&#54252;&#53944;&#54620;&#45796;.</p></li><li><p>_private_function&#45716; __all__ &#47532;&#49828;&#53944;&#50640; &#54252;&#54632;&#46104;&#51648; &#50506;&#50520;&#44592; &#46412;&#47928;&#50640; &#51076;&#54252;&#53944;&#46104;&#51648; &#50506;&#51004;&#47728;, main.py&#50640;&#49436; &#51217;&#44540;&#54624; &#49688; &#50630;&#45796;.</p></li></ul><p></p><h3><strong>__all__&#51032; &#51109;&#51216;</strong></h3><ol><li><p><strong>&#47749;&#54869;&#54620; &#51064;&#53552;&#54168;&#51060;&#49828; &#51221;&#51032;</strong>: __all__&#51012; &#49324;&#50857;&#54616;&#47732; &#47784;&#46280;&#51060; &#50808;&#48512;&#50640; &#44277;&#44060;&#54624; &#44061;&#52404;&#47484; &#47749;&#54869;&#55176; &#51221;&#51032;&#54624; &#49688; &#51080;&#50612;, &#47784;&#46280;&#51032; &#44277;&#50857; &#51064;&#53552;&#54168;&#51060;&#49828;&#47484; &#49789;&#44172; &#54028;&#50501;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>&#52897;&#49808;&#54868; &#44053;&#54868;</strong>: &#51473;&#50836;&#54620; &#45236;&#48512; &#44396;&#54788; &#49464;&#48512; &#49324;&#54637;&#51012; &#49704;&#44600; &#49688; &#51080;&#50612;, &#47784;&#46280;&#51032; &#49324;&#50857;&#51088;&#44032; &#51032;&#46020;&#54616;&#51648; &#50506;&#51008; &#45236;&#48512; &#44061;&#52404;&#50640; &#51217;&#44540;&#54616;&#51648; &#50506;&#46020;&#47197; &#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>&#53076;&#46300; &#50976;&#51648;&#48372;&#49688;&#49457; &#54693;&#49345;</strong>: &#47784;&#46280;&#51032; &#50808;&#48512; &#51064;&#53552;&#54168;&#51060;&#49828;&#47484; &#47749;&#54869;&#55176; &#51221;&#51032;&#54632;&#51004;&#47196;&#50024;, &#47784;&#46280;&#51012; &#49688;&#51221;&#54624; &#46412; &#51032;&#46020;&#54616;&#51648; &#50506;&#51008; &#50808;&#48512; &#50689;&#54693;(&#45796;&#47480; &#47784;&#46280;&#51060;&#45208; &#53076;&#46300;&#50640; &#48120;&#52824;&#45716; &#50689;&#54693;)&#51012; &#51460;&#51068; &#49688; &#51080;&#45796;.</p></li></ol><p></p><h3><strong>&#51452;&#51032;&#49324;&#54637;</strong></h3><ul><li><p>__all__&#51008; from module import * &#44396;&#47928;&#50640;&#47564; &#50689;&#54693;&#51012; &#48120;&#52828;&#45796;. import module&#51060;&#45208; from module import specific_name &#44396;&#47928;&#50640;&#45716; &#50689;&#54693;&#51012; &#48120;&#52824;&#51648; &#50506;&#45716;&#45796;.</p></li><li><p>__all__&#50640; &#51221;&#51032;&#46104;&#51648; &#50506;&#51008; &#44061;&#52404;&#46020; &#50668;&#51204;&#55176; &#51649;&#51217; &#51076;&#54252;&#53944;&#54624; &#49688; &#51080;&#45796;. &#50696;&#47484; &#46308;&#50612;, from mymodule import _private_function&#51008; &#50668;&#51204;&#55176; &#50976;&#54952;&#54616;&#45796;.</p></li><li><p>&#47784;&#46280; &#45236;&#50640;&#49436; &#48145;&#51460;(_)&#47196; &#49884;&#51089;&#54616;&#45716; &#51060;&#47492;&#51008; &#44288;&#47168;&#51201;&#51004;&#47196; &#54532;&#46972;&#51060;&#48727;(&#45236;&#48512;&#50857;)&#51004;&#47196; &#44036;&#51452;&#46104;&#51648;&#47564;, &#51060;&#45716; &#44053;&#51228;&#46104;&#51648; &#50506;&#51004;&#47728; __all__&#50640; &#54252;&#54632;&#54624; &#49688;&#46020; &#51080;&#45796;.</p></li></ul><p></p><p>main.py</p><pre><code>from mymodule import _private_function

_private_function()  # This is a private function.</code></pre><p>&#51060; &#50696;&#51228;&#50640;&#49436; _private_function&#51008; __all__&#50640; &#54252;&#54632;&#46104;&#51648; &#50506;&#50520;&#51648;&#47564;, &#51649;&#51217; &#51076;&#54252;&#53944;&#54616;&#50668; &#49324;&#50857;&#54624; &#49688; &#51080;&#45796;.</p>]]></content:encoded></item><item><title><![CDATA[31. Python Packages]]></title><description><![CDATA[&#54028;&#51060;&#50028; &#54056;&#53412;&#51648;&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/python-packages</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/python-packages</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Tue, 18 Jun 2024 18:17:33 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!ZgtN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZgtN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZgtN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!ZgtN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!ZgtN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!ZgtN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZgtN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:160882,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZgtN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!ZgtN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!ZgtN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!ZgtN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43c32c5d-69e3-4c3e-9e5d-ad250783be0f_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028; &#54056;&#53412;&#51648;(Package)&#45716; &#44288;&#47144; &#47784;&#46280;&#46308;&#51012; &#46356;&#47113;&#53664;&#47532; &#44396;&#51312;&#47196; &#51312;&#51649;&#54868;&#54620; &#44163;&#51060;&#45796;. &#54056;&#53412;&#51648;&#45716; &#47784;&#46280;&#46308;&#51012; &#44228;&#52789;&#51201;&#51004;&#47196; &#44396;&#49457;&#54616;&#50668;, &#53076;&#46300;&#51032; &#44396;&#51312;&#47484; &#52404;&#44228;&#51201;&#51004;&#47196; &#47564;&#46308;&#44256; &#44288;&#47532;&#54616;&#44592; &#49789;&#44172; &#54644;&#51456;&#45796;. &#54056;&#53412;&#51648;&#47484; &#49324;&#50857;&#54616;&#47732; &#45348;&#51076;&#49828;&#54168;&#51060;&#49828;&#47484; &#44396;&#48516;&#54624; &#49688; &#51080;&#50612;, &#46041;&#51068;&#54620; &#51060;&#47492;&#51032; &#47784;&#46280;&#46308;&#51060; &#49436;&#47196; &#52649;&#46028;&#54616;&#51648; &#50506;&#44172; &#46108;&#45796;.</p><p></p><h3><strong>&#54056;&#53412;&#51648; &#44396;&#51312;</strong></h3><p>&#54028;&#51060;&#50028; &#54056;&#53412;&#51648;&#45716; &#46356;&#47113;&#53664;&#47532; &#54805;&#53468;&#47196; &#44396;&#49457;&#46104;&#47728;, &#54056;&#53412;&#51648;&#51032; &#44033; &#46356;&#47113;&#53664;&#47532;&#45716; __init__.py &#54028;&#51068;&#51012; &#54252;&#54632;&#54644;&#50556; &#54620;&#45796;. __init__.py &#54028;&#51068;&#51008; &#54644;&#45817; &#46356;&#47113;&#53664;&#47532;&#47484; &#54056;&#53412;&#51648;&#47196; &#51064;&#49885;&#54616;&#44172; &#54616;&#45716; &#50669;&#54624;&#51012; &#54620;&#45796;. &#51060; &#54028;&#51068;&#51008; &#48708;&#50892;&#46168; &#49688; &#51080;&#51648;&#47564;, &#54056;&#53412;&#51648; &#52488;&#44592;&#54868; &#53076;&#46300;&#45208; &#54616;&#50948; &#47784;&#46280;&#51012; &#54252;&#54632;&#54624; &#49688; &#51080;&#45796;.</p><p></p><p>&#50696;&#51228; &#54056;&#53412;&#51648; &#44396;&#51312;</p><pre><code>my_package/
&#9474;
&#9500;&#9472;&#9472; __init__.py
&#9500;&#9472;&#9472; module1.py
&#9492;&#9472;&#9472; sub_package/
    &#9500;&#9472;&#9472; __init__.py
    &#9492;&#9472;&#9472; module2.py</code></pre><p>&#50948; &#44396;&#51312;&#50640;&#49436; my_package&#45716; &#54056;&#53412;&#51648;&#51060;&#44256;, sub_package&#45716; my_package&#51032; &#54616;&#50948; &#54056;&#53412;&#51648;&#51060;&#45796;. module1.py&#50752; module2.py&#45716; &#44033;&#44033;&#51032; &#54056;&#53412;&#51648;&#50640; &#49549;&#54620; &#47784;&#46280;&#46308;&#51060;&#45796;.</p><p></p><h3><strong>&#54056;&#53412;&#51648; &#48143; &#47784;&#46280; &#51076;&#54252;&#53944;</strong></h3><p>&#54056;&#53412;&#51648; &#48143; &#47784;&#46280;&#51012; &#51076;&#54252;&#53944;&#54616;&#45716; &#48169;&#48277;&#51008; &#45796;&#51020;&#44284; &#44057;&#45796;.<br></p><p>&#47784;&#46280; &#51076;&#54252;&#53944;</p><pre><code>import my_package.module1

my_package.module1.some_function()</code></pre><p><br>&#54616;&#50948; &#54056;&#53412;&#51648; &#47784;&#46280; &#51076;&#54252;&#53944;</p><pre><code>import my_package.sub_package.module2 my_package.sub_package.module2.another_function()</code></pre><p><br><strong>init.py &#54028;&#51068; &#54876;&#50857;</strong></p><p>__init__.py &#54028;&#51068;&#51008; &#54056;&#53412;&#51648;&#47484; &#52488;&#44592;&#54868;&#54616;&#44144;&#45208;, &#54056;&#53412;&#51648; &#45236; &#47784;&#46280;&#51012; &#54200;&#47532;&#54616;&#44172; &#51076;&#54252;&#53944;&#54624; &#49688; &#51080;&#46020;&#47197; &#49444;&#51221;&#54616;&#45716; &#45936; &#49324;&#50857;&#46108;&#45796;.</p><pre><code># my_package/__init__.py

from .module1 import some_function</code></pre><p>&#51060;&#47111;&#44172; &#49444;&#51221;&#54616;&#47732;, &#45796;&#51020;&#44284; &#44057;&#51060; &#54056;&#53412;&#51648;&#47484; &#51076;&#54252;&#53944;&#54616;&#44256; &#54632;&#49688;&#50640; &#51217;&#44540;&#54624; &#49688; &#51080;&#45796;.</p><p></p><pre><code>from my_package import some_function

some_function()</code></pre><p><br></p><p></p><h3><strong>&#50696;&#51228; &#54056;&#53412;&#51648; &#51089;&#49457;</strong></h3><p>&#50696;&#51228;&#47196; &#47564;&#46308;&#50612;&#48380; &#54056;&#53412;&#51648; &#44396;&#51312;&#45716; &#45796;&#51020;&#44284; &#44057;&#45796;.</p><pre><code>math_package/
&#9474;
&#9500;&#9472;&#9472; __init__.py
&#9500;&#9472;&#9472; basic_operations.py
&#9492;&#9472;&#9472; advanced_operations.py</code></pre><p><br>basic_operations.py</p><pre><code>def add(a, b):
    return a + b

def subtract(a, b):
    return a - b</code></pre><p><br>advanced_operations.py</p><pre><code>def square(a):
    return a * a

def cube(a):
    return a * a * a</code></pre><p></p><p>__init__.py</p><pre><code>from .basic_operations import add, subtract
from .advanced_operations import square, cube</code></pre><p></p><p>&#51060;&#51228; &#54056;&#53412;&#51648;&#47484; &#49324;&#50857;&#54644;&#48372;&#51088;.</p><pre><code>from math_package import add, subtract, square, cube

print(add(3, 5))        # 8
print(subtract(10, 4))  # 6
print(square(3))        # 9
print(cube(2))          # 8</code></pre>]]></content:encoded></item><item><title><![CDATA[30. Python __name__]]></title><description><![CDATA[__name__ &#48320;&#49688;&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/python-__name__</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/python-__name__</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Tue, 18 Jun 2024 18:12:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!gaBA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gaBA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gaBA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!gaBA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!gaBA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!gaBA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gaBA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:154970,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gaBA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!gaBA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!gaBA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!gaBA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fee6b9f7d-d8d1-48a8-912b-e291f0a3a6fb_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#50640;&#49436; __name__&#51008; &#53945;&#49688;&#54620; &#45236;&#51109; &#48320;&#49688;&#47196;, &#47784;&#46280;&#51032; &#51060;&#47492;&#51012; &#45208;&#53440;&#45240;&#45796;. &#51060;&#45716; &#54028;&#51060;&#50028; &#53076;&#46300;&#44032; &#51649;&#51217; &#49892;&#54665;&#46104;&#45716;&#51648; &#50500;&#45768;&#47732; &#45796;&#47480; &#47784;&#46280;&#50640; &#51032;&#54644; &#51076;&#54252;&#53944;&#46104;&#45716;&#51648; &#44396;&#48516;&#54616;&#45716; &#45936; &#49324;&#50857;&#46108;&#45796;. &#51060;&#47484; &#53685;&#54644; &#49828;&#53356;&#47549;&#53944;&#47484; &#51649;&#51217; &#49892;&#54665;&#54624; &#46412;&#50752; &#47784;&#46280;&#47196; &#51076;&#54252;&#53944;&#54624; &#46412;&#51032; &#46041;&#51089;&#51012; &#45796;&#47476;&#44172; &#54624; &#49688; &#51080;&#45796;.</p><p></p><h3><strong>__name__&#51032; &#44592;&#48376; &#44060;&#45392;</strong></h3><ol><li><p><strong>&#51649;&#51217; &#49892;&#54665;&#46112; &#46412;</strong>: &#54028;&#51060;&#50028; &#54028;&#51068;&#51012; &#51649;&#51217; &#49892;&#54665;&#54616;&#47732;, __name__ &#48320;&#49688;&#51032; &#44050;&#51008; "__main__"&#51060; &#46108;&#45796;.</p></li><li><p><strong>&#51076;&#54252;&#53944;&#46112; &#46412;</strong>: &#45796;&#47480; &#54028;&#51068;&#50640;&#49436; &#54644;&#45817; &#54028;&#51068;&#51012; &#47784;&#46280;&#47196; &#51076;&#54252;&#53944;&#54616;&#47732;, __name__ &#48320;&#49688;&#51032; &#44050;&#51008; &#47784;&#46280;&#51032; &#49892;&#51228; &#51060;&#47492;(&#54028;&#51068; &#51060;&#47492;)&#51060; &#46108;&#45796;.</p></li></ol><p></p><h3><strong>&#50696;&#51228;</strong></h3><p>&#45796;&#51020;&#51008; __name__&#51032; &#46041;&#51089;&#51012; &#49444;&#47749;&#54616;&#45716; &#50696;&#51228;&#51060;&#45796;.</p><p>mymodule.py</p><pre><code>def greet(name):
    return f"Hello, {name}!"

if __name__ == "__main__":
    # &#51060; &#48660;&#47197;&#51008; &#51649;&#51217; &#49892;&#54665;&#46112; &#46412;&#47564; &#49892;&#54665;&#46108;&#45796;.
    print(greet("Alice"))</code></pre><p><br>main.py</p><pre><code>import mymodule

print(mymodule.greet("Bob"))</code></pre><p><br><strong>&#49892;&#54665; &#44208;&#44284;</strong></p><p>mymodule.py&#47484; &#51649;&#51217; &#49892;&#54665;&#54624; &#46412;:</p><pre><code>$ python mymodule.py

Hello, Alice!</code></pre><p>main.py&#47484; &#49892;&#54665;&#54624; &#46412;:</p><pre><code>$ python main.py

Hello, Bob!</code></pre><p>&#50948; &#50696;&#51228;&#50640;&#49436; mymodule.py&#45716; &#51649;&#51217; &#49892;&#54665;&#46112; &#46412;&#50752; main.py&#50640; &#51032;&#54644; &#51076;&#54252;&#53944;&#46112; &#46412; &#44033;&#44033; &#45796;&#47480; &#46041;&#51089;&#51012; &#54620;&#45796;.</p><p></p><p></p><h3><strong>__name__ == "__main__"&#51032; &#54876;&#50857;</strong></h3><p>__name__ == "__main__" &#54056;&#53556;&#51008; &#45796;&#51020;&#44284; &#44057;&#51008; &#49345;&#54889;&#50640;&#49436; &#50976;&#50857;&#54616;&#44172; &#49324;&#50857;&#46108;&#45796;.</p><ol><li><p><strong>&#53580;&#49828;&#53944; &#53076;&#46300; &#51089;&#49457;</strong>: &#47784;&#46280;&#50640; &#54252;&#54632;&#46108; &#53580;&#49828;&#53944; &#53076;&#46300;&#47484; &#47784;&#46280;&#51032; &#45149; &#48512;&#48516;&#50640; &#51089;&#49457;&#54616;&#44256;, &#51060; &#53076;&#46300;&#45716; &#54644;&#45817; &#47784;&#46280;&#51060; &#51649;&#51217; &#49892;&#54665;&#46112; &#46412;&#47564; &#46041;&#51089;&#54616;&#44172; &#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>&#47784;&#46280;&#47196;&#49436;&#51032; &#49324;&#50857;&#44284; &#49828;&#53356;&#47549;&#53944;&#47196;&#49436;&#51032; &#49324;&#50857; &#44396;&#48516;</strong>: &#47784;&#46280;&#51060; &#45796;&#47480; &#53076;&#46300;&#50640; &#51032;&#54644; &#51076;&#54252;&#53944;&#46112; &#46412;&#45716; &#53945;&#51221; &#53076;&#46300;&#47484; &#49892;&#54665;&#54616;&#51648; &#50506;&#46020;&#47197; &#54624; &#49688; &#51080;&#45796;.</p></li></ol><p></p><h4><strong>&#53580;&#49828;&#53944; &#53076;&#46300; &#51089;&#49457; &#50696;&#49884;</strong></h4><pre><code>def add(a, b):
    return a + b

def multiply(a, b):
    return a * b

if __name__ == "__main__":
    # &#53580;&#49828;&#53944; &#53076;&#46300;
    print("Testing add function:")
    print(add(2, 3))  # 5
    print(add(5, 7))  # 12

    print("Testing multiply function:")
    print(multiply(2, 3))  # 6
    print(multiply(5, 7))  # 35</code></pre><h4><br><strong>&#47784;&#46280;&#47196;&#49436;&#51032; &#49324;&#50857; &#50696;&#49884;</strong></h4><p>utility.py</p><pre><code>def greet(name):
    return f"Hello, {name}!"

if __name__ == "__main__":
    print(greet("Alice"))</code></pre><p><br>app.py</p><pre><code>import utility

print(utility.greet("Bob"))</code></pre><p>&#51060; &#44221;&#50864;, app.py&#47484; &#49892;&#54665;&#54616;&#47732; utility.py&#51032; __name__ == "__main__" &#48660;&#47197; &#50504;&#51032; &#53076;&#46300;&#45716; &#49892;&#54665;&#46104;&#51648; &#50506;&#44256;, greet &#54632;&#49688;&#47564; &#51076;&#54252;&#53944;&#46104;&#50612; &#49324;&#50857;&#46108;&#45796;.<br></p>]]></content:encoded></item><item><title><![CDATA[29. Module Search Path]]></title><description><![CDATA[&#47784;&#46280; &#44160;&#49353; &#44221;&#47196;&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/29-module-search-path</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/29-module-search-path</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Tue, 18 Jun 2024 18:08:30 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!A3Sm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!A3Sm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!A3Sm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!A3Sm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!A3Sm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!A3Sm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!A3Sm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:160713,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!A3Sm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!A3Sm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!A3Sm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!A3Sm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0362c369-7e74-4435-887d-c3ab9d6dfa70_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028;&#50640;&#49436; &#47784;&#46280;&#51012; import&#54624; &#46412;, &#54028;&#51060;&#50028; &#51064;&#53552;&#54532;&#47532;&#53552;&#45716; &#47784;&#46280;&#51012; &#52286;&#44592; &#50948;&#54644; &#53945;&#51221; &#46356;&#47113;&#53664;&#47532; &#44221;&#47196;&#46308;&#51012; &#44160;&#49353;&#54620;&#45796;. &#51060; &#44160;&#49353; &#44221;&#47196;&#46308;&#51008; &#47784;&#46280; &#44160;&#49353; &#44221;&#47196;(module search path)&#46972;&#44256; &#48520;&#47532;&#47728;, &#51060;&#45716; sys &#47784;&#46280;&#51032; path &#48320;&#49688;&#50640; &#51200;&#51109;&#46104;&#50612; &#51080;&#45796;. &#51060; &#44221;&#47196;&#46308;&#51008; &#54028;&#51060;&#50028;&#51060; &#47784;&#46280;&#51012; &#52286;&#45716; &#49692;&#49436;&#47484; &#51221;&#51032;&#54620;&#45796;.</p><p></p><h3><strong>&#44592;&#48376; &#44160;&#49353; &#44221;&#47196;</strong></h3><p>&#54028;&#51060;&#50028; &#51064;&#53552;&#54532;&#47532;&#53552;&#44032; &#47784;&#46280;&#51012; &#44160;&#49353;&#54616;&#45716; &#44592;&#48376; &#44221;&#47196;&#45716; &#45796;&#51020;&#44284; &#44057;&#45796;:</p><ol><li><p><strong>&#54788;&#51116; &#46356;&#47113;&#53664;&#47532; (Current Directory)</strong>: &#49828;&#53356;&#47549;&#53944;&#44032; &#49892;&#54665;&#46104;&#45716; &#54788;&#51116; &#46356;&#47113;&#53664;&#47532;.</p></li><li><p><strong>PYTHONPATH &#54872;&#44221; &#48320;&#49688;</strong>: &#49324;&#50857;&#51088;&#44032; &#51221;&#51032;&#54620; &#46356;&#47113;&#53664;&#47532; &#47785;&#47197;. &#50868;&#50689; &#52404;&#51228;&#51032; &#54872;&#44221; &#48320;&#49688;&#47196; &#49444;&#51221;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>&#54364;&#51456; &#46972;&#51060;&#48652;&#47084;&#47532; &#46356;&#47113;&#53664;&#47532; (Standard Library Directories)</strong>: &#54028;&#51060;&#50028; &#49444;&#52824; &#46356;&#47113;&#53664;&#47532; &#45236;&#51032; &#46972;&#51060;&#48652;&#47084;&#47532; &#46356;&#47113;&#53664;&#47532;&#46308;.</p></li><li><p><strong>&#49324;&#51060;&#53944;-&#54056;&#53412;&#51648; &#46356;&#47113;&#53664;&#47532; (site-packages Directory)</strong>: &#49436;&#46300; &#54028;&#54000; &#54056;&#53412;&#51648;&#46308;&#51060; &#49444;&#52824;&#46104;&#45716; &#46356;&#47113;&#53664;&#47532;.</p></li></ol><p></p><h3><strong>sys.path</strong></h3><p>sys.path&#45716; &#47784;&#46280; &#44160;&#49353; &#44221;&#47196;&#47484; &#45812;&#44256; &#51080;&#45716; &#47532;&#49828;&#53944;&#51060;&#45796;. &#51060;&#47484; &#53685;&#54644; &#54028;&#51060;&#50028;&#51060; &#47784;&#46280;&#51012; &#44160;&#49353;&#54624; &#46412; &#52280;&#51312;&#54616;&#45716; &#44221;&#47196;&#46308;&#51012; &#54869;&#51064;&#54616;&#44256; &#49688;&#51221;&#54624; &#49688; &#51080;&#45796;.</p><h4><strong>sys.path &#54869;&#51064;</strong></h4><p>&#45796;&#51020;&#51008; sys.path&#47484; &#54869;&#51064;&#54616;&#45716; &#50696;&#51228;&#51060;&#45796;.</p><pre><code>import sys

for path in sys.path:
    print(path)</code></pre><p><br>&#51060; &#53076;&#46300;&#47484; &#49892;&#54665;&#54616;&#47732;, &#54028;&#51060;&#50028;&#51060; &#47784;&#46280;&#51012; &#44160;&#49353;&#54616;&#45716; &#44221;&#47196;&#46308;&#51060; &#52636;&#47141;&#46108;&#45796;.</p><pre><code>/path/to/current/directory
/path/to/python/lib
/path/to/python/lib/site-packages
&#8230;</code></pre><p></p><h4><strong>PYTHONPATH &#54872;&#44221; &#48320;&#49688;</strong></h4><p>PYTHONPATH &#54872;&#44221; &#48320;&#49688;&#45716; &#47784;&#46280; &#44160;&#49353; &#44221;&#47196;&#50640; &#49324;&#50857;&#51088; &#51221;&#51032; &#44221;&#47196;&#47484; &#52628;&#44032;&#54624; &#46412; &#49324;&#50857;&#46108;&#45796;. &#51060;&#47484; &#53685;&#54644; &#54028;&#51060;&#50028; &#51064;&#53552;&#54532;&#47532;&#53552;&#44032; &#47784;&#46280;&#51012; &#52286;&#51012; &#49688; &#51080;&#46020;&#47197; &#52628;&#44032;&#51201;&#51064; &#46356;&#47113;&#53664;&#47532;&#47484; &#51648;&#51221;&#54624; &#49688; &#51080;&#45796;.</p><pre><code># PYTHONPATH &#49444;&#51221; (Unix/Mac)
export PYTHONPATH=/path/to/my/modules:$PYTHONPATH



# PYTHONPATH &#49444;&#51221; (Windows)
set PYTHONPATH=C:\path\to\my\modules;%PYTHONPATH%</code></pre><h4><br><strong>sys.path &#49688;&#51221;</strong></h4><p>&#54532;&#47196;&#44536;&#47016; &#49892;&#54665; &#51473;&#50640; sys.path&#50640; &#44221;&#47196;&#47484; &#46041;&#51201;&#51004;&#47196; &#52628;&#44032;&#54624; &#49688;&#46020; &#51080;&#45796;. &#51060;&#45716; &#53945;&#51221; &#47784;&#46280;&#51060; &#53945;&#51221; &#46356;&#47113;&#53664;&#47532;&#50640; &#51080;&#51012; &#46412; &#50976;&#50857;&#54616;&#45796;.</p><pre><code>import sys

sys.path.append('/path/to/my/modules')

import mymodule</code></pre><p>&#51060; &#53076;&#46300;&#47484; &#53685;&#54644; /path/to/my/modules &#46356;&#47113;&#53664;&#47532;&#44032; sys.path&#50640; &#52628;&#44032;&#46104;&#44256;, mymodule&#51012; &#51076;&#54252;&#53944;&#54624; &#49688; &#51080;&#44172; &#46108;&#45796;.</p><p></p><h2>&#47784;&#46280; &#44160;&#49353; &#44221;&#47196;&#51032; &#49692;&#49436;</h2><p>&#47784;&#46280; &#44160;&#49353; &#44221;&#47196;&#45716; &#49692;&#49436;&#44032; &#51473;&#50836;&#54616;&#45796;. &#54028;&#51060;&#50028;&#51008; sys.path&#50640; &#45208;&#50676;&#46108; &#49692;&#49436;&#45824;&#47196; &#46356;&#47113;&#53664;&#47532;&#47484; &#44160;&#49353;&#54616;&#47728;, &#44032;&#51109; &#47676;&#51200; &#52286;&#51008; &#47784;&#46280;&#51012; &#51076;&#54252;&#53944;&#54620;&#45796;. &#46384;&#46972;&#49436;, &#46041;&#51068;&#54620; &#51060;&#47492;&#51032; &#47784;&#46280;&#51060; &#50668;&#47084; &#44221;&#47196;&#50640; &#51316;&#51116;&#54624; &#44221;&#50864;, sys.path&#51032; &#50526;&#48512;&#48516;&#50640; &#51080;&#45716; &#44221;&#47196;&#51032; &#47784;&#46280;&#51060; &#51076;&#54252;&#53944;&#46108;&#45796;.&nbsp;</p><p>&#51060;&#47084;&#54620; &#51060;&#50976; &#46412;&#47928;&#50640; &#44592;&#48376; &#47784;&#46280;&#44284; &#44057;&#51008; &#51060;&#47492;&#51004;&#47196; &#47784;&#46280; &#54028;&#51068;&#51012; &#47564;&#46308;&#47732;, &#45208;&#51473;&#50640; &#44592;&#48376; &#47784;&#46280;&#51012; import&#54616;&#47140;&#44256; &#54624;&#46412; &#51221;&#49345;&#51201;&#51004;&#47196; import&#44032; &#50504;&#46112; &#49688; &#51080;&#45796;. &#44536;&#47092; &#46412;&#45716; &#47784;&#46280; &#54028;&#51068;&#51032; &#51060;&#47492;&#51012; &#45796;&#47480; &#51060;&#47492;&#51004;&#47196; &#48320;&#44221;&#54644;&#49436; &#49324;&#50857;&#54616;&#45716; &#54200;&#51060; &#51339;&#45796;.<br></p><p></p>]]></content:encoded></item><item><title><![CDATA[28. 파이썬 모듈(Module)]]></title><description><![CDATA[&#54028;&#51060;&#50028; &#47784;&#46280;&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/28-module</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/28-module</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Tue, 18 Jun 2024 18:00:34 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3e0Q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3e0Q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3e0Q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!3e0Q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!3e0Q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!3e0Q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3e0Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:156728,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3e0Q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!3e0Q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!3e0Q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!3e0Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa71b5ec5-f3e8-4ebb-b60e-0b76ee9e6f00_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#54028;&#51060;&#50028; &#47784;&#46280;&#51008; &#54632;&#49688;, &#53364;&#47000;&#49828;, &#48320;&#49688; &#46321;&#51012; &#47784;&#50500; &#45459;&#51008; &#54028;&#51068;&#51012; &#51032;&#48120;&#54620;&#45796;. &#47784;&#46280;&#51012; &#49324;&#50857;&#54616;&#47732; &#53076;&#46300;&#47484; &#45436;&#47532;&#51201;&#51064; &#45800;&#50948;&#47196; &#45208;&#45580; &#49688; &#51080;&#50612; &#53076;&#46300;&#51032; &#51116;&#49324;&#50857;&#49457;&#44284; &#44288;&#47532;&#44032; &#50857;&#51060;&#54644;&#51652;&#45796;. &#47784;&#46280;&#51008; &#53076;&#46300;&#51032; &#44396;&#51312;&#47484; &#52404;&#44228;&#51201;&#51004;&#47196; &#47564;&#46308;&#44256;, &#45796;&#47480; &#54028;&#51068;&#50640;&#49436; &#49789;&#44172; &#48520;&#47084;&#50752; &#49324;&#50857;&#54624; &#49688; &#51080;&#44172; &#54620;&#45796;.</p><p></p><h3><strong>&#47784;&#46280; &#49373;&#49457;</strong></h3><p>&#47784;&#46280;&#51008; &#45800;&#49692;&#55176; .py &#54869;&#51109;&#51088;&#47484; &#44032;&#51652; &#54028;&#51060;&#50028; &#54028;&#51068;&#51060;&#45796;. &#50696;&#47484; &#46308;&#50612;, mymodule.py&#46972;&#45716; &#54028;&#51068;&#51012; &#49373;&#49457;&#54616;&#44256; &#45796;&#51020;&#44284; &#44057;&#51008; &#53076;&#46300;&#47484; &#51089;&#49457;&#54624; &#49688; &#51080;&#45796;.</p><pre><code>def greet(name):
    return f"Hello, {name}!"

def add(a, b):
    return a + b</code></pre><p><br>&#45796;&#47480; &#54028;&#51068;&#50640;&#49436; &#51060; &#47784;&#46280;&#51012; &#48520;&#47084;&#50752; &#49324;&#50857;&#54624; &#49688; &#51080;&#45796;. &#51060;&#47484; &#50948;&#54644; import &#47928;&#51012; &#49324;&#50857;&#54620;&#45796;.</p><pre><code>import mymodule

print(mymodule.greet("Alice"))  # Hello, Alice!
print(mymodule.add(3, 5))       # 8</code></pre><h3><br><strong>&#45796;&#50577;&#54620; import &#48169;&#49885;</strong></h3><p>&#47784;&#46280;&#51012; &#48520;&#47084;&#50724;&#45716; &#48169;&#48277;&#50640;&#45716; &#50668;&#47084; &#44032;&#51648;&#44032; &#51080;&#45796;.</p><h4>1. &#47784;&#46280; &#51204;&#52404;&#47484; import</h4><pre><code>import mymodule

print(mymodule.greet("Alice"))
print(mymodule.add(3, 5))</code></pre><p></p><h4>2. &#47784;&#46280;&#50640;&#49436; &#53945;&#51221; &#54632;&#49688;&#47564; import</h4><pre><code>from mymodule import greet, add

print(greet("Alice"))
print(add(3, 5))</code></pre><p></p><h4>3. &#47784;&#46280; &#51204;&#52404;&#47484; &#48324;&#52845;(alias)&#51004;&#47196; import</h4><pre><code>import mymodule as mm

print(mm.greet("Alice"))
print(mm.add(3, 5))</code></pre><h4><br>4. &#47784;&#46280;&#50640;&#49436; &#53945;&#51221; &#54632;&#49688;&#47564; &#48324;&#52845;&#51004;&#47196; import</h4><pre><code>from mymodule import greet as g, add as a

print(g("Alice"))
print(a(3, 5))</code></pre><h3><br><br><strong>&#54364;&#51456; &#46972;&#51060;&#48652;&#47084;&#47532; &#47784;&#46280;</strong></h3><p>&#54028;&#51060;&#50028;&#51008; &#45796;&#50577;&#54620; &#54364;&#51456; &#46972;&#51060;&#48652;&#47084;&#47532; &#47784;&#46280;&#51012; &#51228;&#44277;&#54620;&#45796;. &#51060;&#47084;&#54620; &#47784;&#46280;&#46308;&#51008; &#54028;&#51060;&#50028; &#49444;&#52824; &#49884; &#54632;&#44760; &#51228;&#44277;&#46104;&#47728;, &#48324;&#46020;&#51032; &#49444;&#52824; &#50630;&#51060; &#49324;&#50857;&#54624; &#49688; &#51080;&#45796;.</p><p></p><h4><strong>&#50696;&#51228;: math &#47784;&#46280;</strong></h4><p>math &#47784;&#46280;&#51008; &#49688;&#54617; &#44288;&#47144; &#54632;&#49688;&#50752; &#49345;&#49688;&#47484; &#51228;&#44277;&#54620;&#45796;.</p><pre><code>import math

print(math.sqrt(16))   # 4.0
print(math.pi)         # 3.141592653589793</code></pre><h4><br><strong>&#50696;&#51228;: random &#47784;&#46280;</strong></h4><p>random &#47784;&#46280;&#51008; &#45212;&#49688; &#49373;&#49457;&#51012; &#50948;&#54620; &#54632;&#49688;&#46308;&#51012; &#51228;&#44277;&#54620;&#45796;.</p><pre><code>import random

print(random.randint(1, 10))   # 1&#48512;&#53552; 10 &#49324;&#51060;&#51032; &#51076;&#51032;&#51032; &#51221;&#49688;
print(random.random())         # 0.0&#48512;&#53552; 1.0 &#49324;&#51060;&#51032; &#51076;&#51032;&#51032; &#48512;&#46041; &#49548;&#49688;&#51216; &#49688;</code></pre><h4><br><strong>&#50696;&#51228;: datetime &#47784;&#46280;</strong></h4><p>datetime &#47784;&#46280;&#51008; &#45216;&#51676;&#50752; &#49884;&#44036; &#52376;&#47532;&#47484; &#50948;&#54620; &#54632;&#49688;&#46308;&#51012; &#51228;&#44277;&#54620;&#45796;.</p><pre><code>import datetime

now = datetime.datetime.now()
print(now)                     # &#54788;&#51116; &#45216;&#51676;&#50752; &#49884;&#44036; &#52636;&#47141;
print(now.strftime("%Y-%m-%d"))# &#45216;&#51676;&#47484; &#51648;&#51221;&#54620; &#54805;&#49885;&#51004;&#47196; &#52636;&#47141;</code></pre><p><br><br></p>]]></content:encoded></item></channel></rss>