<?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[Confessions of a Code Addict: The Pursuit of Programming]]></title><description><![CDATA[Articles for a beginner level programmer covering everything about programming from the very basics using the Python programming language.]]></description><link>https://blog.codingconfessions.com/s/the-pursuit-of-programming</link><image><url>https://substackcdn.com/image/fetch/$s_!lstI!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe440a724-cff0-437a-8361-d7699406ac22_500x500.png</url><title>Confessions of a Code Addict: The Pursuit of Programming</title><link>https://blog.codingconfessions.com/s/the-pursuit-of-programming</link></image><generator>Substack</generator><lastBuildDate>Thu, 14 May 2026 11:18:40 GMT</lastBuildDate><atom:link href="https://blog.codingconfessions.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Abhinav Upadhyay]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[codeconfessions@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[codeconfessions@substack.com]]></itunes:email><itunes:name><![CDATA[Abhinav Upadhyay]]></itunes:name></itunes:owner><itunes:author><![CDATA[Abhinav Upadhyay]]></itunes:author><googleplay:owner><![CDATA[codeconfessions@substack.com]]></googleplay:owner><googleplay:email><![CDATA[codeconfessions@substack.com]]></googleplay:email><googleplay:author><![CDATA[Abhinav Upadhyay]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[The Pursuit of Programming #2: Variables, Operators and Data Types]]></title><description><![CDATA[Building Blocks of Programming: Unravelling Variables, Operators, and Data Types]]></description><link>https://blog.codingconfessions.com/p/the-pursuit-of-programming-2</link><guid isPermaLink="false">https://blog.codingconfessions.com/p/the-pursuit-of-programming-2</guid><dc:creator><![CDATA[Abhinav Upadhyay]]></dc:creator><pubDate>Fri, 26 May 2023 06:31:07 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3O0i!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the <a href="https://codeconfessions.substack.com/p/the-pursuit-of-programming-1">first post</a> of the Pursuit of Programming series, we covered setting up our Python development environment and configuring Visual Studio Code as our preferred editor for writing Python code. In this second post, we will introduce the concept of variables, data types, and operators. Let's dive in!</p><p>(This post is a bit long, if you are reading it in your email I would encourage you to read it online or in the Substack app.)</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.codingconfessions.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Confessions of a Code Addict! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h1>Variables</h1><p>Variables are fundamental building blocks for creating programs. A variable is a name with an associated value, somewhat similar to variables used in algebra. For example, we can create a variable <code>x</code> with the value 10 by writing <code>x = 10</code> in Python. Here, <code>x</code> is the variable name, <code>=</code> is the assignment operator, and <code>10</code> is the value assigned to <code>x</code>. From this point on, whenever we write <code>x</code> in our program, it will refer to its value <code>10</code>.</p><p>We can also change the value of a variable. In a Python shell let&#8217;s try the following examples (refer to <a href="https://codeconfessions.substack.com/i/119819378/starting-python-shell-on-windows">this</a> on how to start the Python shell):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3O0i!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3O0i!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png 424w, https://substackcdn.com/image/fetch/$s_!3O0i!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png 848w, https://substackcdn.com/image/fetch/$s_!3O0i!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png 1272w, https://substackcdn.com/image/fetch/$s_!3O0i!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3O0i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png" width="600" height="610" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/03827bff-1b43-4325-bd23-67e89e678cff_600x610.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:610,&quot;width&quot;:600,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:136552,&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_!3O0i!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png 424w, https://substackcdn.com/image/fetch/$s_!3O0i!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png 848w, https://substackcdn.com/image/fetch/$s_!3O0i!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.png 1272w, https://substackcdn.com/image/fetch/$s_!3O0i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F03827bff-1b43-4325-bd23-67e89e678cff_600x610.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>In this example, we first created a variable <code>x</code> with the value <code>10</code> which is displayed when we print <code>x</code>. Next on line 4, we update <code>x</code> to the value <code>12</code>, and when we print it again, we can see its updated value.</p><p>The purpose of variables is to represent data in our programs. Suppose we intend to write a program that calculates simple interest using the formula shown below.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;I = \\text{principal} \\times \\text{interest rate} \\times \\text{time}\n&quot;,&quot;id&quot;:&quot;TSUBBIZIPJ&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Our program would need three variables, one for principal, one for interest rate and one for time. We could also create a fourth variable which will store the value of the computed interest. Based on this, our program to calculate simple interest could look like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OE2F!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OE2F!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png 424w, https://substackcdn.com/image/fetch/$s_!OE2F!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png 848w, https://substackcdn.com/image/fetch/$s_!OE2F!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png 1272w, https://substackcdn.com/image/fetch/$s_!OE2F!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OE2F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png" width="836" height="706" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:706,&quot;width&quot;:836,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:156783,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!OE2F!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png 424w, https://substackcdn.com/image/fetch/$s_!OE2F!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png 848w, https://substackcdn.com/image/fetch/$s_!OE2F!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png 1272w, https://substackcdn.com/image/fetch/$s_!OE2F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fded154c0-ec1e-46ea-9194-1d124b05d39d_836x706.png 1456w" sizes="100vw" loading="lazy"></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>On line 1-3 we have created variables for principal, interest rate and time period.</p><p>On line 4 we are creating the variable for <code>interest</code> whose value is the product of the variables: <code>principal</code>, <code>interest</code> and <code>time</code>. Since at the time of evaluating this expression, Python knows the values of those variables, it can immediately calculate the product as <code>100 * 5 * 1</code> and assign the result to interest. This means that the value of the interest variable upon assignment on line 4 becomes <code>500</code>.</p><h2>Naming Convention for Variables in Python</h2><p>Now that we know how to create a variable in Python, let's discuss the rules for naming them. Each programming language has certain rules for naming variables; for Python, these rules are as follows:</p><ul><li><p><strong>Valid Characters</strong>: Python allows all alphabets (uppercase and lowercase), digits, and underscores (<code>_</code>) in a variable name. A name must start with a letter or an underscore but cannot start with a digit.</p></li><li><p><strong>Case-sensitive</strong>: Variable names are case-sensitive. For example, the variables <code>x</code> and <code>X</code> are different.</p></li><li><p><strong>Reserved Keywords</strong>: We cannot use certain names because they are reserved keywords in Python. For example, keywords like <code>for</code>, <code>if</code>, <code>elif</code>, <code>def</code>, etc. cannot be used. Check this <a href="https://docs.python.org/3/reference/lexical_analysis.html#keywords">link</a> for the complete list of reserved keywords in Python.</p></li><li><p><strong>Meaningful Names</strong>: Although not enforced by Python, it is generally important to use meaningful names for our variables, so that someone reading the code can understand the purpose of those variables.</p></li><li><p><strong>Snakecase</strong>: When coming up with variable names consisting of multiple words, the convention in Python is to separate the words with underscores, for example: <code>interest_rate</code>. This convention is also called snakecase in programming.</p></li></ul><p>Let&#8217;s look at some examples of variable names following these rules and conventions.</p><pre><code>age
name
student_name
total_count
_my_var</code></pre><p>And, here are some examples of invalid variable names:</p><pre><code>1number (starts with a digit)
my-var (contains a hyphen)
for (reserved keyword)</code></pre><div><hr></div><h1>Data Types in Python</h1><p>Now that we know what a variable is, we need to discuss their data types (or simply called types). In programming, a variable not only has a value but also an associated data type based on the value. For example, it can be a number, a string, or something else. Knowing the data type allows us to decide what operations we can perform on that variable. Different programming languages have different data types (although most share a common subset), Python has the following primitive data types:</p><p><strong>int</strong>: These are integer numbers, such as 1, 20, 30, etc.</p><p><strong>float</strong>: These are floating point numbers, such as 3.14, 2.1, 5.0, etc.</p><p><strong>string</strong>: These represent text data, such as <code>&#8220;apple&#8221;</code>. String values in Python need to be enclosed between double quotes (e.g. <code>&#8220;apple&#8221;</code>) or single quotes (e.g. <code>&#8216;apple&#8217;</code>).  </p><p><strong>bool</strong>:  <code>bool</code> represents boolean values, which have only two possible values: <code>True</code> and <code>False</code>. These are commonly used when writing program logic based on conditions. </p><p>These are the most basic data types available in most programming languages. Python also has more complex data types, which we will discuss in our next post in this series. </p><p>Let&#8217;s create some variables with different types in the Python shell and print their types. We will use Python&#8217;s builtin <code>type</code> function to print the types of the variables.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!C6Pb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!C6Pb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png 424w, https://substackcdn.com/image/fetch/$s_!C6Pb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png 848w, https://substackcdn.com/image/fetch/$s_!C6Pb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!C6Pb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!C6Pb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png" width="1348" height="1138" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1138,&quot;width&quot;:1348,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:449697,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!C6Pb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png 424w, https://substackcdn.com/image/fetch/$s_!C6Pb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png 848w, https://substackcdn.com/image/fetch/$s_!C6Pb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png 1272w, https://substackcdn.com/image/fetch/$s_!C6Pb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F351a400b-adea-447a-9c9d-16189e8feb83_1348x1138.png 1456w" sizes="100vw" loading="lazy"></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>Python is a dynamically typed language, which means that the type of a variable is inferred based on the value assigned to it. For example, try the following code in the Python shell:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ili5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ili5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png 424w, https://substackcdn.com/image/fetch/$s_!Ili5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png 848w, https://substackcdn.com/image/fetch/$s_!Ili5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png 1272w, https://substackcdn.com/image/fetch/$s_!Ili5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ili5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png" width="1388" height="578" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/de62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:578,&quot;width&quot;:1388,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:217000,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!Ili5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png 424w, https://substackcdn.com/image/fetch/$s_!Ili5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png 848w, https://substackcdn.com/image/fetch/$s_!Ili5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png 1272w, https://substackcdn.com/image/fetch/$s_!Ili5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde62d0c4-cc80-497d-91f2-6560131956a6_1388x578.png 1456w" sizes="100vw" loading="lazy"></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>In this example, initially, the variable <code>x</code> has the type <code>int</code> because we assigned the value 10 to it. However, on line 4, we assigned the value <code>hello, world</code> to <code>x</code>, which changed its type to <code>string</code>. </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.codingconfessions.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">If you have read this far, consider subscribing to the Confessions of a Code Addict!</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h1>Operators in Python</h1><p>Variables themselves are of not much use to us unless we can perform operations on them and manipulate them, this is where operators come into the picture. We have already used some operators in some of our examples, let&#8217;s discuss them more formally.</p><p>Operators are symbols which allow us to perform certain operations on the variables and data in our program. For example, we used the <code>*</code> operator in our example to calculate simple interest for multiplying the numbers. In this section let&#8217;s look at the complete list of operators available in Python.</p><h3><strong>Numeric Operators in Python</strong></h3><p>Python supports all arithmetic operators for <code>int</code> and <code>float</code> type variables. Let&#8217;s see them with examples below:</p><p><strong>Addition: </strong>Python uses the <code>+</code> operator to add two numbers (<code>int</code> or <code>float</code> types).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iyVA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iyVA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png 424w, https://substackcdn.com/image/fetch/$s_!iyVA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png 848w, https://substackcdn.com/image/fetch/$s_!iyVA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png 1272w, https://substackcdn.com/image/fetch/$s_!iyVA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iyVA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png" width="1388" height="578" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:578,&quot;width&quot;:1388,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:213139,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!iyVA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png 424w, https://substackcdn.com/image/fetch/$s_!iyVA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png 848w, https://substackcdn.com/image/fetch/$s_!iyVA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png 1272w, https://substackcdn.com/image/fetch/$s_!iyVA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a49831d-c066-4070-ae66-04ed66f9db78_1388x578.png 1456w" sizes="100vw" loading="lazy"></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><blockquote><p>When doing any arithmetic operation where <code>int</code> and <code>float</code> types are involved, the resulting value is always a floating-point value. </p></blockquote><p><strong>Subtraction: </strong>Python uses the <code>-</code> operator for subtracting two numbers. See the example below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hXY0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hXY0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png 424w, https://substackcdn.com/image/fetch/$s_!hXY0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png 848w, https://substackcdn.com/image/fetch/$s_!hXY0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png 1272w, https://substackcdn.com/image/fetch/$s_!hXY0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hXY0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png" width="600" height="610" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/db12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:610,&quot;width&quot;:600,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:125312,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!hXY0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png 424w, https://substackcdn.com/image/fetch/$s_!hXY0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png 848w, https://substackcdn.com/image/fetch/$s_!hXY0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png 1272w, https://substackcdn.com/image/fetch/$s_!hXY0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb12caf1-ca8b-4261-ad7a-7ffb3621a8b6_600x610.png 1456w" sizes="100vw" loading="lazy"></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><strong>Multiplication: </strong>The <code>*</code> operator is used for multiplying two numbers. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Eul1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Eul1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png 424w, https://substackcdn.com/image/fetch/$s_!Eul1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png 848w, https://substackcdn.com/image/fetch/$s_!Eul1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png 1272w, https://substackcdn.com/image/fetch/$s_!Eul1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Eul1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png" width="916" height="746" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:746,&quot;width&quot;:916,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:214773,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!Eul1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png 424w, https://substackcdn.com/image/fetch/$s_!Eul1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png 848w, https://substackcdn.com/image/fetch/$s_!Eul1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png 1272w, https://substackcdn.com/image/fetch/$s_!Eul1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4489865b-c293-4ce8-a6cc-3d98e5e4faa8_916x746.png 1456w" sizes="100vw" loading="lazy"></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><strong>Division: </strong>We use the <code>/</code> operator for division. This operator produces the quotient after the division. Let&#8217;s see some examples. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qSLF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qSLF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png 424w, https://substackcdn.com/image/fetch/$s_!qSLF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png 848w, https://substackcdn.com/image/fetch/$s_!qSLF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png 1272w, https://substackcdn.com/image/fetch/$s_!qSLF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qSLF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png" width="1456" height="974" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:974,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:364836,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!qSLF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png 424w, https://substackcdn.com/image/fetch/$s_!qSLF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png 848w, https://substackcdn.com/image/fetch/$s_!qSLF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png 1272w, https://substackcdn.com/image/fetch/$s_!qSLF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4780e3-e2e8-47fd-84db-b06d176a2bb0_1456x974.png 1456w" sizes="100vw" loading="lazy"></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><blockquote><p>When we divide a number by 0, Python gives us a <code>ZeroDivisionError</code>. This is because dividing by 0 is not a well-defined operation, and Python doesn't know what to do. As a programmer, we need to avoid such cases by putting appropriate checks in place. We will discuss how to do these checks when we talk about <code>if</code> conditions in a future post.</p></blockquote><p><strong>Integer Division</strong>:<strong> </strong>You might have noticed that the <code>/</code> operator always produces a floating-point value even when we are dividing two integers that are perfectly divisible, such as the result of <code>10 / 2</code> being <code>5.0</code>. If we are interested only in the integer part of the result and not the fraction, Python provides the special <code>//</code> operator for integer division. Let&#8217;s see some examples.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ryvV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ryvV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png 424w, https://substackcdn.com/image/fetch/$s_!ryvV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png 848w, https://substackcdn.com/image/fetch/$s_!ryvV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png 1272w, https://substackcdn.com/image/fetch/$s_!ryvV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ryvV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png" width="824" height="938" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:938,&quot;width&quot;:824,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:240953,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!ryvV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png 424w, https://substackcdn.com/image/fetch/$s_!ryvV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png 848w, https://substackcdn.com/image/fetch/$s_!ryvV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png 1272w, https://substackcdn.com/image/fetch/$s_!ryvV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd45a30-f662-4e50-8d38-b2c5e3119e94_824x938.png 1456w" sizes="100vw" loading="lazy"></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><strong>Exponentiation Operator</strong>: Python also includes the <code>**</code> operator to calculate the power of a number. For example, <code>2 ** 3</code> calculates <code>2</code> raised to the power of <code>3</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YjMc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YjMc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png 424w, https://substackcdn.com/image/fetch/$s_!YjMc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png 848w, https://substackcdn.com/image/fetch/$s_!YjMc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png 1272w, https://substackcdn.com/image/fetch/$s_!YjMc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YjMc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png" width="748" height="770" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:770,&quot;width&quot;:748,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:181654,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!YjMc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png 424w, https://substackcdn.com/image/fetch/$s_!YjMc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png 848w, https://substackcdn.com/image/fetch/$s_!YjMc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png 1272w, https://substackcdn.com/image/fetch/$s_!YjMc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F028e804e-b2f1-49fb-a8e2-b8b750fe929f_748x770.png 1456w" sizes="100vw" loading="lazy"></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><strong>Modulo Operator</strong>: The modulo operator (<code>%</code>) computes the remainder of a division operation. For example, <code>5 % 2</code> gives <code>1</code> as the result.</p><h3><strong>Comparison Operators in Python</strong></h3><p>Python (and every other programming language) includes operators to compare two values:</p><ul><li><p><strong>Equality Operator</strong>: The <code>==</code> operator compares two values to determine if they are equal. It produces a boolean value as a result, which will be <code>True</code> if the values on both sides of the operator are equal, and <code>False</code> otherwise. Let&#8217;s try some examples in the Python shell.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6ELc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6ELc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png 424w, https://substackcdn.com/image/fetch/$s_!6ELc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png 848w, https://substackcdn.com/image/fetch/$s_!6ELc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png 1272w, https://substackcdn.com/image/fetch/$s_!6ELc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6ELc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png" width="884" height="1262" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1262,&quot;width&quot;:884,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:325966,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!6ELc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png 424w, https://substackcdn.com/image/fetch/$s_!6ELc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png 848w, https://substackcdn.com/image/fetch/$s_!6ELc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png 1272w, https://substackcdn.com/image/fetch/$s_!6ELc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1971dcf6-fdea-4c8b-b973-b26c75fe4cf0_884x1262.png 1456w" sizes="100vw" loading="lazy"></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><ul><li><p><strong>Not Equal Operator</strong>: The not equal operator is represented by <code>!=</code>. It produces <code>True</code> if the values on the two sides of the operator are not equal and <code>False</code> otherwise. Let&#8217;s try a few examples.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TVN1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TVN1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png 424w, https://substackcdn.com/image/fetch/$s_!TVN1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png 848w, https://substackcdn.com/image/fetch/$s_!TVN1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png 1272w, https://substackcdn.com/image/fetch/$s_!TVN1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TVN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png" width="884" height="1262" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1262,&quot;width&quot;:884,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:321664,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!TVN1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png 424w, https://substackcdn.com/image/fetch/$s_!TVN1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png 848w, https://substackcdn.com/image/fetch/$s_!TVN1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png 1272w, https://substackcdn.com/image/fetch/$s_!TVN1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff71df005-989f-4d20-b780-c48d2c9219ea_884x1262.png 1456w" sizes="100vw" loading="lazy"></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><ul><li><p><strong>Numerical Comparison Operators</strong>: Python includes operators for comparing numbers. These are <code>&gt;</code> (greater than), <code>&lt;</code> (less than), <code>&gt;=</code> (greater than or equal to), and <code>&lt;=</code> (less than or equal to). </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TT3w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TT3w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png 424w, https://substackcdn.com/image/fetch/$s_!TT3w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png 848w, https://substackcdn.com/image/fetch/$s_!TT3w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png 1272w, https://substackcdn.com/image/fetch/$s_!TT3w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TT3w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png" width="600" height="798" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:798,&quot;width&quot;:600,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:167160,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!TT3w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png 424w, https://substackcdn.com/image/fetch/$s_!TT3w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png 848w, https://substackcdn.com/image/fetch/$s_!TT3w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png 1272w, https://substackcdn.com/image/fetch/$s_!TT3w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5316a3e3-5417-4ed5-b3c2-fc27bf4009d4_600x798.png 1456w" sizes="100vw" loading="lazy"></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></li></ul><h4>Operator Precedence</h4><p>When doing complex calculations, we need to be aware which operators are evaluated first because this order can change the result of the expression. The following table shows the precedence of operators in Python.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_xXo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_xXo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!_xXo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!_xXo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!_xXo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_xXo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png" width="1080" height="1080" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1080,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:38626,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!_xXo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png 424w, https://substackcdn.com/image/fetch/$s_!_xXo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png 848w, https://substackcdn.com/image/fetch/$s_!_xXo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!_xXo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe719ad02-cbe7-4807-8d25-90ed5a2fe518_1080x1080.png 1456w" sizes="100vw" loading="lazy"></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>In any expression, the higher precedence operators are evaluated first. Let&#8217;s understand with the help of some examples.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Acn5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Acn5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png 424w, https://substackcdn.com/image/fetch/$s_!Acn5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png 848w, https://substackcdn.com/image/fetch/$s_!Acn5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png 1272w, https://substackcdn.com/image/fetch/$s_!Acn5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Acn5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png" width="600" height="746" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:746,&quot;width&quot;:600,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:147606,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!Acn5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png 424w, https://substackcdn.com/image/fetch/$s_!Acn5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png 848w, https://substackcdn.com/image/fetch/$s_!Acn5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png 1272w, https://substackcdn.com/image/fetch/$s_!Acn5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61ff179a-53f4-43f2-aad6-083b5fb33621_600x746.png 1456w" sizes="100vw" loading="lazy"></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>As you can see in the first example <code>5 + 10 * 2</code>, because of higher precedence of the <code>*</code> operator, <code>10 * 2</code> is calculated first and then the result is added to <code>5</code>. </p><p>In a simpler expression such as <code>5 + 10 - 2</code>,  where both the operators (<code>+</code> and <code>-)</code> are of equal precedence, the operators are evaluated from left to right. In this case first  <code>5 + 10</code> is evaluated to <code>15,</code> and then <code>15 - 2</code> is evaluated.</p><p>We can use parenthesis to change the order of evaluation. If an expression has parenthesis, then the sub-expressions within the parenthesis are evaluated first. For example:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u3bR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u3bR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png 424w, https://substackcdn.com/image/fetch/$s_!u3bR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png 848w, https://substackcdn.com/image/fetch/$s_!u3bR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png 1272w, https://substackcdn.com/image/fetch/$s_!u3bR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u3bR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png" width="692" height="734" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/22233746-2e61-46f1-a285-9132d52b83a5_692x734.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:734,&quot;width&quot;:692,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:154469,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!u3bR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png 424w, https://substackcdn.com/image/fetch/$s_!u3bR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png 848w, https://substackcdn.com/image/fetch/$s_!u3bR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png 1272w, https://substackcdn.com/image/fetch/$s_!u3bR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F22233746-2e61-46f1-a285-9132d52b83a5_692x734.png 1456w" sizes="100vw" loading="lazy"></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>We can also use nested parenthesis as shown in the last example. In case of nested parenthesis, we start the evaluation from the innermost parenthesis.</p><h3>String Operators in Python</h3><p><strong>Concatenation Operator</strong>: In programming, concatenating strings means joining two or more strings together to form a new string. In Python, the <code>+</code> operator is used to concatenate strings. For example, <code>&#8220;hello&#8221; + &#8220;world&#8221;</code> produces the new string <code>&#8220;helloworld&#8221;</code>. </p><blockquote><p>Note that the + operator when used with numbers performed addition, but when used with strings, it performs concatenation. </p></blockquote><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ow7u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ow7u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png 424w, https://substackcdn.com/image/fetch/$s_!ow7u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png 848w, https://substackcdn.com/image/fetch/$s_!ow7u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png 1272w, https://substackcdn.com/image/fetch/$s_!ow7u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ow7u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png" width="1456" height="619" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:619,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:260937,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!ow7u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png 424w, https://substackcdn.com/image/fetch/$s_!ow7u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png 848w, https://substackcdn.com/image/fetch/$s_!ow7u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png 1272w, https://substackcdn.com/image/fetch/$s_!ow7u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac66434-ca84-47ce-a576-55d7cc2ffff5_1528x650.png 1456w" sizes="100vw" loading="lazy"></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><strong>Repetition Operator</strong>: The repetition operator (<code>*</code>) repeats a string the specified number of times. For example, if we have a string <code>s</code>, then <code>s * 3</code> produces a new string where <code>s</code> has been repeated 3 times.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gE2I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gE2I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png 424w, https://substackcdn.com/image/fetch/$s_!gE2I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png 848w, https://substackcdn.com/image/fetch/$s_!gE2I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png 1272w, https://substackcdn.com/image/fetch/$s_!gE2I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gE2I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png" width="840" height="594" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:594,&quot;width&quot;:840,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:166603,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!gE2I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png 424w, https://substackcdn.com/image/fetch/$s_!gE2I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png 848w, https://substackcdn.com/image/fetch/$s_!gE2I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png 1272w, https://substackcdn.com/image/fetch/$s_!gE2I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcf7d544-9b8a-4830-8df9-a87d619b7d23_840x594.png 1456w" sizes="100vw" loading="lazy"></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><h3>Boolean Operators in Python</h3><p>Boolean operators allow us to implement logic in our programs based on conditions. For example, when we want a piece of code to execute only when a certain condition is true, we need to evaluate that condition using these operators. We will delve deeper into how to write such conditional code, but first, let's understand how to use these operators.</p><p><strong>The </strong><code>and</code><strong>, </strong><code>or</code><strong> and </strong><code>not</code><strong> operators</strong>: These operators allow us to express complex logical conditions by combining multiple conditions into a single expression. For example:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!S-br!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!S-br!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png 424w, https://substackcdn.com/image/fetch/$s_!S-br!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png 848w, https://substackcdn.com/image/fetch/$s_!S-br!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png 1272w, https://substackcdn.com/image/fetch/$s_!S-br!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!S-br!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png" width="600" height="574" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:574,&quot;width&quot;:600,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:111759,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!S-br!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png 424w, https://substackcdn.com/image/fetch/$s_!S-br!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png 848w, https://substackcdn.com/image/fetch/$s_!S-br!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png 1272w, https://substackcdn.com/image/fetch/$s_!S-br!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1906c312-d5fa-419e-98c1-65c279d1fbb5_600x574.png 1456w" sizes="100vw" loading="lazy"></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>The <code>and</code> operator evaluates whether both conditions on its left and right are true. If either of them is false, it produces <code>False</code>. </p><p>Similarly, the <code>or</code> operator evaluates whether at least one of the conditions is true. If both conditions are false, then it produces <code>False</code>; otherwise, it produces <code>True</code>.</p><p>Finally, the <code>not</code> operator negates a condition. For example, <code>not True</code> produces <code>False</code>.</p><blockquote><p>Unlike the <code>and</code> and <code>or</code> operators, <code>not</code> is a unary operator,  that means it only has one operand, which appears on the right-hand side of <code>not</code>.  </p></blockquote><p>Let&#8217;s try some examples in the Python shell.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!69rC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!69rC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png 424w, https://substackcdn.com/image/fetch/$s_!69rC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png 848w, https://substackcdn.com/image/fetch/$s_!69rC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png 1272w, https://substackcdn.com/image/fetch/$s_!69rC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!69rC!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png" width="1200" height="786.2637362637363" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:954,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:633229,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!69rC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png 424w, https://substackcdn.com/image/fetch/$s_!69rC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png 848w, https://substackcdn.com/image/fetch/$s_!69rC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png 1272w, https://substackcdn.com/image/fetch/$s_!69rC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F285cd1a1-ada2-40ef-9f8d-672d57bbb943_1968x1290.png 1456w" sizes="100vw" loading="lazy"></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>We can also combine <code>and</code> and <code>or</code> conditions in a single statement. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UuSZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UuSZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png 424w, https://substackcdn.com/image/fetch/$s_!UuSZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png 848w, https://substackcdn.com/image/fetch/$s_!UuSZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png 1272w, https://substackcdn.com/image/fetch/$s_!UuSZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UuSZ!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png" width="1200" height="786.2637362637363" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:954,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:617654,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UuSZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png 424w, https://substackcdn.com/image/fetch/$s_!UuSZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png 848w, https://substackcdn.com/image/fetch/$s_!UuSZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png 1272w, https://substackcdn.com/image/fetch/$s_!UuSZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F798bb262-6f7d-43b5-bf55-4e5e80a63552_1968x1290.png 1456w" sizes="100vw" loading="lazy"></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><blockquote><p><strong>Use of parenthesis</strong>: The use of parentheses clarifies the code's intent. For example, when we have code like this:</p><pre><code><code>x &gt; 10 and x &lt; 12 or y == 5</code></code></pre><p>Even though Python is able to evaluate this using the operator precedence rules. But as a reader, it&#8217;s hard for me to understand whether the programmer intended to evaluate the <code>or</code> part first or the <code>and</code> part first. However, if we add parentheses appropriately, the intent becomes clear. For example:</p><pre><code><code>(x &gt; 10 and x &lt; 12) or y == 5</code></code></pre></blockquote><h3>Short-Circuit Evaluation of Boolean Operators</h3><p>The <code>and</code> and <code>or</code> operators perform a short-circuit evaluation of their operands. For example, if the left operand of the <code>and</code> operator is <code>False</code> then the right operand is not evaluated because the end result of the <code>and</code> operation would have been <code>False</code> anyway.</p><p>Similarly, in case of an <code>or</code> operation, if the left operand is evaluated as <code>True</code> then the right operand is not evaluated because the <code>or</code> operation would result in a <code>True</code> value regardless the value of the right operand.</p><p>You might wonder why this is useful, let&#8217;s understand with the help of an example. Let&#8217;s say you want to check whether a number is divisible by another number. You could do this by checking that the remainder of their division is <code>0</code> as shown below.</p><pre><code>is_divisble = x % y == 0</code></pre><p>However, what if <code>y</code> is <code>0</code>? Python would give a <code>ZeroDivisionError</code> in that case and your program will crash. To avoid this, you want to add a check that <code>y</code> is not <code>0</code> and only then do the division. The short-circuit evaluation of the <code>and</code> operator will allow us to do that.</p><pre><code>is_divisble = y != 0 and x % y == 0</code></pre><p>If <code>y</code> is <code>0</code>, then the <code>and</code> operator would short-circuit and it will not evaluate <code>x % y</code> which will prevent the division by <code>0</code>.</p><h2>Putting it All Together in a Project</h2><p>We have covered a lot in this post. Let&#8217;s apply what we've learned by building a small project. We will write a small program that computes the area of a circle by asking the user to input the radius. </p><p>Assuming you have set up Visual Studio Code with the Python plugin, you can now create a new file and save it with the name "circle_area_calculator.py" in the "python_tutorial" directory. Write the following code in the file:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eOZf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eOZf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png 424w, https://substackcdn.com/image/fetch/$s_!eOZf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png 848w, https://substackcdn.com/image/fetch/$s_!eOZf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png 1272w, https://substackcdn.com/image/fetch/$s_!eOZf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eOZf!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png" width="1200" height="499.45054945054943" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:606,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:402736,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eOZf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png 424w, https://substackcdn.com/image/fetch/$s_!eOZf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png 848w, https://substackcdn.com/image/fetch/$s_!eOZf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png 1272w, https://substackcdn.com/image/fetch/$s_!eOZf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3be4d978-2cb3-4271-940e-59b259c64fab_1976x822.png 1456w" sizes="100vw" loading="lazy"></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>On line 1, we create a variable to store the value of <code>pi</code>.</p><p>On line 2, we use the Python function <code>input</code> to prompt the user to provide the value for the radius. The <code>input</code> function prints a message on the screen and waits for the user to enter a value in the response, which can then be assigned to a variable.</p><p>By default, the <code>input</code> function treats user input as a string. To compute the area of the circle, we need the radius to be a float. Therefore, we use the <code>float()</code> function to convert the string value into a <code>float</code> type before assigning it to the radius variable.</p><p>On line 3, we calculate the area of the circle by squaring the <code>radius</code> and multiplying it by <code>pi</code>. In Python, the <code>**</code> operator has a higher priority than multiplication, so Python first calculates <code>radius ** 2</code> and then multiplies the result by <code>pi</code>. </p><p>On line 4, we print the result. We used the string concatenation operator (<code>+</code>) to generate the output message. When concatenating a string and a number, we need to typecast the number into a string using the <code>str</code> function; otherwise, Python will return a <code>TypeError</code>. </p><p>Press <code>Ctrl + F5</code> to run the project. The screen displays a message prompting you to enter the radius. Input the value and press <code>Enter</code> to calculate the area.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2pfG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2pfG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png 424w, https://substackcdn.com/image/fetch/$s_!2pfG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png 848w, https://substackcdn.com/image/fetch/$s_!2pfG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png 1272w, https://substackcdn.com/image/fetch/$s_!2pfG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2pfG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png" width="525" height="319" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:319,&quot;width&quot;:525,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32726,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!2pfG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png 424w, https://substackcdn.com/image/fetch/$s_!2pfG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png 848w, https://substackcdn.com/image/fetch/$s_!2pfG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png 1272w, https://substackcdn.com/image/fetch/$s_!2pfG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2298517f-32cb-40a5-a0a2-cf71ac0726e5_525x319.png 1456w" sizes="100vw" loading="lazy"></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><h1>Conclusion and Next Steps</h1><p>In this second instalment of the Pursuit of Programming series, we delved into essential programming concepts such as variables, data types, and operators in Python. We provided real-world examples to illustrate these concepts, ensuring thorough understanding. Furthermore, we combined these topics in a practical exercise, developing a simple program to calculate the area of a circle.</p><p>As you continue to explore Python programming, take the time to practice writing more programs using the concepts we've covered. Examples include a compound interest calculator or a program to compute the area of a rectangle. Utilizing these concepts in numerous scenarios will help solidify your understanding.</p><p>In our upcoming posts, we will explore more advanced concepts such as lists, tuples, and dictionaries. Feel free to ask questions and share your experiences in the comments section below as we continue in the Pursuit of Programming. Happy coding!</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.codingconfessions.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Confessions of a Code Addict! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[The Pursuit of Programming #1: What, Why, and How to Start]]></title><description><![CDATA[A Step-by-Step Tutorial on Setting up Python and Writing Your First "Hello, World" Program]]></description><link>https://blog.codingconfessions.com/p/the-pursuit-of-programming-1</link><guid isPermaLink="false">https://blog.codingconfessions.com/p/the-pursuit-of-programming-1</guid><dc:creator><![CDATA[Abhinav Upadhyay]]></dc:creator><pubDate>Sun, 07 May 2023 16:20:12 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Z_O6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As promised when starting this newsletter, I will begin at the very beginning. While learning to program is fun and leads to endless creativity, teaching it in a way that engages students is no easy feat. In the Pursuit of Programming series, my aim is to explain programming concepts creatively so that they can be understood intuitively.</p><p>In this post, we will discuss what programming is, how to install Python, and set up our development environment. We will wrap up by writing our first program. If this sounds like fun, let's get started!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Z_O6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Z_O6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Z_O6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Z_O6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Z_O6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Z_O6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg" width="512" height="512" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:512,&quot;width&quot;:512,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:68070,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&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_!Z_O6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Z_O6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Z_O6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Z_O6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f90c2cd-26c1-4e30-8d2d-2de0437c5b32_512x512.jpeg 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><figcaption class="image-caption">Programmer working on laptop</figcaption></figure></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.codingconfessions.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">If you are enjoying reading this post, consider subscribing to this newsletter.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h1>What is Programming</h1><p>Computers are relatively simple machines that cannot do anything on their own. To perform any task, we must provide them with detailed instructions in their own language. This language allows us to communicate with computers, and writing instructions in this language is called programming.</p><p>To better understand this concept, imagine you have a remote control car that understands only four basic commands: move forward, move backward, turn left, and turn right. To navigate the car from point A to point B, you must provide a sequence of these commands, such as:</p><pre><code>1. Move forward for 15 meters.
2. Turn left 90 degrees.
3. Move forward for 20 meters.
4. Turn right 90 degrees.
5. Move forward 5 meters.</code></pre><p>Programming a computer is similar to providing these instructions to the remote control car. However, unlike the car, which is designed for a specific purpose, computers are general-purpose devices, so their instruction language is more versatile. Nevertheless, the fundamental concept of providing step-by-step instructions remains the same.</p><div><hr></div><h1>Getting Setup - Installing Python</h1><p>We will use Python in this series of posts to learn programming. Python is an excellent choice for beginners due to its user-friendly syntax, which reads like English and does not hinder understanding programming concepts. Python also features an interactive programming environment that makes experimentation a breeze. In this section, we will cover how to set up Python on various operating systems. </p><h2>Installing Python on Windows</h2><p>To install Python on Windows, follow these steps:</p><ol><li><p>Visit the official Python download page to download the Python installer: <a href="https://www.python.org/downloads/windows/">https://www.python.org/downloads/windows/</a>. As of writing this post, the latest Python version is 3.11.3. Note that if you have Windows 7, you need to download Python 3.8.16 or earlier because later Python versions do not support Windows 7. If you are unsure which of the several Windows installers to choose, base your decision on your CPU architecture. Most household computers use an AMD or Intel CPU, and 64-bit is the most common architecture these days, so select "Windows Installer (64-bit)".</p></li><li><p>After downloading the installer, double-click it to start the installation process.</p></li><li><p>When the installer starts, select the "<strong>Add python.exe to PATH</strong>" option so you can run Python from the command line.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Usr8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Usr8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png 424w, https://substackcdn.com/image/fetch/$s_!Usr8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png 848w, https://substackcdn.com/image/fetch/$s_!Usr8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png 1272w, https://substackcdn.com/image/fetch/$s_!Usr8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Usr8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png" width="663" height="407" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:407,&quot;width&quot;:663,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:101366,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!Usr8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png 424w, https://substackcdn.com/image/fetch/$s_!Usr8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png 848w, https://substackcdn.com/image/fetch/$s_!Usr8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png 1272w, https://substackcdn.com/image/fetch/$s_!Usr8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e128b2f-3179-436f-bb15-7c9895486feb_663x407.png 1456w" sizes="100vw" loading="lazy"></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></li><li><p>If this is your first time installing Python, click "Install Now" and continue with the installation. The installer will apply default settings suitable for most users, including IDLE (an interactive Python code editor), pip (a package manager for installing additional Python packages), and shortcuts for starting Python.</p></li><li><p>Once the installer completes, verify the installation by going to <code>Start</code>, typing "<code>cmd</code>" in the search bar, and pressing Enter. This will open a command prompt. Type the following command in the command prompt and press Enter:</p><pre><code>python --version</code></pre><p>You should output similar to this:</p><pre><code><code>Python 3.11.3</code></code></pre><p>This means Python is installed on your system. If you see an error, such as "command not found," you likely did not select the option to add Python to the PATH environment variable during installation, as recommended in step 3. In this case, uninstall Python, reinstall it, and ensure you select that option this time.</p></li></ol><h2>Installing Python on MacOS</h2><p>Mac comes preinstalled with Python. To check the version of Python, open a terminal window (click the spotlight icon and type "terminal" in the dialog that appears). In the terminal window, type the following command and press Enter:</p><pre><code>python3 --version</code></pre><p>If the output says "command not found," you need to download and install Python. To do this, go to the URL <a href="https://www.python.org/downloads/macos/">https://www.python.org/downloads/macos/</a> and select the latest version for Mac. Once the installer is downloaded, double-click to start it and follow the instructions. After it finishes, verify the installation by rerunning the &#8216;<code>python3 --version</code>&#8217; command in the terminal.</p><h2>Installing Python on Linux</h2><p>Most popular Linux distributions, such as Ubuntu and Fedora, come preinstalled with Python. As we primarily focus on learning Python syntax basics, the installed Python version is not crucial as long as it is a Python 3 version. Verify the Python version by running the following command in a terminal window:</p><pre><code>python --version</code></pre><p>If the output says something similar to "<code>Python 3.x.x</code>," you're good to go.</p><div><hr></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.codingconfessions.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Did this post help you install Python? Consider subscribing to the newsletter to get more such posts in your inbox</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h1>Playing With Python &#128013;</h1><p>Now that Python is installed, let's explore it a bit. We'll do this in the Python shell&#8212;an interactive command-line interpreter for Python that allows us to write small amounts of code and see the output immediately. </p><h2>Starting Python Shell on Windows</h2><p>Click on <code>Start</code> and enter "<code>cmd</code>." This will open the Windows command prompt. In the Windows command prompt, type "<code>python</code>" and press Enter. This will start the Python shell within the same command prompt window. You should now see the Python shell prompt (<code>&gt;&gt;&gt;</code>). </p><h2>Starting Python Shell on MacOS and Linux</h2><p>Open a terminal window, type "<code>python</code>" (Mac users need to type "<code>python3</code>"), and press Enter. You should see the Python shell prompt (<code>&gt;&gt;&gt;</code>).</p><h2>Writing Our First Python Code</h2><p>Let&#8217;s write our first line of Python code in the Python shell. </p><pre><code>&gt;&gt;&gt; print("hello, world")
hello, world</code></pre><p>You don't need to type the "<code>&gt;&gt;&gt;</code>" part; that's the Python shell prompt. This prompt indicates that the Python shell is ready for our input, meaning we can type our code.</p><p><code>print(&#8220;hello, world&#8221;) </code>is our first line of Python code. The <code>print</code> function tells Python to display a message on the screen. In this case, we are printing the message "hello, world." (We enclose the message in double quotes so Python knows where the message begins and ends. We will discuss strings in more detail in a later post.)</p><p>After typing this code and pressing Enter, the message appears on the screen. </p><p>Next, we can perform some basic arithmetic in the Python shell, such as:</p><pre><code>&gt;&gt;&gt; 2 + 3
5
&gt;&gt;&gt; 5 * 2
10
&gt;&gt;&gt; 10 / 5
2.0
&gt;&gt;&gt; 5 - 1
4
&gt;&gt;&gt;
</code></pre><p>These lines are valid Python code. Python understands basic arithmetic operators, which can be used with numbers and variables. We will discuss variables in an upcoming post in this series and demonstrate how to use these operators with them.</p><div><hr></div><h1>Installing Visual Studio Code (VSCode)</h1><p>Now that we've had a taste of Python, it's time to complete our development environment setup. We have installed Python, but we also need a place to write code. While the Python shell is excellent for testing small bits of code, we need a proper code editor for working on projects. <a href="https://code.visualstudio.com/">Visual Studio Code (VSCode)</a> is a popular choice nowadays, as it supports not only Python but also many other programming languages. </p><p>To install VSCode, download the installer from the official website: <a href="https://code.visualstudio.com/">https://code.visualstudio.com/</a>. After downloading the installer for your OS, open it and follow the instructions to install it. Once installed, you can launch VSCode from your OS's application launcher (for Windows, go to the Start menu and type "visual studio code" in the search bar). </p><p>One more step remains before we're all set: we must install the Python extension for Visual Studio Code to enable Python code execution. To do this, click the gear icon in the bottom left corner of the VS Code window or use shortcut <code>Ctrl + Shift + X</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3fDG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3fDG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!3fDG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!3fDG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!3fDG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3fDG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:146593,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!3fDG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!3fDG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!3fDG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!3fDG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2994331c-69f1-49eb-8f78-7536044f9c10_1920x1080.png 1456w" sizes="100vw" loading="lazy"></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>This action opens the VSCode Extensions Marketplace. In the text box on the left side of the screen, type "python." This search will display all Python-related extensions. Select the official Python extension provided by Microsoft, which typically appears as the first option (see screenshot below).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZgFv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZgFv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!ZgFv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!ZgFv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!ZgFv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZgFv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:366919,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!ZgFv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!ZgFv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!ZgFv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!ZgFv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5ce30f88-678a-460f-83eb-f35c5d2d19bf_1920x1080.png 1456w" sizes="100vw" loading="lazy"></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>Click "Install," and the extension should install within a couple of minutes.</p><div><hr></div><h1>Writing and Running Our First Python Program</h1><p>Now, let's create a folder for our Python code and write our first program in that folder. First, create a folder on your Desktop, as it is easy to locate. Name the folder something like "python_tutorial." </p><p>In VSCode, create a new file by either going to File &gt; New File or using the shortcut <code>Ctrl + N</code>. In the file, type the following line:</p><pre><code>print("hello, world")</code></pre><p>Press <code>Ctrl + S</code> to save the file. In the save dialog box, navigate to the "python_tutorial" folder on your Desktop and save the file there as "helloworld.py." </p><p>To run the program in VSCode, go to the Run menu and click "Run Without Debugging." This action will launch the terminal within VSCode and display the program's output. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZSId!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZSId!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!ZSId!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!ZSId!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!ZSId!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZSId!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:116139,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&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_!ZSId!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!ZSId!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!ZSId!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!ZSId!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7ba1895-2b4f-4b01-991a-cbbad263aad0_1920x1080.png 1456w" sizes="100vw" loading="lazy"></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>Congratulations! You've just completed your very first Python project, which prints a message on the screen. Feel free to experiment by changing the message. As we saw in the previous section, Python understands arithmetic computations, so you can also print the results of such calculations. For example:</p><pre><code>print(2 + 6)</code></pre><p>We don't need quotes here because they're usually unnecessary when printing numbers. For a fun experiment, try adding quotes around the code above and observe the result. Share your answer in the replies or comments, explaining what happened and why the output changed.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.codingconfessions.com/p/the-pursuit-of-programming-1/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.codingconfessions.com/p/the-pursuit-of-programming-1/comments"><span>Leave a comment</span></a></p><div><hr></div><h1>Conclusion</h1><p>We have reached the end of this post. We've accomplished a lot here: learning what programming a computer entails, discovering Python, installing it, and setting up its development environment using Visual Studio Code. We also wrote and ran our first program. I encourage you to play around and explore other things you can do.</p><p>In upcoming posts, we will delve deeper into programming concepts such as variables, data types, loops, and more. Don't worry if these terms are unfamiliar to you.</p><p>If you encounter any errors while following the steps in this post or running the programs, feel free to reply or comment here. I will try to help you. If you discover something fun while experimenting with Python, please share it here so we can all learn together.</p><p>Until the next post, have fun on your Python adventures&#128013;</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://blog.codingconfessions.com/p/the-pursuit-of-programming-1?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Thank you for reading Confessions of a Code Addict. This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.codingconfessions.com/p/the-pursuit-of-programming-1?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.codingconfessions.com/p/the-pursuit-of-programming-1?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><p></p>]]></content:encoded></item></channel></rss>