<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: David Fabusuyi </title>
    <description>The latest articles on DEV Community by David Fabusuyi  (@techwithdavid).</description>
    <link>https://dev.to/techwithdavid</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1035774%2F1f0be28d-7b3b-4e9b-b409-c7188f79de11.jpeg</url>
      <title>DEV Community: David Fabusuyi </title>
      <link>https://dev.to/techwithdavid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/techwithdavid"/>
    <language>en</language>
    <item>
      <title>Python Tutorial: Basic Syntax - How to Work With Python</title>
      <dc:creator>David Fabusuyi </dc:creator>
      <pubDate>Mon, 15 May 2023 04:03:57 +0000</pubDate>
      <link>https://dev.to/techwithdavid/python-tutorial-basic-syntax-how-to-work-with-python-3oo1</link>
      <guid>https://dev.to/techwithdavid/python-tutorial-basic-syntax-how-to-work-with-python-3oo1</guid>
      <description>&lt;p&gt;In my previous article, I wrote extensively on an Introduction to Python programming. The article covered a lot on what you need to know to get started with Python.&lt;/p&gt;

&lt;p&gt;In today's article, you will learn how codes are formatted in Python. This article will cover concepts such as white space, line indentation, multi-line statements, comments in Python, and multiple statements on a single line. &lt;/p&gt;

&lt;p&gt;This article provides a brief overview of how Python code is formatted and is not intended to be a comprehensive guide to Python's syntax. Additional syntax concepts will be explained in future articles as they are used.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python's Syntax
&lt;/h2&gt;

&lt;p&gt;A language has a unique form in which it is written. This distinguishes it from other languages. This is what is referred to as syntax. &lt;/p&gt;

&lt;p&gt;Python has a set of rules that govern the way statements are written. While there may be some similarities between its syntax and that of other languages, there are also differences that makes it unique.&lt;/p&gt;

&lt;p&gt;Let's take a look at this example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'Hello, world'&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 'Hello, world'
&lt;/span&gt;&lt;span class="s"&gt;'Hello, world'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, I created a variable named &lt;code&gt;greet&lt;/code&gt; and I assigned the string &lt;code&gt;Hello, world&lt;/code&gt; to it.&lt;/p&gt;

&lt;p&gt;You may or may not be familiar with what variables and strings are. If you have experiences with other programming languages, you likely know what variables and strings are.&lt;/p&gt;

&lt;p&gt;If you are completely new to programming, variables are used as containers to hold values, while a string is a sequence of characters enclosed within double or single quotes. More on these topics will be covered in future articles.&lt;/p&gt;

&lt;p&gt;If you have experiences with other languages like C, you might expect this line of code to end with a semi-colon. That's not the case in Python.&lt;/p&gt;

&lt;p&gt;Python does not require semi-colons at the end of statements. It operates only on whitespaces which makes it a very clean language to work with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comments
&lt;/h2&gt;

&lt;p&gt;Let's take a look at the example below.&lt;/p&gt;

