<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python on Semonan Book</title><link>https://semonan.com/en/book/programming/python/</link><description>Recent content in Python on Semonan Book</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 26 Aug 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://semonan.com/en/book/programming/python/rss.xml" rel="self" type="application/rss+xml"/><item><title>Feature</title><link>https://semonan.com/en/book/programming/python/feature/</link><pubDate>Fri, 05 Jul 2024 00:00:00 +0000</pubDate><guid>https://semonan.com/en/book/programming/python/feature/</guid><description>&lt;h1 id="basic-characteristics-of-python"&gt;Basic Characteristics of Python&lt;a class="anchor" href="#basic-characteristics-of-python"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Python is a multipurpose programming language and its characteristics are as follows.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Readable Syntax&lt;br&gt;
Python&amp;rsquo;s syntax is intuitive and clear, which enhances the readability of the code. This improves maintainability and productivity.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Dynamic Typing&lt;br&gt;
Python supports dynamic typing, which allows you to use variables without explicitly declaring their types. The type of a variable is determined at runtime.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Interpreter Language&lt;br&gt;
Python is an interpreted language, executing code line by line. This enhances debugging and development speed, but may result in slower execution speeds compared to compiled languages.&lt;/p&gt;</description></item><item><title>Data type</title><link>https://semonan.com/en/book/programming/python/data-type/</link><pubDate>Mon, 08 Jul 2024 00:00:00 +0000</pubDate><guid>https://semonan.com/en/book/programming/python/data-type/</guid><description>&lt;h1 id="python-data-types"&gt;Python Data Types&lt;a class="anchor" href="#python-data-types"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Python has various data types, each with its own unique characteristics and purposes.&lt;br&gt;
I will explain the main data types.&lt;/p&gt;
&lt;h2 id="1-numeric-types"&gt;1. Numeric Types&lt;a class="anchor" href="#1-numeric-types"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Integer (&lt;code&gt;int&lt;/code&gt;): An integer data type. It includes both positive and negative numbers and has no size limit.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;Floating Point (&lt;code&gt;float&lt;/code&gt;): A floating-point data type that includes decimal points.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;Complex Numbers (&lt;code&gt;complex&lt;/code&gt;): A complex number data type with a real part and an imaginary part.&lt;br&gt;
The imaginary part is represented using j.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="2-sequence-types"&gt;2. Sequence Types&lt;a class="anchor" href="#2-sequence-types"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;String (&lt;code&gt;str&lt;/code&gt;): A collection of characters enclosed in single quotes (&amp;rsquo;) or double quotes (&amp;quot;).&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Hello, World!&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;List (&lt;code&gt;list&lt;/code&gt;): A mutable sequence type that stores multiple values in order.&lt;br&gt;
It is defined using square brackets ([ ]) and can include different data types.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;c&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;Tuple (&lt;code&gt;tuple&lt;/code&gt;): Similar to a list but immutable.&lt;br&gt;
It is defined using parentheses (( )).&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;c&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="3-set-types"&gt;3. Set Types&lt;a class="anchor" href="#3-set-types"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Set (&lt;code&gt;set&lt;/code&gt;): A collection of unique elements.&lt;br&gt;
It is unordered and defined using curly braces ({ }).&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;frozenset: An immutable set.&lt;br&gt;
It is created using the frozenset() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;frozenset&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="4-mapping-types"&gt;4. Mapping Types&lt;a class="anchor" href="#4-mapping-types"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Dictionary (&lt;code&gt;dict&lt;/code&gt;): A collection of key-value pairs.&lt;br&gt;
It is defined using curly braces ({ }) and the keys must be unique.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Alice&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;age&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="5-other-types"&gt;5. Other Types&lt;a class="anchor" href="#5-other-types"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Boolean (&lt;code&gt;bool&lt;/code&gt;): A type that represents True and False.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;None&lt;/code&gt;: A type that represents the absence of a value.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>Casting</title><link>https://semonan.com/en/book/programming/python/casting/</link><pubDate>Mon, 08 Jul 2024 00:00:00 +0000</pubDate><guid>https://semonan.com/en/book/programming/python/casting/</guid><description>&lt;h1 id="casting-in-python-type-conversion"&gt;Casting in Python (Type Conversion)&lt;a class="anchor" href="#casting-in-python-type-conversion"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;In Python, &amp;ldquo;casting&amp;rdquo; means converting a data type to another data type.&lt;br&gt;
Since Python is a dynamically typed language, it is sometimes necessary to explicitly convert the data type of a variable.&lt;/p&gt;
&lt;h2 id="1-int---float"&gt;1. int -&amp;gt; float&lt;a class="anchor" href="#1-int---float"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In the following code, the variable &lt;code&gt;a&lt;/code&gt; is of int type.&lt;br&gt;
Since &lt;code&gt;a&lt;/code&gt; is cast to float type as &lt;code&gt;b = float(a)&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt; is of float type and its value is the floating-point number 10.0.&lt;/p&gt;</description></item><item><title>List</title><link>https://semonan.com/en/book/programming/python/list/</link><pubDate>Mon, 08 Jul 2024 00:00:00 +0000</pubDate><guid>https://semonan.com/en/book/programming/python/list/</guid><description>&lt;h1 id="python-list"&gt;Python List&lt;a class="anchor" href="#python-list"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;In Python, a list is an ordered and mutable collection of data.&lt;br&gt;
A list can contain items of various data types, and the items can be modified, added, or deleted.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s assume we need to handle 10,000 values.&lt;br&gt;
Creating 10,000 variables would be highly inefficient.&lt;br&gt;
Therefore, Python provides lists to efficiently handle multiple values.&lt;/p&gt;
&lt;h2 id="1-creating-a-list"&gt;1. Creating a List&lt;a class="anchor" href="#1-creating-a-list"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A list can be created using &lt;code&gt;[ ]&lt;/code&gt; as follows.&lt;br&gt;
You can place multiple values inside the &lt;code&gt;[ ]&lt;/code&gt; to handle them as a single list.&lt;br&gt;
In the following example, integers, floats, and strings are all included in a single list.&lt;br&gt;
An important feature is that a single list can contain multiple data types.&lt;br&gt;
Each value contained in a list is called an element.&lt;/p&gt;</description></item><item><title>Read/Write a file</title><link>https://semonan.com/en/book/programming/python/file-io/</link><pubDate>Mon, 26 Aug 2024 00:00:00 +0000</pubDate><guid>https://semonan.com/en/book/programming/python/file-io/</guid><description>&lt;h1 id="how-to-read-and-write-files-in-python"&gt;How to Read and Write Files in Python&lt;a class="anchor" href="#how-to-read-and-write-files-in-python"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;This guide explains how to read and write files in Python.&lt;br&gt;
It is organized around the most commonly used example codes.&lt;/p&gt;
&lt;h2 id="1-reading-a-text-file---reading-the-entire-file"&gt;1. Reading a Text File - Reading the Entire File&lt;a class="anchor" href="#1-reading-a-text-file---reading-the-entire-file"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;You can create a file stream using &lt;code&gt;open(&amp;quot;abcd.txt&amp;quot;, &amp;quot;r&amp;quot;)&lt;/code&gt; and read the entire file at once with &lt;code&gt;.read()&lt;/code&gt;.&lt;br&gt;
(Creating a file stream means establishing a link to access the file.)&lt;br&gt;
Here, &lt;code&gt;&amp;quot;abcd.txt&amp;quot;&lt;/code&gt; refers to the full path of the file to be read, and you can use either an absolute path or a relative path.&lt;br&gt;
&lt;code&gt;&amp;quot;r&amp;quot;&lt;/code&gt; stands for read mode.&lt;/p&gt;</description></item></channel></rss>