<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="lt">
	<id>https://wiki.pitonas.lt/index.php?action=history&amp;feed=atom&amp;title=Knyga%2FModuli%C5%B3_naudojimas</id>
	<title>Knyga/Modulių naudojimas - Versijų istorija</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pitonas.lt/index.php?action=history&amp;feed=atom&amp;title=Knyga%2FModuli%C5%B3_naudojimas"/>
	<link rel="alternate" type="text/html" href="https://wiki.pitonas.lt/index.php?title=Knyga/Moduli%C5%B3_naudojimas&amp;action=history"/>
	<updated>2026-10-07T04:34:01Z</updated>
	<subtitle>Šio puslapio versijų istorija projekte</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.pitonas.lt/index.php?title=Knyga/Moduli%C5%B3_naudojimas&amp;diff=690&amp;oldid=prev</id>
		<title>ArturasNik 13:18, 15 rugsėjo 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.pitonas.lt/index.php?title=Knyga/Moduli%C5%B3_naudojimas&amp;diff=690&amp;oldid=prev"/>
		<updated>2025-09-15T13:18:40Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;lt&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Ankstesnė versija&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;16:18, 15 rugsėjo 2025 versija&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;1 eilutė:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;1 eilutė:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{navigation |previous=Rekursinės funkcijos |next=Siekiant tobulumo}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{navigation |previous=Rekursinės funkcijos |next=Siekiant tobulumo}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=== Ką išmoksi šiame skyriuje? ===&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* Kas yra Python modulis&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* Kaip importuoti standartinius modulius (&amp;lt;code&amp;gt;calendar&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt;)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* Kaip naudoti &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; ir &amp;lt;code&amp;gt;from ... import ...&amp;lt;/code&amp;gt; būdus&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* Kaip Python ieško modulių&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* Kaip susikurti savo modulį&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* Kaip naudoti konstrukciją &amp;lt;code&amp;gt;if __name__ == &#039;__main__&#039;&amp;lt;/code&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* Kaip įdiegti papildomus modulius naudojant &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Modulių naudojimas ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Modulių naudojimas ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Štai šio skyriaus pratimas. Failas, kuriame yra ši užduotis, geriausia būtų pavadinti kalendorius.py, kad nesimaišytų su importuojamu calendar.py moduliu. Modulis iš tiesų yra failas su priesaga .py, kuriame yra papildomų funkcijų rinkinys, kurį &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;norite &lt;/del&gt;įtraukti ir naudoti savo programoje. Eilutė &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt; iš tikrųjų ieško failo pavadinimu calendar.py ir jį su jo funkcijomis įtraukia į savo kodą, kad &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;galėtume &lt;/del&gt;naudoti &amp;lt;code&amp;gt;prcal&amp;lt;/code&amp;gt; funkciją, kuri atspausdins visų metų kalendorių. Jei failas būtų pavadintas calendar.py ir matytų &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt;, jis bandytų skaityti pats save, ir kodas tada neveiktų tinkamai.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Štai šio skyriaus pratimas. Failas, kuriame yra ši užduotis, geriausia būtų pavadinti kalendorius.py, kad nesimaišytų su importuojamu calendar.py moduliu. Modulis iš tiesų yra failas su priesaga .py, kuriame yra papildomų funkcijų rinkinys, kurį &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;nori &lt;/ins&gt;įtraukti ir naudoti savo programoje. Eilutė &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt; iš tikrųjų ieško failo pavadinimu calendar.py ir jį su jo funkcijomis įtraukia į savo kodą, kad &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;galėtum &lt;/ins&gt;naudoti &amp;lt;code&amp;gt;prcal&amp;lt;/code&amp;gt; funkciją, kuri atspausdins visų metų kalendorių. Jei failas būtų pavadintas calendar.py ir matytų &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt;, jis bandytų skaityti pats save, ir kodas tada neveiktų tinkamai.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l26&quot;&gt;26 eilutė:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;35 eilutė:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  29 30 31                  26 27 28                  26 27 28 29 30 31         &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  29 30 31                  26 27 28                  26 27 28 29 30 31         &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;(Aš praleidau kai kurias išvesties dalis, bet manau, kad principas aiškus.) Taigi, ką daro programa? Pirma eilutė &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt; naudoja naują komandą &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt;.  Komanda &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; įkelia modulį (šiuo atveju &amp;lt;code&amp;gt;calendar&amp;lt;/code&amp;gt; modulį).  Norint pamatyti standartiniuose moduliuose esančias funkcijas, ieškok Python&#039;o bibliotekos nuorodos (jei atsisiuntei biblioteką) arba eik į http://docs.python.org/3/library/.  Jei pažvelsi į kalendoriaus modulio dokumentaciją, jame yra funkcija, vadinama &amp;lt;code&amp;gt;prcal&amp;lt;/code&amp;gt;, kuri spausdina metų kalendorių. Komanda &amp;lt;code&amp;gt;calendar.prcal(metai)&amp;lt;/code&amp;gt; naudoja šią funkciją. Apskritai, norint naudoti modulį, reikia naudoti raktažodį &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; ir kartu panaudoti &amp;lt;code&amp;gt;modulio_pavadinimas.&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;function&lt;/del&gt;&amp;lt;/code&amp;gt;, kreipiantis į funkcijas esančias modulyje. Yra ir kitas būdas parašyti analogišką programą:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;(Aš praleidau kai kurias išvesties dalis, bet manau, kad principas aiškus.) Taigi, ką daro programa? Pirma eilutė &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt; naudoja naują komandą &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt;.  Komanda &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; įkelia modulį (šiuo atveju &amp;lt;code&amp;gt;calendar&amp;lt;/code&amp;gt; modulį).  Norint pamatyti standartiniuose moduliuose esančias funkcijas, ieškok Python&#039;o bibliotekos nuorodos (jei atsisiuntei biblioteką) arba eik į http://docs.python.org/3/library/.  Jei pažvelsi į kalendoriaus modulio dokumentaciją, jame yra funkcija, vadinama &amp;lt;code&amp;gt;prcal&amp;lt;/code&amp;gt;, kuri spausdina metų kalendorių. Komanda &amp;lt;code&amp;gt;calendar.prcal(metai)&amp;lt;/code&amp;gt; naudoja šią funkciją. Apskritai, norint naudoti modulį, reikia naudoti raktažodį &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; ir kartu panaudoti &amp;lt;code&amp;gt;modulio_pavadinimas.&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;funkcija&lt;/ins&gt;&amp;lt;/code&amp;gt;, kreipiantis į funkcijas esančias modulyje. Yra ir kitas būdas parašyti analogišką programą:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l62&quot;&gt;62 eilutė:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;71 eilutė:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Kadangi išvestis yra begalinė, todėl ją atšaukiu (kitu atveju, išvestis tęstųsi bent jau tol, kol būtų paspaustas Ctrl+C). Programa atlieka nesibaigiantį ciklą (&amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt; yra visada tiesa, taigi &amp;lt;code&amp;gt;while True:&amp;lt;/code&amp;gt; vykdoma amžinai). &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Kiekvieną &lt;/del&gt;kartą patikrina, ar laikas nepasikeitė, ir išspausdina, jei pasikeitė. Atkreipk dėmesį, kaip naudojami keli funkcijų pavadinimai po &#039;&#039;import&#039;&#039; sakinyje &amp;lt;code&amp;gt;from time import time, ctime&amp;lt;/code&amp;gt;.   &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Kadangi išvestis yra begalinė, todėl ją atšaukiu (kitu atveju, išvestis tęstųsi bent jau tol, kol būtų paspaustas Ctrl+C). Programa atlieka nesibaigiantį ciklą (&amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt; yra visada tiesa, taigi &amp;lt;code&amp;gt;while True:&amp;lt;/code&amp;gt; vykdoma amžinai). &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Programa kiekvieną &lt;/ins&gt;kartą patikrina, ar laikas nepasikeitė, ir išspausdina, jei pasikeitė. Atkreipk dėmesį, kaip naudojami keli funkcijų pavadinimai po &#039;&#039;import&#039;&#039; sakinyje &amp;lt;code&amp;gt;from time import time, ctime&amp;lt;/code&amp;gt;.   &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Python&#039;o bibliotekoje yra daug naudingų funkcijų. Šios funkcijos suteikia &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tavo &lt;/del&gt;programoms daugiau galimybių ir daugelis jų gali supaprastinti programavimą Python&#039;u.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Python&#039;o bibliotekoje yra daug naudingų funkcijų. Šios funkcijos suteikia &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tavo &lt;/ins&gt;programoms daugiau galimybių ir daugelis jų gali supaprastinti programavimą Python&#039;u.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Pratimai ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Pratimai ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l92&quot;&gt;92 eilutė:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;101 eilutė:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Kiti moduliai==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Kiti moduliai==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Kartais Tu gali norėti naudoti Python&#039;o modulį, kurio nėra &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;standatinėje &lt;/del&gt;Python versijoje. Tu gali juos importuoti, tačiau pirmiau turėsi juos įsidiegti savo kompiuterį.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Kartais Tu gali norėti naudoti Python&#039;o modulį, kurio nėra &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;standartinėje &lt;/ins&gt;Python versijoje. Tu gali juos importuoti, tačiau pirmiau turėsi juos įsidiegti savo kompiuterį.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Kuriant savo modulį===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===Kuriant savo modulį===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Kai Python&#039;as skaito importavimo komandą, jis pirmiausia patikrina &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tavo &lt;/del&gt;katalogo failus, po to svetainės paketus ir iš anksto įdiegtus modulius. Norint sukurti savo modulį, tiesiog sukurk .py failą dabartiniame kataloge ir parašyk komandą:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Kai Python&#039;as skaito importavimo komandą, jis pirmiausia patikrina &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tavo &lt;/ins&gt;katalogo failus, po to svetainės paketus ir iš anksto įdiegtus modulius. Norint sukurti savo modulį, tiesiog sukurk .py failą dabartiniame kataloge ir parašyk komandą:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import modulis&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import modulis&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Taip bus bandoma importuoti failą modulis.py iš dabartinio katalogo, o jei modulis bus nerastas, iš svetainių paketų ir iš anksto paruoštų modulių. Pakeitus modulį į &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tavo &lt;/del&gt;sukurto .py failo pavadinimą, jis bus importuotas.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Taip bus bandoma importuoti failą modulis.py iš dabartinio katalogo, o jei modulis bus nerastas, iš svetainių paketų ir iš anksto paruoštų modulių. Pakeitus modulį į &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;tavo &lt;/ins&gt;sukurto .py failo pavadinimą, jis bus importuotas&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tačiau kai jis importuoja modulį, jis iš esmės vykdo failo kodą kaip programą, todėl bet koks jame esantis kodas bus paleistas. Patartina visą kodą sugrupuoti į funkcijas&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Tačiau kai jis importuoja modulį, jis iš esmės paleidžia failą kaip programą, todėl bet koks jame esantis kodas bus paleistas. Patartina visą kodą sugrupuoti į funkcijas.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===__name__ == __main__ triukas===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=&lt;/del&gt;===__name__ == __main__ triukas&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=&lt;/del&gt;===&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Python&amp;#039;e kintamasis &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; suteiks dabartinį programos pavadinimą. Jei importuojamas modulis spausdina &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; kintamąjį, tada jis atspausdins modulio pavadinimą. Jei dabartinis failas spausdina &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; kintamąjį, jis atspausdins &amp;lt;code&amp;gt;__main__&amp;lt;/code&amp;gt;, tam, kad parodytų, kad tai yra pagrindinė programa.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Python&amp;#039;e kintamasis &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; suteiks dabartinį programos pavadinimą. Jei importuojamas modulis spausdina &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; kintamąjį, tada jis atspausdins modulio pavadinimą. Jei dabartinis failas spausdina &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; kintamąjį, jis atspausdins &amp;lt;code&amp;gt;__main__&amp;lt;/code&amp;gt;, tam, kad parodytų, kad tai yra pagrindinė programa.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Sąlyginis sakinys patikrina vardo kintamąjį ir paleidžia kodą, jei programa yra pagrindinė. Taip ji gali apeiti netyčinio paleidimo problemą, sukuriamą importuojant modulį. Tarkime, kad turi failą, kuriame veikia tam tikras kodas. Jis taip pat turi funkciją, kurią nori naudoti kitoje programoje. Tačiau nori tik funkcijos, esančios faile, o ne paleisti vykdyti kodą. Parašius žemiau pateiktą kodą, programa bus vykdoma tik tuo atveju, jei bus spustelėtas ar paleistas vykdyti esamas failas, o ne importuotas.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Sąlyginis sakinys patikrina vardo kintamąjį ir paleidžia kodą, jei programa yra pagrindinė. Taip ji gali apeiti netyčinio paleidimo problemą, sukuriamą importuojant modulį. Tarkime, kad turi failą, kuriame veikia tam tikras kodas. Jis taip pat turi funkciją, kurią nori naudoti kitoje programoje. Tačiau nori tik funkcijos, esančios faile, o ne paleisti vykdyti kodą. Parašius žemiau pateiktą kodą, programa bus vykdoma tik tuo atveju, jei bus spustelėtas ar paleistas vykdyti esamas failas, o ne importuotas.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;if __name__ == &amp;#039;__main__&amp;#039;:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;if __name__ == &amp;#039;__main__&amp;#039;:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     pass&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     pass&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Šiuo atveju, jei failas paleidžiamas, bet neimportuojamas, jis vykdys komandą pass. &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Pass komandą galite &lt;/del&gt;pakeisti kodu, kurį &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;norite &lt;/del&gt;paleisti, kai jis nėra importuotas. Tiesiog nepamiršk to kodo parašyti.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Šiuo atveju, jei failas paleidžiamas, bet neimportuojamas, jis vykdys komandą &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;&lt;/ins&gt;pass&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/code&amp;gt;&lt;/ins&gt;. &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Komandą &amp;lt;code&amp;gt;pass&amp;lt;/code&amp;gt; gali &lt;/ins&gt;pakeisti kodu, kurį &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;nori &lt;/ins&gt;paleisti, kai jis nėra importuotas. Tiesiog nepamiršk to kodo parašyti.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===pip modulis===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;===pip modulis===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Pip modulis yra įdiegtas kartu su Python&amp;#039;u ir veikia kaip modulio atsisiuntėjas/tvarkytojas. Kitus modulius galima atsisiųsti iš interneto naudojant pip.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Pip modulis yra įdiegtas kartu su Python&amp;#039;u ir veikia kaip modulio atsisiuntėjas/tvarkytojas. Kitus modulius galima atsisiųsti iš interneto naudojant pip.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Pip modulis &lt;/del&gt;nenaudojamas Python&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;o &lt;/del&gt;interpretatoriuje, bet yra vykdomas per komandinę eilutę. Norint jį naudoti, atidaryk komandų eilutės programėlę (Windows tai yra komandinė eilutė, Mac/Linux – terminalas) ir įvesk šį kodą:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; &lt;/ins&gt;nenaudojamas Python interpretatoriuje, bet yra vykdomas per komandinę eilutę. Norint jį naudoti, atidaryk komandų eilutės programėlę (Windows tai yra komandinė eilutė, Mac/Linux – terminalas) ir įvesk šį kodą:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;py3 -m pip install modulis&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;py3 -m pip install modulis&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>ArturasNik</name></author>
	</entry>
	<entry>
		<id>https://wiki.pitonas.lt/index.php?title=Knyga/Moduli%C5%B3_naudojimas&amp;diff=520&amp;oldid=prev</id>
		<title>ArturasNik: Naujas puslapis: {{navigation |previous=Rekursinės funkcijos |next=Siekiant tobulumo}}  === Modulių naudojimas ===  Štai šio skyriaus pratimas. Failas, kuriame yra ši užduotis, geriausia būtų pavadinti kalendorius.py, kad nesimaišytų su importuojamu calendar.py moduliu. Modulis iš tiesų yra failas su priesaga .py, kuriame yra papildomų funkcijų rinkinys, kurį norite įtraukti ir naudoti savo programoje. Eilutė &lt;code&gt;import calendar&lt;/code&gt; iš tikrųjų ieško failo pavadinim...</title>
		<link rel="alternate" type="text/html" href="https://wiki.pitonas.lt/index.php?title=Knyga/Moduli%C5%B3_naudojimas&amp;diff=520&amp;oldid=prev"/>
		<updated>2024-10-10T10:25:16Z</updated>

		<summary type="html">&lt;p&gt;Naujas puslapis: {{navigation |previous=Rekursinės funkcijos |next=Siekiant tobulumo}}  === Modulių naudojimas ===  Štai šio skyriaus pratimas. Failas, kuriame yra ši užduotis, geriausia būtų pavadinti kalendorius.py, kad nesimaišytų su importuojamu calendar.py moduliu. Modulis iš tiesų yra failas su priesaga .py, kuriame yra papildomų funkcijų rinkinys, kurį norite įtraukti ir naudoti savo programoje. Eilutė &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt; iš tikrųjų ieško failo pavadinim...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Naujas puslapis&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{navigation |previous=Rekursinės funkcijos |next=Siekiant tobulumo}}&lt;br /&gt;