&lt;p&gt;I've added a new line above the print statement which explains what the print statement will do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'Hello, world'&lt;/span&gt; &lt;span class="c1"&gt;# Creates a variable and assigns a string to it
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#  Prints Hello, world
&lt;/span&gt;&lt;span class="s"&gt;'Hello, world'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What I did is what is referred to as commenting. Comments are mostly used to explain a line of code, functions, classes and so on. The way you add a comment to a line is by preceding the line with a pound sign &lt;code&gt;(#)&lt;/code&gt;. This tells python you're writing a comment. This line of code will be skipped when python is running your program.&lt;/p&gt;

&lt;p&gt;The pound sign can be used on multiple lines to make a multi-line comment.&lt;/p&gt;

&lt;p&gt;For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Adds x and y
&lt;/span&gt;    &lt;span class="c1"&gt;# And prints the output
&lt;/span&gt;    &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Triple quotes can also be used to write comments, especially when defining functions, conditional statements, and classes. &lt;/p&gt;

&lt;p&gt;For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="s"&gt;"""Add x and y"""&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And they can as well be used for multi-line comments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="s"&gt;"""
This is a multi-line comment.
It can span multiple lines.
This is useful for documenting code.
"""&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Line indentation
&lt;/h2&gt;

&lt;p&gt;To explain how indentation works, let's take a look at this piece of code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't have to worry about how &lt;code&gt;if&lt;/code&gt; statements works for now, the goal is to understand how indentation affects codes in Python.&lt;/p&gt;

&lt;p&gt;Indentation in python is something you will always come across. For beginners and even experienced programmers, indentation is something you will most likely find frustrating when you're just getting started with Python. It's advisable to take note of this.&lt;/p&gt;

&lt;p&gt;Notice in the code above that, on line 4, I added a little space before the print(x) statement.&lt;/p&gt;

&lt;p&gt;Most of the time, you will hear people say indent, this is what they mean. I indented on line 4, and what this does is that it tells python that the code is still a part of line 3. That is, this is a block of code.&lt;/p&gt;

&lt;p&gt;Python does not support the use of braces to indicate blocks of code. So the way you write a block of code is by line indentation.&lt;/p&gt;

&lt;p&gt;The way you indent code varies, you either hit the space bar four times or use the Tab key to make an indent.&lt;/p&gt;

&lt;p&gt;Looking at our example, the greater than operator, &lt;code&gt;&amp;gt;&lt;/code&gt;, checks if &lt;code&gt;x&lt;/code&gt; is greater than &lt;code&gt;2&lt;/code&gt;. &lt;code&gt;x&lt;/code&gt; will be printed only if it is greater than &lt;code&gt;2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now if you're wondering how this program works,&lt;/p&gt;

&lt;p&gt;On line 1, &lt;code&gt;3&lt;/code&gt; is assigned to &lt;code&gt;x&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;On line 2, &lt;code&gt;5&lt;/code&gt; is assigned to &lt;code&gt;y&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Line 3 checks if x is greater than 2, which is True, so &lt;code&gt;x&lt;/code&gt; will be printed out.&lt;/p&gt;

&lt;p&gt;Let's assume we had something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;x&lt;/code&gt; will not be printed out, because it is less than &lt;code&gt;4&lt;/code&gt;. But the last line will be executed since it's not inside the block of code. &lt;code&gt;5&lt;/code&gt; will be printed out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-line statements
&lt;/h2&gt;

&lt;p&gt;All statements in python ends with a new line but there's a way to tell python that more than one line of code should be treated as one.&lt;/p&gt;

&lt;p&gt;Let's say we have&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last line can be written as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; \
         &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; \
         &lt;span class="n"&gt;z&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The backslash is used to perform this task.&lt;/p&gt;

&lt;p&gt;After running this program, &lt;code&gt;6&lt;/code&gt; should be printed out.&lt;/p&gt;

&lt;p&gt;Since we're writing a very small program, this is not so useful because everything looks okay on a single line.&lt;/p&gt;

&lt;p&gt;Having this knowledge will become really useful by the time you start writing longer programs where you will need to split a line of code into multiple lines for a better readability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multiple statements on a single line
&lt;/h2&gt;

&lt;p&gt;The semicolon can be used to write multiple statements on a single line. There's an exception. The statements should not start a new block of code.&lt;/p&gt;

&lt;p&gt;Let's say we have&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 2
y = 5
print(x + y)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can be also written as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running this program, &lt;code&gt;7&lt;/code&gt; should be printed out.&lt;/p&gt;

&lt;p&gt;However, it is not recommended to do this often as it can make the code less readable and harder to understand. It is better to write each statement on a separate line for better clarity and easier maintenance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Python has a Syntax which allows for faster readability and clarity, and in this article, I have covered some of the essential concepts. &lt;/p&gt;

&lt;p&gt;I covered topics on white spaces, how indentation works, how to use comments, how to write multi-line statements and multiple statements on a single line. &lt;/p&gt;

&lt;p&gt;While this is just the tip of the iceberg, understanding these concepts is a crucial step in becoming a proficient Python programmer.&lt;/p&gt;

&lt;p&gt;That's it for this article. I hope you find it helpful as much as I do.&lt;/p&gt;

&lt;p&gt;If you have any question or you think there's something you want me to add to this article or upcoming ones, please drop them in the comment section below.&lt;/p&gt;

&lt;p&gt;And If you like this article, please follow for more and don't forget to share with others who might find it helpful.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python Tutorial: Numbers - A beginner's Guide to Understanding Numeric Data Types in Python</title>
      <dc:creator>David Fabusuyi </dc:creator>
      <pubDate>Sat, 13 May 2023 09:47:38 +0000</pubDate>
      <link>https://dev.to/techwithdavid/python-tutorial-numbers-a-beginners-guide-to-understanding-numeric-data-types-in-python-379b</link>
      <guid>https://dev.to/techwithdavid/python-tutorial-numbers-a-beginners-guide-to-understanding-numeric-data-types-in-python-379b</guid>
      <description>&lt;p&gt;Data in Python takes the form of objects, either those that Python comes with pre-built or those that we generate using Python tools or other programming languages. As a result, the foundation of every Python program is an object.&lt;/p&gt;

&lt;p&gt;We'll examine Python's numeric type in-depth in this tutorial. Numerical Literals, arithmetic operators, comparison operators, built-in numeric tools (functions and modules), operator precedence, and other ideas will be covered.&lt;/p&gt;

&lt;h2&gt;
  
  
  TABLE OF CONTENTS
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Fundamentals of Numeric Types&lt;/li&gt;
&lt;li&gt;Numeric Literals&lt;/li&gt;
&lt;li&gt;Built-in Numeric Tools&lt;/li&gt;
&lt;li&gt;
Python Expression Operators

&lt;ul&gt;
&lt;li&gt;Arithmetic Operators&lt;/li&gt;
&lt;li&gt;Operator Precedence&lt;/li&gt;
&lt;li&gt;Incrementing and Decrementing values&lt;/li&gt;
&lt;li&gt;Comparison Operators&lt;/li&gt;
&lt;li&gt;Built-in Functions&lt;/li&gt;
&lt;li&gt;Built-in Modules&lt;/li&gt;
&lt;li&gt;Math Module&lt;/li&gt;
&lt;li&gt;Random Module&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Number Display Formats&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Fundamentals of Numeric Types
&lt;/h2&gt;

&lt;p&gt;In Python, floats and integers are most frequently used to represent numeric data types. Python does, however, include a range of numeric built-ins and modules for more difficult operations, including complex numbers, rational fraction numbers, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Numeric Literals
&lt;/h2&gt;

&lt;p&gt;As previously mentioned, Python's primary methods for representing numbers are integers and floats. Integers are whole numbers that can either be positive or negative, but floats, also known as floating-point numbers, are numbers that contain a fractional part.&lt;/p&gt;

&lt;p&gt;This tutorial will mostly focus on integers and floats even though Python also allows us to create integers using hexadecimal, octal, and binary literals.&lt;/p&gt;

&lt;p&gt;For a better grasp of the fundamental numerical Literals, see the example below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;num_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="c1"&gt;# An Integer
&lt;/span&gt;&lt;span class="n"&gt;num_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.23&lt;/span&gt; &lt;span class="c1"&gt;# A floating-point number
&lt;/span&gt;&lt;span class="n"&gt;num_3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;3j&lt;/span&gt; &lt;span class="c1"&gt;# A complex number literal 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Built-in Numeric Tools
&lt;/h2&gt;

&lt;p&gt;Since number types are objects, Python offers a collection of tools for manipulating them. These tools include Expression operators (Arithmetic operators, comparison operators, etc.), Built-in mathematical functions (abs, round, pow, int, etc.), Built-in modules (math, random, etc.)&lt;/p&gt;

&lt;p&gt;In the next section and a few more sections, we will see some of these built-in numeric tools in action. &lt;/p&gt;

&lt;p&gt;To start with, let's see how to work with expression operators.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python Expression Operators
&lt;/h2&gt;

&lt;p&gt;An expression is basically a combination of objects and operators that are used to manipulate these objects. &lt;/p&gt;

&lt;p&gt;In the case of numbers, an expression is a combination of numbers and operators that computes a value when executed by Python. &lt;/p&gt;

&lt;p&gt;Expressions are represented using the normal mathematical operator symbols and notations.&lt;/p&gt;

&lt;p&gt;Listed below are some of the basic expression operators available in Python.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arithmetic Operators&lt;/li&gt;
&lt;li&gt;Comparison Operators&lt;/li&gt;
&lt;li&gt;Object identity tests&lt;/li&gt;
&lt;li&gt;Membership tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding Python's numeric objects, expressions, and most likely all other types of objects is best accomplished through using them. Let's begin using these expressions right away so that we can move on&lt;/p&gt;

&lt;h3&gt;
  
  
  Arithmetic Operators
&lt;/h3&gt;

&lt;p&gt;Arithmetic operators are used to perform the normal, basic math.&lt;/p&gt;

&lt;p&gt;Listed below are the arithmetic operators available in Python&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Addition&lt;/li&gt;
&lt;li&gt;Subtraction&lt;/li&gt;
&lt;li&gt;Multiplication&lt;/li&gt;
&lt;li&gt;Division (True and Floor)&lt;/li&gt;
&lt;li&gt;Exponentiation (Power)&lt;/li&gt;
&lt;li&gt;Modulus (Remainder)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code below illustrates how these operators are used. I've also added comments also to give explanations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Addition 
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Adds 3 and 2 together and prints 5
&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; 

&lt;span class="c1"&gt;# Subtraction
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Subtracts 2 from 3 and prints 1
&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="c1"&gt;# Multiplication
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Multiplies 3 by 2 and prints 6
&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;

&lt;span class="c1"&gt;# Division
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Performs true division and prints 1.5
&lt;/span&gt;&lt;span class="mf"&gt;1.5&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Performs floor division and prints 1.0
&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;# Fractional part gets truncated
&lt;/span&gt;
&lt;span class="c1"&gt;# Exponentiation
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Raises 3 to the power of 2 and prints 9
&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;

&lt;span class="c1"&gt;# Remainder
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints the remainder of dividing 3 by 2 using the Modulus operator
&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, there are a few things to note during division.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The single forward slash &lt;code&gt;(x / y)&lt;/code&gt; performs true division, regardless of types. That is, it keeps remainders either you're dividing integers or floating-point numbers.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 1.0
&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 1.5
&lt;/span&gt;&lt;span class="mf"&gt;1.5&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 1.5
&lt;/span&gt;&lt;span class="mf"&gt;1.5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The double forward slashes &lt;code&gt;(x // y)&lt;/code&gt; performs floor division, regardless of types. This operator always truncates fractional remainders to their floor, either you're dividing integers or floating-point numbers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;//&lt;/code&gt;, when used, truncates the remainder and returns an integer for integer operands, or returns a float if any operand is a float.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 1
&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 1.0
&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Operator Precedence
&lt;/h3&gt;

&lt;p&gt;A more complex expression can be created in Python by combining multiple operators. For instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What will be the answer when these alphabets (variables) are replaced by real numbers? For instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may be expecting that python will carry out this operation from left to right and &lt;code&gt;1&lt;/code&gt; will be printed out.&lt;/p&gt;

&lt;p&gt;Well, that's not how it works. &lt;/p&gt;

&lt;p&gt;So how does python know which operation to perform first? This is where &lt;strong&gt;operator precedence&lt;/strong&gt; comes in. &lt;/p&gt;

&lt;p&gt;There are some rules known as precedence rules, which helps python to group complex expressions into parts. This rule determines which part of the expression is executed first.&lt;/p&gt;

&lt;p&gt;These parts of the expression is executed in order of precedence from the highest to the lowest. That is, parts with an operator which have a higher precedence is executed first.&lt;/p&gt;

&lt;p&gt;The following operators are arranged in their increasing order of precedence.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Addition -&amp;gt; Subtraction -&amp;gt; Multiplication -&amp;gt; Modulus (Remainder) -&amp;gt; Division&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;3.0&lt;/code&gt; is printed out.&lt;/p&gt;

&lt;p&gt;Division first, followed by remainder, multiplication, subtraction and addition.&lt;/p&gt;

&lt;p&gt;Trace the steps through this operation to gain a better understanding of how operator precedence works.&lt;/p&gt;

&lt;p&gt;However, you can manually instruct Python as to which portion of an expression should be executed first.&lt;/p&gt;

&lt;p&gt;This is done by grouping parts of expressions within parentheses. This way, you'll override Python's precedence rules.&lt;/p&gt;

&lt;p&gt;For instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 4
&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wrapping &lt;code&gt;4+2&lt;/code&gt; in parentheses will force Python to evaluate the addition operation first, even though division has a higher precedence.&lt;/p&gt;

&lt;h3&gt;
  
  
  Incrementing and Decrementing values
&lt;/h3&gt;

&lt;p&gt;The idea of working with arithmetic operators can be used to increment and decrement values.&lt;/p&gt;

&lt;p&gt;For instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="c1"&gt;# Incrementing 
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;# Adds 1 to x
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 2
&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="c1"&gt;# Line 4 can also be written as 
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="c1"&gt;# Decrementing 
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;# or
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These forms of incrementing/decrementing can also be used with other operators.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;

&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="c1"&gt;# x = x * 2. Prints 12 (6 * 2)
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;/=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="c1"&gt;# x = x / 3. Prints 4.0 (12 / 3)
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;%=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="c1"&gt;# x = x % 2. Prints 0.0 (4 % 2)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Decrementing or incrementing values comes in handy mostly when working with loops.&lt;/p&gt;

&lt;p&gt;Modulus (Remainder) are mostly used to check if a value is even or odd.&lt;/p&gt;

&lt;p&gt;For instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 0 because 2 divides 2 completely 
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints 1
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even numbers will return &lt;code&gt;0&lt;/code&gt; when they are divided by 2. &lt;br&gt;
Odd numbers will return &lt;code&gt;1&lt;/code&gt; when they are divided by 2.&lt;/p&gt;

&lt;p&gt;You'll see these operators and operator expression a lot more in future topics when you start to write more complex programs. However, it is important that you're given a basic introduction.&lt;/p&gt;
&lt;h3&gt;
  
  
  Comparison Operators
&lt;/h3&gt;

&lt;p&gt;Python also supports comparison of numbers. Comparison Operators compares the relative magnitudes of their operands and returns a Boolean as a result of the comparison.&lt;/p&gt;

&lt;p&gt;Listed below are the comparison operators available in Python&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Equal to ( == )&lt;/li&gt;
&lt;li&gt;Not equal ( != )&lt;/li&gt;
&lt;li&gt;Greater than ( &amp;gt; )&lt;/li&gt;
&lt;li&gt;Less than ( &amp;lt; )&lt;/li&gt;
&lt;li&gt;Greater than or Equal to ( &amp;gt;= )&lt;/li&gt;
&lt;li&gt;Less than or equal to ( &amp;lt;= )&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The best way to understand how these operators work is by seeing them in action.&lt;/p&gt;

&lt;p&gt;The code below illustrates how these operators work. I've also added comments explaining how they work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Equal
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints True since 2 is equal to 2
&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints False because 3 is not equal to 2
&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;

&lt;span class="c1"&gt;# Not equal
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints False because 2 is equal to 2
&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints True
&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="c1"&gt;# Greater than
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints False
&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints True
&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="c1"&gt;# Less than
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints False
&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints True
&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="c1"&gt;# Greater or equal to
# Checks if a number is greater than or equal to the other
# Returns True if at least one condition is True
# Returns False if both conditions are False
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints True because 2 is equal to 2
&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints True
&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints False
&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;

&lt;span class="c1"&gt;# Less than or equal to
# Checks if a number is lesser than or equal to the other
# Returns True if at least one condition is True
# Returns False if both conditions are False
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints True
&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints False
&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints True
&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Interestingly, Comparison operators can also be combined together to perform more complex tests. &lt;/p&gt;

&lt;p&gt;For instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Print True because a &amp;lt; b and b &amp;lt; c
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Prints False because a &amp;lt; b but b is not &amp;gt; c
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Built-in Functions
&lt;/h3&gt;

&lt;p&gt;In addition to the built-in expression operators, Python also provides built-in functions for manipulating numeric object types. &lt;/p&gt;

&lt;p&gt;Some of these functions include; &lt;code&gt;pow()&lt;/code&gt;, &lt;code&gt;abs()&lt;/code&gt;, &lt;code&gt;min()&lt;/code&gt;, &lt;code&gt;max()&lt;/code&gt;, &lt;code&gt;round()&lt;/code&gt;, and &lt;code&gt;int()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's see these functions in action.&lt;/p&gt;

&lt;p&gt;The code below illustrates how these built-in functions are used in python. I've also added comments to give explanations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Absolute value
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Prints 3
&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="c1"&gt;# Exponentiation (power)
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 3 ** 3. Prints 9
&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;

&lt;span class="c1"&gt;# Round
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.567&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Prints 4
&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;

&lt;span class="c1"&gt;# Minimum value
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Prints 3
&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="c1"&gt;# Maximum value
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Prints 5
&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;

&lt;span class="c1"&gt;# Summation
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Adds all the values and prints 6
&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;

&lt;span class="c1"&gt;# Truncate
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.47&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Prints 3
&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Built-in Modules
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;math&lt;/code&gt; and &lt;code&gt;random&lt;/code&gt; modules provided by Python, can also be used for numeric processing. These modules contains functions that can be used to perform certain operations on numbers.&lt;/p&gt;

&lt;p&gt;These modules must be imported first before they can be used.&lt;/p&gt;

&lt;p&gt;Let's see some examples of how these modules work&lt;/p&gt;

&lt;h4&gt;
  
  
  Math module
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;math&lt;/code&gt; module contains functions that are used to process numeric object types.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;math&lt;/span&gt;

&lt;span class="c1"&gt;# Common constants
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="mf"&gt;3.141592653589793&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mf"&gt;2.718281828459045&lt;/span&gt;

&lt;span class="c1"&gt;# Square root
&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;49&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mf"&gt;7.0&lt;/span&gt;

&lt;span class="c1"&gt;# Floor
&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.56&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;3.56&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Floors to the next-lower integer
&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;

&lt;span class="c1"&gt;# Truncate decimal digits
&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.56&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;trunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;3.56&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Random module
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;random&lt;/code&gt; module is a built-in module which provides tools for picking a random floating-point number between &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt;, selecting a random integer between two numbers, and also for choosing an item at random from a sequence.&lt;/p&gt;

&lt;p&gt;Let's see an example of how this module works&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;random&lt;/span&gt;

&lt;span class="c1"&gt;# Picking a random floating-point number between 0 and 1
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="mf"&gt;0.812811807707059&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="mf"&gt;0.1516146750767553&lt;/span&gt;

&lt;span class="c1"&gt;# Selecting a random integer between two numbers 
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;randint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;randint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;randint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt;

&lt;span class="c1"&gt;# Choosing an item at random from a sequence 
&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'john'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'joe'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'smith'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="s"&gt;'ham'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'foo'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'spam'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="s"&gt;'joe'&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="s"&gt;'ham'&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="s"&gt;'foo'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Number Display Formats
&lt;/h2&gt;

&lt;p&gt;One last thing I'd like to show you is how to manually specify how numbers are displayed. To format a number for output, use the built-in format() function.&lt;/p&gt;

&lt;p&gt;To get a better understanding of this concept, see the code below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1234.56789&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1234.56789&lt;/span&gt;

&lt;span class="c1"&gt;# Two decimal places of accuracy 
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'0.2f'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Suitable when working with just one variable
&lt;/span&gt;&lt;span class="s"&gt;'1234.57'&lt;/span&gt;

&lt;span class="c1"&gt;# Another method
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'{:0.2f} | {:0.3f}'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Suitable when working with more than one variable 
&lt;/span&gt;&lt;span class="s"&gt;'1234.57 | 1234.568'&lt;/span&gt; &lt;span class="c1"&gt;# Rounds x to 2 decimal places of accuracy and y to 3 decimal places of accuracy 
&lt;/span&gt;
&lt;span class="c1"&gt;# Exponentiation notation
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'e'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# Change the f to e
&lt;/span&gt;&lt;span class="s"&gt;'1.234568e+03
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Python offers a range of numeric data types that allows for precise and efficient numerical computations. These data types include integers, floating-point numbers, complex numbers, and more. &lt;/p&gt;

&lt;p&gt;Python's built-in numeric data types make it a powerful tool for scientific computing, data analysis, and many other applications and in this article we've taken a look at how numbers works in Python.&lt;/p&gt;

&lt;p&gt;In the course of writing this article, I've learned a lot and I hope you do too.&lt;/p&gt;

&lt;p&gt;That's it for this article. If you have any question or you think there's something you want me to add to this article or upcoming ones, please drop them in the comment section below.&lt;/p&gt;

&lt;p&gt;And If you like this article, please follow for more and don't forget to share with others who might find it helpful.&lt;/p&gt;

&lt;p&gt;Finally, I'd like to connect with you on &lt;a href="https://www.linkedin.com/in/fabusuyi-olasunkanmi"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://www.twitter.com/techwithdavid"&gt;Twitter&lt;/a&gt; | &lt;a href="https://github.com/techwithdavid"&gt;GitHub&lt;/a&gt; | &lt;a href="https://www.youtube.com/@techwithdavid"&gt;YouTube&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks for reading. See you in the next one!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python Tutorial: Introduction to Python Programming</title>
      <dc:creator>David Fabusuyi </dc:creator>
      <pubDate>Mon, 17 Apr 2023 03:43:30 +0000</pubDate>
      <link>https://dev.to/techwithdavid/python-tutorial-introduction-to-python-programming-1i4l</link>
      <guid>https://dev.to/techwithdavid/python-tutorial-introduction-to-python-programming-1i4l</guid>
      <description>&lt;h2&gt;
  
  
  TABLE OF CONTENTS
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is Python?&lt;/li&gt;
&lt;li&gt;Who Developed Python?&lt;/li&gt;
&lt;li&gt;Why Is Python Used by many people?&lt;/li&gt;
&lt;li&gt;What are the Advantages of using Python?&lt;/li&gt;
&lt;li&gt;What's the downside of using Python?&lt;/li&gt;
&lt;li&gt;What can I do with Python?&lt;/li&gt;
&lt;li&gt;Some of the Companies that Use Python?&lt;/li&gt;
&lt;li&gt;Careers with Python?&lt;/li&gt;
&lt;li&gt;What's an Interpreter?&lt;/li&gt;
&lt;li&gt;
Setting up your Programming environment

&lt;ul&gt;
&lt;li&gt;Python on Windows&lt;/li&gt;
&lt;li&gt;Python on macOS&lt;/li&gt;
&lt;li&gt;Python on Linux&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

How To Run Programs

&lt;ul&gt;
&lt;li&gt;The Interactive Prompt&lt;/li&gt;
&lt;li&gt;The IDLE User Interface&lt;/li&gt;
&lt;li&gt;Text Editors, Command lines and System files&lt;/li&gt;
&lt;li&gt;Creating UNIX Executable Scripts&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Final Thoughts&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Are you completely new to python or programming? or you've gained some programming knowledge and you will like to learn how the python programming language works, or let's say for some other reasons you want to learn to write python codes, here is a good place to start your adventure.&lt;/p&gt;

&lt;p&gt;In today's article and a few more series of articles, I'll go over most of the important topics in Python, from the fundamentals to more complex concepts.This article will feature practice examples, exercises, and quizzes to assist you in developing the muscle memory required to retain and apply the concepts you'll learn here in future projects.&lt;/p&gt;

&lt;p&gt;Today's article will focus primarily on a detailed introduction to python, and some of the topics includes what python is, why it was created, who created it, why it is used by so many developers and why it is a very good language to learn, it's strength and downsides, it's use cases, how python run programs, how you can run programs, as well as it's installation and a simple python script.&lt;/p&gt;

&lt;p&gt;Let's get right into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Python?
&lt;/h2&gt;

&lt;p&gt;Python is a general-purpose, interpreted, and high-level language. It is easy to learn yet so powerful.&lt;/p&gt;

&lt;p&gt;Python as an interpreted language means that python programs are executed directly by what is referred to as an interpreter. The interpreter abstracts away all the underlying compilation process, allowing for speedier testing and development. In lower level languages like C, these compilation processes are usually done step by step before an executable file is generated. The interpreter will be explained more in-depth later in this article.&lt;/p&gt;

&lt;p&gt;Python is an high-level language because it supports simplicity and understandibility. Python is designed in a way that is easy to read. This can make Python codes easier to write and maintain as well as debug, especially for beginners or developers with little programming experience.&lt;/p&gt;

&lt;p&gt;In short Python was created with simplicity in mind.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who Developed Python?
&lt;/h2&gt;

&lt;p&gt;Python was developed by Guido van Rossum between the 1980 and 1991 as a successor to the ABC programming language. It's first stable release was released in 1991 as python 0.9.0.&lt;/p&gt;

&lt;p&gt;Some of the programming languages that influenced python includes ABC, Ada, ALGOL 68, APL, C, C++, CLU, Dylan, Haskell, Icon, and some other languages.&lt;/p&gt;

&lt;p&gt;Python has influenced languages such as Ruby, Swift, Go, CoffeScript and Julia.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Is Python Used by many people?
&lt;/h2&gt;

&lt;p&gt;As a beginner, you should know why you want to learn a language. Sometimes, it might be a bad idea to jump into learning a programming language without thorough research on why you should learn it.&lt;/p&gt;

&lt;p&gt;Is it because of the ease that comes with learning it? or because it has a huge community ready to provide resources and support during the learning process, or ofcourse you want to make money with it. Whichever reason it is, having a reason will go a really long way.&lt;/p&gt;

&lt;p&gt;Looking at Python, all the 3 reasons listed above are applicable. I'll explain the already listed reasons and some other reasons why people use python, in details.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ease of use&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Python was designed with simplicity in mind, as already stated above. It's easy for beginners to approach python since it's syntax are readable just like English. Does it mean Python is made just for simple task? The short answer is No. Python is not just for simple tasks. Rather, it makes tasks simple by its ease of use and flexibility. Python has a simple feature set, but it also allows for building more complex softwares as needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Support and community&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;There's a large community of python developers around the world. As a result, you will receive the best possible assistance both when you first begin learning Python and as you grow. There is no reason to feel isolated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Developer productivity&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Python allows developers to get more complicated tasks done in lesser time with fewer lines of codes. It allows for a great development speed because of it's simple syntax, dynamic typing, built-in tools and absence of manual compilation steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Portability&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;A Python program that works well without any error on a window OS will most likely work without any errors on a Linux OS. It's just a matter of copying codes between these machines. The efficiency of programs written in low-level languages like C depends on the operating system on which they are run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Libraries support&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Python comes with a large collection of libraries often regarded as standard libraries. Python also support a vast collection of third-party libraries. These libraries provide functionalities which makes it possible to use Python to solve a wide variety of tasks such as web development, game development, data analysis, AI and machine learning, to name a few.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the Advantages of using Python?
&lt;/h2&gt;

&lt;p&gt;This is one of the questions often asked by developers. It is worth knowing some of python's features which makes it stands out.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It's free.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's object-oriented.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's portable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's easy to learn and write.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's interpreted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It supports automatic memory management.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It can be easily integrated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It's interactive.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What's the downside of using Python?
&lt;/h2&gt;

&lt;p&gt;The only downside of using python is the execution speed. Python is not as fast as compiled languages like C or C++. But this is not always a problem. Let's talk about this.&lt;/p&gt;

&lt;p&gt;Whenever you compile a program written in a lower level language, let's say C, the executable file is always in a binary form containing 0s and 1s. But in Python, the standard implementation of python known as CPython, compiles source codes to an intermediate form called byte codes and then interprets the byte code.&lt;/p&gt;

&lt;p&gt;So, because Python programs are not compiled all the way to binary machine code, some programs will run slowly.&lt;/p&gt;

&lt;p&gt;Why is this always not a problem? The speed of your programs depends on the kind of programs you're writing and moreover, a lot of optimization have been done to make python programs run at C speed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can I do with Python?
&lt;/h2&gt;

&lt;p&gt;Python being a general-purpose language, the possibilities of what can be done with it is endless. Listed below are some categories of real-world tasks that can be completed with python&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Web development&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Software programming&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scripting&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Component Integration&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Database programming&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Game programming&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scientific programming&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Some of the Companies that Use Python?
&lt;/h2&gt;

&lt;p&gt;Python is very high in demand, and some of the major companies are seeking experienced python developers to develop softwares, build websites and applications, or to work with machine learning and AI tools. Python is a general-purpose language, as such, the possibilities of what can be done with it is endless. Listed below are some of the companies that make use of python&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Google&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;YouTube&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Intel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;NASA&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PayPal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Facebook&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IBM&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Amazon&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Netflix&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pinterest&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;iRobot&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PMorgan Chase&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uber and many more&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Careers with Python?
&lt;/h2&gt;

&lt;p&gt;Learning Python is a good choice of career.&lt;/p&gt;

&lt;p&gt;Gaining enough knowledge on how the python programming language works, automatically opens up countless opportunities, that can help improve your standard of living. Listed below are some of the career options where Python is a key skill:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Web developer&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Full stack developer&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Python developer&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Game developer&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data analyst&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data scientist&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Machine learning Engineer&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What's an Interpreter?
&lt;/h2&gt;

&lt;p&gt;An interpreter is a software package that executes other programs. As stated earlier, the python interpreter abstracts away all the compilation process, allowing you to focus mainly on writing codes.&lt;/p&gt;

&lt;p&gt;After installing python, a few other packages gets installed with it, on your machine. These includes the interpreter and a large collection of support libraries which I've talked about earlier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up your Programming Environment
&lt;/h2&gt;

&lt;p&gt;Before you can start using Python on your machine, it must be properly installed, and a more recent version must be installed. Python's most recent version is 3.11.3.&lt;/p&gt;

&lt;p&gt;Python, as a cross-platform programming language, operates on nearly all, if not all, operating systems. Does this imply that Python is available on all operating systems? The short answer is No. The long answer is that some operating systems, such as MacOS and Linux, come with Python installed, but others, such as Windows, do not.&lt;/p&gt;

&lt;p&gt;In that case, I'll show you how to setup python on these 3 major operating systems; windows, Mac, and Linux.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python on Windows
&lt;/h2&gt;

&lt;p&gt;Python is not always included with Windows. You must download and install it.&lt;/p&gt;

&lt;p&gt;But, before you proceed with the download, you should check if at all python is installed. Open the command window.&lt;/p&gt;

&lt;p&gt;To do this,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to the start menu.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type in &lt;code&gt;cmd&lt;/code&gt; and open the command prompt.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the terminal, type &lt;code&gt;python --version&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8nwmkk2z1vm1ypcqsrni.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8nwmkk2z1vm1ypcqsrni.jpeg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you get an error, python isn't installed. If it doesn't return an error, you also want to check if the installed version is still supported. If you see a version earlier than python 3.x.x, you need to download a more recent version.&lt;/p&gt;

&lt;p&gt;To download the latest version, Go to &lt;a href="https://python.org/downloads/" rel="noopener noreferrer"&gt;https://python.org/downloads/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should see a button for downloading the latest version of Python. Click the button, and the download will start automatically.&lt;/p&gt;

&lt;p&gt;After the download is complete, double click on the download file to start the installation. Make sure you select the option &lt;code&gt;Add Python to PATH&lt;/code&gt;, which will make it easier to configure your system correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python on macOS
&lt;/h2&gt;

&lt;p&gt;Python is pre-installed on most macOS systems, however it is most likely an outdated version that is unsuitable for learning.&lt;/p&gt;

&lt;p&gt;You can as well check the version first before downloading it.&lt;/p&gt;

&lt;p&gt;To download the latest version of python on macOS, Go to &lt;a href="https://python.org/downloads/" rel="noopener noreferrer"&gt;https://python.org/downloads/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should see a button for downloading the latest version of Python. Click the button, and the download will start automatically.&lt;/p&gt;

&lt;p&gt;After the download is complete, double click on the download file to start the installation. Make sure you select the option &lt;code&gt;Add Python to PATH&lt;/code&gt; which will make it easier to configure your system correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python on Linux
&lt;/h2&gt;

&lt;p&gt;Since Linux systems are designed for programming, python is already installed on it. But you should check if it's python3.&lt;/p&gt;

&lt;p&gt;Open the terminal window, let's say you're using Ubuntu, type in &lt;code&gt;python3&lt;/code&gt;. You should get something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7cw0tfkouj5wyqf1fln5.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7cw0tfkouj5wyqf1fln5.jpeg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the screenshot above, you can see i have python 3.8.10 installed and this is enough to learn with.&lt;/p&gt;

&lt;h2&gt;
  
  
  How To Run Programs
&lt;/h2&gt;

&lt;p&gt;At this point, I assume that you already have Python installed, and it's time to start writing some Python programs.&lt;/p&gt;

&lt;p&gt;Python applications can be run in a variety of ways. In this section of the article, I will walk you through some of the most common ways to run Python programs. I will describe what it means to run Python interactively, how to build and run Python scripts from the terminal, how to use Python's IDLE, and how to use graphical user interfaces (GUIs).&lt;/p&gt;

&lt;h2&gt;
  
  
  The Interactive Prompt
&lt;/h2&gt;

&lt;p&gt;The simplest way to run python is by using the interactive prompt. The interactive prompt looks something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyp6nhdp4sg8k1x2eul51.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyp6nhdp4sg8k1x2eul51.jpeg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It allows you to type one line of code at a time. So how do you start the interactive prompt? It's simple. But you should know that the way you start the interactive prompt differs slightly with operating systems. The most common way is by typing &lt;code&gt;python&lt;/code&gt; on the command prompt.&lt;/p&gt;

&lt;p&gt;On windows, type &lt;code&gt;python&lt;/code&gt; to start the interactive prompt.&lt;/p&gt;

&lt;p&gt;It's thesame for macOS and Linux, typing &lt;code&gt;python3&lt;/code&gt; will start the interactive prompt.&lt;/p&gt;

&lt;p&gt;Let's talk on how you can run programs with the interactive prompt&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; indicates that you should type in your codes here. When working interactively, you use the &lt;code&gt;Enter&lt;/code&gt; Key to display the results of what you've typed and also to go to a new line.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpl0io36bsqb1iqu2jk8.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmpl0io36bsqb1iqu2jk8.jpeg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the above image, you can see that the interactive prompt started when I typed &lt;code&gt;python&lt;/code&gt;. I used &lt;code&gt;python&lt;/code&gt; because I'm working on a windows OS.&lt;/p&gt;

&lt;p&gt;You don't need to worry about the &lt;code&gt;print&lt;/code&gt; statement for now. All you need to know is that it prints out values to the terminal.&lt;/p&gt;

&lt;p&gt;The first &lt;code&gt;print&lt;/code&gt; statement prints out the string &lt;code&gt;Hello, world!&lt;/code&gt; to the terminal. We'll talk more on strings in coming lessons.&lt;/p&gt;

&lt;p&gt;The result of what I typed is printed below the &lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; sign.&lt;/p&gt;

&lt;p&gt;Next, I assigned the string &lt;code&gt;David&lt;/code&gt; to the variable, &lt;code&gt;name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Notice that I also performed a basic arithmetic in the interactive prompt.&lt;/p&gt;

&lt;p&gt;The python's interactive prompt is called an interactive prompt for a reason. You get your results on the go. This is what makes it interactive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There are few things to note when using the interactive prompt&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The interactive prompt doesn't save your code in a file. Meaning once you close the interactive prompt, you can't access the codes you've written already. This is why the interactive prompt is a perfect place to experiment with the language.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You'll probably want to run a piece of code without having to create a new file, this is a good situation to use the interactive prompt.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The print statement is not necessarily needed. Since the interactive prompt runs and prints the result of an expression automatically, you do not need to use the print statement when working with it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The interactive prompt runs one statement at a time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can't copy and paste multiple lines of code into the interactive prompt. Trying this will return a SyntaxError. There's a catch, if there's a blank line after each statement, it will run without any error.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To exit the the interactive prompt, Type in &lt;code&gt;exit()&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The IDLE User Interface
&lt;/h2&gt;

&lt;p&gt;Up until this moment, you've been working from the terminal and it will be nice if you can work with something a bit more visual.&lt;/p&gt;

&lt;p&gt;IDLE is a standard environment from writing python programs. It comes installed with python and it is usually refered to as integrated development environment.&lt;/p&gt;

&lt;p&gt;The IDLE is a GUI that lets you write, edit, open and debug python programs. It looks something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffpkvy573f4m1dox5qzcf.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffpkvy573f4m1dox5qzcf.jpeg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;There are few things to know about the IDLE&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You can save your codes into a file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You must add &lt;code&gt;.py&lt;/code&gt; when saving your files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There's a button to run programs after they are written.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IDLE is a python program that uses the standard library's tkinter GUI toolkit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can customize the IDLE.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Text Editors, Command lines and System files
&lt;/h2&gt;

&lt;p&gt;The interactive prompt is a good environment to write codes, but it is only appropriate for tiny programs such as a fast experiment or test. When it comes to building huge programs, using the interactive prompt becomes a major issue. There is a better way to do this.&lt;/p&gt;

&lt;p&gt;Using text editors like vi, emacs, sublime text, VSCode and others, you can write programs in files and run then on the command line.&lt;/p&gt;

&lt;p&gt;Let's see how this works.&lt;/p&gt;

&lt;p&gt;One of my favorite text editor is vi. It's a shell-based editor used on the command. I have a file created already, and this file simply prints out Hello, world to the command line, and I have this program saved in a file named &lt;code&gt;hello.py&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can run this file by typing &lt;code&gt;python hello.py&lt;/code&gt;. Make sure you're in the right directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmkvbhy2xz2dcsxi7zz3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpmkvbhy2xz2dcsxi7zz3.jpeg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are a few things you should know&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The files where programs are kept are sometimes called modules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can access these files anytime you want.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure to type the name the file with the correct extension. Use &lt;code&gt;python hello.py&lt;/code&gt; not &lt;code&gt;python hello&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You will need to download and install a text editor yourself, unless you are working on a UNIX-like environment (e.g. Linux), in which case vi is already installed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating UNIX Executable Scripts
&lt;/h2&gt;

&lt;p&gt;In Linux, or any UNIX-like environment, you can turn python files into executable scripts.&lt;/p&gt;

&lt;p&gt;Executable scripts has two main attributes which are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first line usually starts with &lt;code&gt;#!&lt;/code&gt; commonly referred to as Hashbang or Shebang followed by the path to the python interpreter on your machine. I have a file created with the following lines of code in it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;#!/usr/bin/python3
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello, world&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;These files are usually granted &lt;code&gt;executable&lt;/code&gt; permissions. The &lt;code&gt;chmod&lt;/code&gt; command in Linux is used to set permissions for directories and files. I have a file named &lt;code&gt;hello.py&lt;/code&gt; already.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Typing &lt;code&gt;chmod +x hello.py&lt;/code&gt; will make the file an executable one. Make sure you're in the right directory.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;x&lt;/code&gt; means &lt;code&gt;execute&lt;/code&gt;. Other permission mode are &lt;code&gt;r&lt;/code&gt; for &lt;code&gt;read&lt;/code&gt; and &lt;code&gt;w&lt;/code&gt;for &lt;code&gt;write&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To run this executable file, simply type, &lt;code&gt;./hello.py&lt;/code&gt; or &lt;code&gt;./hello&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbo5931neazjltk58km1x.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbo5931neazjltk58km1x.jpeg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Python is a really good choice of Programming language to learn, and in this article, I've given a well-detailed introduction to Python. I've worked you through the overview of python, how programs are run, how to install and Setup python, as well as how to run programs.&lt;/p&gt;

&lt;p&gt;In the course of writing this article, I've learned a lot and I hope you do too.&lt;/p&gt;

&lt;p&gt;That's it for this article. If you have any question or you think there's something you want me to add to this article or upcoming ones, please drop them in the comment section below.&lt;/p&gt;

&lt;p&gt;And If you like this article, please follow for more and don't forget to share with others who might find it helpful.&lt;/p&gt;

&lt;p&gt;Finally, I'd like to connect with you on &lt;a href="https://www.linkedin.com/in/fabusuyi-olasunkanmi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://www.twitter.com/techguy_daveed" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; | &lt;a href="https://github.com/techwithdavid" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; | &lt;a href="https://www.youtube.com/@techwithdavid" rel="noopener noreferrer"&gt;YouTube&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to install and Setup Termux on Android: A beginner's guide</title>
      <dc:creator>David Fabusuyi </dc:creator>
      <pubDate>Tue, 14 Mar 2023 23:13:09 +0000</pubDate>
      <link>https://dev.to/techwithdavid/how-to-install-and-use-termux-on-android-a-beginners-guide-1h23</link>
      <guid>https://dev.to/techwithdavid/how-to-install-and-use-termux-on-android-a-beginners-guide-1h23</guid>
      <description>&lt;p&gt;Termux is a powerful Android terminal emulator that helps users reach the Linux command-line environment on their mobile phones. With Termux, users can install and run a wide variety of Linux tools and utilities, including text editors, programming languages, and system administration tools.&lt;/p&gt;

&lt;p&gt;This article will provide a beginner's guide on how to install and use Termux on an Android device. It will cover everything from the basic requirements for using Termux to advanced usage scenarios, and will include troubleshooting tips for common issues. By the end of this article, you will have a solid understanding of how to use Termux to access the power of Linux on your Android device.&lt;/p&gt;

&lt;p&gt;Let's get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Before getting into the installations of Termux, it is worth knowing the requirements for the installation.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Android version&lt;/u&gt;: The minimum Android version required for Termux to work properly is Android 7.0 and higher, this is because support have been stopped for Android 6 and 5 or below. Using a greater version of Android makes it possible to enjoy the best performance.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Permissions&lt;/u&gt;: During installation and running of Termux, certain permissions are required for proper functioning of the app. The permissions may vary depending on the version of Termux installed, but they basically include &lt;em&gt;storage&lt;/em&gt; and &lt;em&gt;network&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Storage access is required in order to read and write files, while Termux requires access to the device's network to in order to download packages and updates and to access remote servers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Download and Installation
&lt;/h2&gt;

&lt;p&gt;A quick note is that termux have been deprecated on playstore and no longer supported.&lt;/p&gt;

&lt;p&gt;Termux can be downloaded from F-Droid or GitHub either through the &lt;a href="https://github.com/termux/termux-app/releases" rel="noopener noreferrer"&gt;GitHub Releases&lt;/a&gt; or &lt;a href="https://github.com/termux/termux-app/actions/workflows/debug_build.yml" rel="noopener noreferrer"&gt;GitHub Build&lt;/a&gt; action workflows. This article will provide the steps on how to download the app from F-Droid, install and configure the app.&lt;/p&gt;

&lt;p&gt;Click &lt;a href="https://f-droid.org/repo/com.termux_118.apk" rel="noopener noreferrer"&gt;here&lt;/a&gt; to download the app. The download should start immediately. After that, install the app and open it. Your home page will look exactly like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi16di1csha8qtg8nq1s4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi16di1csha8qtg8nq1s4.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next crucial step is to upgrade termux to the latest builds. Run the command below to begin the process.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;apt update &amp;amp;&amp;amp; apt upgrade&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Accept all prompts and continue with the upgrade.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Firgx603ibobee262j97x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Firgx603ibobee262j97x.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And voila! You're done with the upgrade.&lt;/p&gt;

&lt;p&gt;The last step is to give termux access to read and write files. Termux by default does not have access to your phone's storage so permissions are needed to be set manually by running the command below.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;termux-setup-storage&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will be prompted to give termux access to your phone's storage. Click on &lt;strong&gt;Allow&lt;/strong&gt; to accept.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Termux is a really great tool to get developers into the world of Linux, and it is loved and preferred by many due to the fact that it is well customizable and it offers a lot of feature's that makes tasks really easier.&lt;/p&gt;

&lt;p&gt;This article has shown you how to get up and running with this great tool and if you're impressed by the content of the article, please stick around here for more.&lt;/p&gt;

&lt;p&gt;I'd like to connect with you on &lt;a href="https://twitter.com/techguy_daveed" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; | &lt;a href="http://www.linkedin.com/in/fabusuyi-olasunkanmi" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; | &lt;a href="https://github.com/techwithdavid" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; | &lt;a href="https://youtube.com/@techwithdavid" rel="noopener noreferrer"&gt;YouTube&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