&lt;br /&gt;
=== Modulių naudojimas ===&lt;br /&gt;
&lt;br /&gt;
Štai šio skyriaus pratimas. Failas, kuriame yra ši užduotis, geriausia būtų pavadinti kalendorius.py, kad nesimaišytų su importuojamu calendar.py moduliu. Modulis iš tiesų yra failas su priesaga .py, kuriame yra papildomų funkcijų rinkinys, kurį norite įtraukti ir naudoti savo programoje. Eilutė &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt; iš tikrųjų ieško failo pavadinimu calendar.py ir jį su jo funkcijomis įtraukia į savo kodą, kad galėtume naudoti &amp;lt;code&amp;gt;prcal&amp;lt;/code&amp;gt; funkciją, kuri atspausdins visų metų kalendorių. Jei failas būtų pavadintas calendar.py ir matytų &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt;, jis bandytų skaityti pats save, ir kodas tada neveiktų tinkamai.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import calendar&lt;br /&gt;
metai = int(input(&amp;quot;Įvesk metų skaičių: &amp;quot;))&lt;br /&gt;
calendar.prcal(metai)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ir čia yra gautos programos išvestis:&lt;br /&gt;
&lt;br /&gt;
 Įvesk metų skaičių: 2001&lt;br /&gt;
 &lt;br /&gt;
                                  2001                                  &lt;br /&gt;
 &lt;br /&gt;
        Sausis                  Vasaris                    Kovas      &lt;br /&gt;
 &lt;br /&gt;
 Pr An Tr Ke Pe Še Se      Pr An Tr Ke Pe Še Se      Pr An Tr Ke Pe Še Se&lt;br /&gt;
 1  2  3  4  5  6  7                1  2  3  4                1  2  3  4     &lt;br /&gt;
 8  9 10 11 12 13 14       5  6  7  8  9 10 11       5  6  7  8  9 10 11&lt;br /&gt;
 15 16 17 18 19 20 21      12 13 14 15 16 17 18      12 13 14 15 16 17 18     &lt;br /&gt;
 22 23 24 25 26 27 28      19 20 21 22 23 24 25      19 20 21 22 23 24 25     &lt;br /&gt;
 29 30 31                  26 27 28                  26 27 28 29 30 31        &lt;br /&gt;
&lt;br /&gt;
(Aš praleidau kai kurias išvesties dalis, bet manau, kad principas aiškus.) Taigi, ką daro programa? Pirma eilutė &amp;lt;code&amp;gt;import calendar&amp;lt;/code&amp;gt; naudoja naują komandą &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt;.  Komanda &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; įkelia modulį (šiuo atveju &amp;lt;code&amp;gt;calendar&amp;lt;/code&amp;gt; modulį).  Norint pamatyti standartiniuose moduliuose esančias funkcijas, ieškok Python&amp;#039;o bibliotekos nuorodos (jei atsisiuntei biblioteką) arba eik į http://docs.python.org/3/library/.  Jei pažvelsi į kalendoriaus modulio dokumentaciją, jame yra funkcija, vadinama &amp;lt;code&amp;gt;prcal&amp;lt;/code&amp;gt;, kuri spausdina metų kalendorių. Komanda &amp;lt;code&amp;gt;calendar.prcal(metai)&amp;lt;/code&amp;gt; naudoja šią funkciją. Apskritai, norint naudoti modulį, reikia naudoti raktažodį &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt; ir kartu panaudoti &amp;lt;code&amp;gt;modulio_pavadinimas.function&amp;lt;/code&amp;gt;, kreipiantis į funkcijas esančias modulyje. Yra ir kitas būdas parašyti analogišką programą:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from calendar import prcal&lt;br /&gt;
&lt;br /&gt;
metai = int(input(&amp;quot;Įveskite metų skaičių: &amp;quot;))&lt;br /&gt;
prcal(metai)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Šis variantas importuoja konkrečią funkciją iš modulio. &lt;br /&gt;
Panagrinėkime dar vieną programą, kuri naudoja Python&amp;#039;o biblioteką (pavadink ją clock.py) (tuo pačiu metu paspausk Ctrl ir klavišą c, kad nutrauktum darbą):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from time import time, ctime&lt;br /&gt;
&lt;br /&gt;
ankstesnis_laikas = &amp;quot;&amp;quot;&lt;br /&gt;
while True:&lt;br /&gt;
    laikas = ctime(time())&lt;br /&gt;
    if ankstesnis_laikas != laikas:&lt;br /&gt;
        print(&amp;quot;Laikas:&amp;quot;, ctime(time()))&lt;br /&gt;
        ankstesnis_laikas = laikas&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Dalis išvesties yra:&lt;br /&gt;
&lt;br /&gt;
 Laikas: Tue Dec 21 13:14:20 2021&lt;br /&gt;
 Laikas: Tue Dec 21 13:14:21 2021&lt;br /&gt;
 Laikas: Tue Dec 21 13:14:22 2021&lt;br /&gt;
 Laikas: Tue Dec 21 13:14:23 2021&lt;br /&gt;
 &lt;br /&gt;
 Traceback (most recent call last):&lt;br /&gt;
   File &amp;quot;laikas.py&amp;quot;, line 5, in &amp;lt;module&amp;gt;&lt;br /&gt;
     laikas = ctime(time())&lt;br /&gt;
 KeyboardInterrupt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kadangi išvestis yra begalinė, todėl ją atšaukiu (kitu atveju, išvestis tęstųsi bent jau tol, kol būtų paspaustas Ctrl+C). Programa atlieka nesibaigiantį ciklą (&amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt; yra visada tiesa, taigi &amp;lt;code&amp;gt;while True:&amp;lt;/code&amp;gt; vykdoma amžinai). Kiekvieną kartą patikrina, ar laikas nepasikeitė, ir išspausdina, jei pasikeitė. Atkreipk dėmesį, kaip naudojami keli funkcijų pavadinimai po &amp;#039;&amp;#039;import&amp;#039;&amp;#039; sakinyje &amp;lt;code&amp;gt;from time import time, ctime&amp;lt;/code&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
Python&amp;#039;o bibliotekoje yra daug naudingų funkcijų. Šios funkcijos suteikia Tavo programoms daugiau galimybių ir daugelis jų gali supaprastinti programavimą Python&amp;#039;u.&lt;br /&gt;
&lt;br /&gt;
=== Pratimai ===&lt;br /&gt;
Perrašyk &amp;lt;code&amp;gt;daugiau_maziau.py&amp;lt;/code&amp;gt; programą iš skyriaus [[Vadovėlis/Pasirinkimai#Pavyzdžiai|Pasirinkimai]], kad naudotų atsitiktinį sveikąjį skaičių nuo 0 iki 99, o ne įkoduotą 7. Naudok &amp;lt;code&amp;gt;random&amp;lt;/code&amp;gt; modulį ir &amp;lt;code&amp;gt;randint&amp;lt;/code&amp;gt; funkciją.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;mw-collapsible mw-collapsed wikitable&amp;quot;&lt;br /&gt;
! colspan=2 | Sprendimas &amp;amp;nbsp;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from random import randint&lt;br /&gt;
&lt;br /&gt;
skaičius = randint(0, 99)&lt;br /&gt;
spėjimas = -1&lt;br /&gt;
while spėjimas != skaičius: &lt;br /&gt;
    spėjimas = int(input (&amp;quot;Atspėk skaičių: &amp;quot;))&lt;br /&gt;
    if spėjimas &amp;gt; skaičius:&lt;br /&gt;
        print(&amp;quot;Per didelis&amp;quot;)&lt;br /&gt;
    elif spėjimas &amp;lt; skaičius:&lt;br /&gt;
        print(&amp;quot;Per mažas&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
print(&amp;quot;Būtent tas&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Kiti moduliai==&lt;br /&gt;
Kartais Tu gali norėti naudoti Python&amp;#039;o modulį, kurio nėra standatinėje Python versijoje. Tu gali juos importuoti, tačiau pirmiau turėsi juos įsidiegti savo kompiuterį.&lt;br /&gt;
&lt;br /&gt;
===Kuriant savo modulį===&lt;br /&gt;
Kai Python&amp;#039;as skaito importavimo komandą, jis pirmiausia patikrina Tavo katalogo failus, po to svetainės paketus ir iš anksto įdiegtus modulius. Norint sukurti savo modulį, tiesiog sukurk .py failą dabartiniame kataloge ir parašyk komandą:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;br /&gt;
import modulis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taip bus bandoma importuoti failą modulis.py iš dabartinio katalogo, o jei modulis bus nerastas, iš svetainių paketų ir iš anksto paruoštų modulių. Pakeitus modulį į Tavo sukurto .py failo pavadinimą, jis bus importuotas.&lt;br /&gt;
&lt;br /&gt;
Tačiau kai jis importuoja modulį, jis iš esmės paleidžia failą kaip programą, todėl bet koks jame esantis kodas bus paleistas. Patartina visą kodą sugrupuoti į funkcijas.&lt;br /&gt;
====__name__ == __main__ triukas====&lt;br /&gt;
Python&amp;#039;e kintamasis &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; suteiks dabartinį programos pavadinimą. Jei importuojamas modulis spausdina &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; kintamąjį, tada jis atspausdins modulio pavadinimą. Jei dabartinis failas spausdina &amp;lt;code&amp;gt;__name__&amp;lt;/code&amp;gt; kintamąjį, jis atspausdins &amp;lt;code&amp;gt;__main__&amp;lt;/code&amp;gt;, tam, kad parodytų, kad tai yra pagrindinė programa.&lt;br /&gt;
&lt;br /&gt;
Sąlyginis sakinys patikrina vardo kintamąjį ir paleidžia kodą, jei programa yra pagrindinė. Taip ji gali apeiti netyčinio paleidimo problemą, sukuriamą importuojant modulį. Tarkime, kad turi failą, kuriame veikia tam tikras kodas. Jis taip pat turi funkciją, kurią nori naudoti kitoje programoje. Tačiau nori tik funkcijos, esančios faile, o ne paleisti vykdyti kodą. Parašius žemiau pateiktą kodą, programa bus vykdoma tik tuo atveju, jei bus spustelėtas ar paleistas vykdyti esamas failas, o ne importuotas.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot;&amp;gt;&lt;br /&gt;
if __name__ == &amp;#039;__main__&amp;#039;:&lt;br /&gt;
    pass&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Šiuo atveju, jei failas paleidžiamas, bet neimportuojamas, jis vykdys komandą pass. Pass komandą galite pakeisti kodu, kurį norite paleisti, kai jis nėra importuotas. Tiesiog nepamiršk to kodo parašyti.&lt;br /&gt;
===pip modulis===&lt;br /&gt;
Pip modulis yra įdiegtas kartu su Python&amp;#039;u ir veikia kaip modulio atsisiuntėjas/tvarkytojas. Kitus modulius galima atsisiųsti iš interneto naudojant pip.&lt;br /&gt;
&lt;br /&gt;
Pip modulis nenaudojamas Python&amp;#039;o interpretatoriuje, bet yra vykdomas per komandinę eilutę. Norint jį naudoti, atidaryk komandų eilutės programėlę (Windows tai yra komandinė eilutė, Mac/Linux – terminalas) ir įvesk šį kodą:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
py3 -m pip install modulis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
arba alternatyvus kodas&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pip install modulis&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ši komandų eilutė bandys atsisiųsti ir įdiegti modulį iš vartotojo pateiktos Python&amp;#039;o modulių duomenų bazės. Modulis gali būti pakeistas į konkretaus modulio pavadinimą.&lt;br /&gt;
&lt;br /&gt;
{{navigation |previous=Rekursinės funkcijos |next=Siekiant tobulumo}}&lt;br /&gt;
[[Category:Knyga]]&lt;/div&gt;</summary>
		<author><name>ArturasNik</name></author>
	</entry>
</feed>