<?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>Forem: hrishikesh1990</title>
    <description>The latest articles on Forem by hrishikesh1990 (@hrishikesh1990).</description>
    <link>https://forem.com/hrishikesh1990</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%2F138512%2F39f101de-507b-4d1a-8845-90d625814e25.jpeg</url>
      <title>Forem: hrishikesh1990</title>
      <link>https://forem.com/hrishikesh1990</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hrishikesh1990"/>
    <language>en</language>
    <item>
      <title>I made 90+ high-quality illustration packs, totally free. Use it anywhere without attribution.</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Tue, 09 Aug 2022 12:36:00 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/i-made-90-high-quality-illustration-packs-totally-free-use-it-anywhere-without-attribution-4bh4</link>
      <guid>https://forem.com/hrishikesh1990/i-made-90-high-quality-illustration-packs-totally-free-use-it-anywhere-without-attribution-4bh4</guid>
      <description>&lt;p&gt;Hey everyone,&lt;/p&gt;

&lt;p&gt;I know that all of you are working on exciting products. To help you make them a bit more beautiful, I have made 500+ illustrations and 90+ high-quality illustration packs.&lt;/p&gt;

&lt;p&gt;As the title suggests, they are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Totally free&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;2. Absolutely need NO attribution :)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's the link: &lt;a href="https://flexiple.com/illustrations/"&gt;Scale&lt;/a&gt;!&lt;/p&gt;




&lt;h3&gt;
  
  
  What's new in Scale 3.0?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Select illustrations across 90+ illustration packs&lt;/li&gt;
&lt;li&gt;Now you can tweak 3 colors in the illustration&lt;/li&gt;
&lt;li&gt;Filter illustrations by Gender&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Have fun and buildd great projects!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is a while loop in Python?</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Mon, 25 Jul 2022 09:06:57 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/what-is-a-while-loop-in-python-26d7</link>
      <guid>https://forem.com/hrishikesh1990/what-is-a-while-loop-in-python-26d7</guid>
      <description>&lt;h3&gt;
  
  
  Table of Content
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  While loop in Python
&lt;/li&gt;
&lt;li&gt;  Single statement
&lt;/li&gt;
&lt;li&gt;  While loop with else statement
&lt;/li&gt;
&lt;li&gt;  Infinite while loop
&lt;/li&gt;
&lt;li&gt;  Closing Thoughts
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  While loop in Python
&lt;/h2&gt;

&lt;p&gt;The while loop in python is used to iterate over a block of code till the given condition is True. And as soon as the condition turns False, the next statement immediately after the loop is executed. It comes under indefinite iteration.&lt;/p&gt;

&lt;p&gt;Indefinite iteration means that the number of times the loop is supposed to be executed is not specified in advance.&lt;/p&gt;

&lt;h4&gt;
  
  
  Syntax of while loop in Python:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while expression:
       statement(s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The expression is executed in the Boolean context and if it is true, then the statement is executed. The expression is checked again when the loop is executed and will continue this process until the expression returns False.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count = 0
while (count &amp;lt; 5):
    count = count + 1
    print("Flexiple")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;p&gt;&lt;span id="section2"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flexiple
Flexiple
Flexiple
Flexiple
Flexiple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The expression count&amp;lt;5 is True till count=4 but as soon as the value of count becomes 5, the expression is not satisfied and the loop ends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Single statement
&lt;/h2&gt;

&lt;p&gt;Similar to the syntax of the if statement, if the while block consists of a single statement then it may be declared in the same line as the while header. And if there are multiple statements, then each statement can be separated by semicolons.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count = 0
while (count &amp;lt; 5): count += 1; print("Flexiple")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flexiple
Flexiple
Flexiple
Flexiple
Flexiple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  While loop with else statement in Python
&lt;/h2&gt;

&lt;p&gt;Python also allows programmers to use the else statement within the while loop. Like in the for loop, if the expression becomes false in the while loop, the else block is executed.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count = 0
while (count &amp;lt; 5):
    count = count + 1
    print("Flexiple")

else:  
    print("The else statement is executed.")   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flexiple
Flexiple
Flexiple
Flexiple
Flexiple
The else statement is executed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If the break control statement is used with the while loop, then the else statement will not be executed. As soon as the condition becomes false, the break statement will ignore the else statement and end the loop and the statement after the loop will be executed.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count = 0
while (count &amp;lt; 5):
    count = count + 1
    print("Flexiple")
    break

else:  
    print("The else statement is executed.")   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;p&gt;&lt;span id="section4"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flexiple
Flexiple
Flexiple
Flexiple
Flexiple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Infinite while loop in Python
&lt;/h2&gt;

&lt;p&gt;If the expression in the while loop never becomes False, then the loop will never end and it becomes an infinite while loop.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count = 1
while (count &amp;gt; 0):
    count = count + 1
    print("Flexiple")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;p&gt;&lt;span id="section5"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flexiple
Flexiple
Flexiple...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since the value of count will always be greater than 0, this loop will never end and will keep printing ‘Flexiple’ infinitely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing Thoughts
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we read about the while loop in Python and various situations where the while loop can be used. We can use the &lt;a href="//In%20this%20tutorial,%20we%20read%20about%20the%20while%20loop%20in%20Python%20and%20various%20situations%20where%20the%20while%20loop%20can%20be%20used.%20We%20can%20use%20the%20control%20statements%20with%20the%20while%20loop%20to%20change%20how%20the%20loop%20behaves.%20One%20can%20read%20about%20other%20Python%20concepts%20here."&gt;control statements&lt;/a&gt; with the while loop to change how the loop behaves. One can read about other Python concepts &lt;a href="https://flexiple.com/python/control-statements-in-python/"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Looping Statements in Python</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Wed, 13 Jul 2022 08:36:07 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/looping-statements-in-python-gj2</link>
      <guid>https://forem.com/hrishikesh1990/looping-statements-in-python-gj2</guid>
      <description>&lt;p&gt;The flow of the programs written in any programming language is sequential by default. The first statement in a function is executed first, followed by the second, and so on. There may be a situation when the programmer needs to execute a block of code several times. For this purpose, The programming languages provide various kinds of loops that are able to repeat some particular code numerous numbers of times. Here, we are going to talk about looping statements in Python.&lt;/p&gt;

&lt;p&gt;In a programming language, a looping statement contains instructions that continually repeat until a certain condition is reached. Read on to find out more about them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of Content
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Looping statements in Python
&lt;/li&gt;
&lt;li&gt;  For Loop
&lt;/li&gt;
&lt;li&gt;  While Loop
&lt;/li&gt;
&lt;li&gt;  Nested Loop
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Looping statements in Python
&lt;/h2&gt;

&lt;p&gt;Looping simplifies complicated problems into smooth ones. It allows programmers to modify the flow of the program so that rather than writing the same code, again and again, programmers are able to repeat the code a finite number of times.&lt;/p&gt;

&lt;p&gt;In Python, there are three different types of loops: for loop, while loop, and nested loop.&lt;br&gt;&lt;br&gt;
Here, we will read about these different types of loops and how to use them.&lt;/p&gt;

&lt;p&gt;&lt;span id="section2"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  For Loop
&lt;/h2&gt;

&lt;p&gt;The for loop is used in the case where a programmer needs to execute a part of the code until the given condition is satisfied. The for loop is also called a pre-tested loop. It is best to use for loop if the number of iterations is known in advance.&lt;/p&gt;

&lt;p&gt;In Python, there is no C style for loop, i.e., for (i=0; i&amp;lt;n; i++).&lt;/p&gt;

&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for variable in sequence:
    statements(s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
for i in range(0, a):
    print(i)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
1
2
3
4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The for loop runs till the value of i is less than a. As the value of i is 5, the loop ends.&lt;/p&gt;

&lt;h2&gt;
  
  
  While Loop
&lt;/h2&gt;

&lt;p&gt;The while loop is to be used in situations where the number of iterations is unknown at first. The block of statements is executed in the while loop until the condition specified in the while loop is satisfied. It is also called a pre-tested loop.&lt;/p&gt;

&lt;p&gt;In Python, the while loop executes the statement or group of statements repeatedly while the given condition is True. And when the condition becomes false, the loop ends and moves to the next statement after the loop.&lt;/p&gt;

&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;While condition:
       statement(s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count = 0
while (count &amp;lt; 5):   
    count = count + 1
    print("Flexiple")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;p&gt;&lt;span id="section4"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flexiple
Flexiple
Flexiple
Flexiple
Flexiple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The loop prints ‘Flexiple’ till the value of count becomes 5 and the condition is False.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nested Looping statements in Python
&lt;/h2&gt;

&lt;p&gt;The Python programming language allows programmers to use one looping statement inside &lt;a href="https://pynative.com/python-nested-loops/"&gt;another looping&lt;/a&gt; statement.&lt;/p&gt;

&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#for loop statement&lt;br&gt;
for variable in sequence:&lt;br&gt;
    for variable in sequence:&lt;br&gt;
       statement(s)&lt;br&gt;
       statement(s)
&lt;h1&gt;
  
  
  while loop statement
&lt;/h1&gt;

&lt;p&gt;while condition:&lt;br&gt;
    while condition:&lt;br&gt;
       statement(s)&lt;br&gt;
       statement(s)&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Input:&lt;br&gt;
&lt;/h4&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in range(1, 7):&lt;br&gt;
    for j in range(i):&lt;br&gt;
         print(i, end=' ')&lt;br&gt;
    print()&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Output:&lt;br&gt;
&lt;/h4&gt;
&lt;br&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1&lt;br&gt;
2 2&lt;br&gt;
3 3 3&lt;br&gt;
4 4 4 4&lt;br&gt;
5 5 5 5 5&lt;br&gt;
6 6 6 6 6 6&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Closing Thoughts&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we read about different looping statements in Python and their uses. The looping statements are used to repeat a specific block of code various number of times. One can read about other Python concepts &lt;a href="https://flexiple.com/python/control-statements-in-python/"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What are the Control Statements in Python?</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Thu, 07 Jul 2022 08:42:37 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/what-are-the-control-statements-in-python-4d6f</link>
      <guid>https://forem.com/hrishikesh1990/what-are-the-control-statements-in-python-4d6f</guid>
      <description>&lt;p&gt;In Python, Loops are used to iterate repeatedly over a block of code. In order to change the way a loop is executed from its usual behavior, control statements are used. Control statements are used to control the flow of the execution of the loop based on a condition. There are many types of control statements in Python and in this tutorial, we will discuss all of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Control Statements in Python
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Break statement
&lt;/li&gt;
&lt;li&gt;  Continue statement
&lt;/li&gt;
&lt;li&gt;  Pass statement
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Break statement
&lt;/h2&gt;

&lt;p&gt;The break statement in Python is used to terminate or abandon the loop containing the statement and brings the control out of the loop. It is used with both the while and the for loops, especially with nested loops (loop within a loop) to quit the loop. It terminates the inner loop and control shifts to the statement in the outer loop.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = “\n Please enter your age: ”
while True:
       age = input
       if age &amp;gt;= 18:
              break
       else:
             print (“You’re not eligible to vote”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Please enter your age: 17 You’re not eligible to vote
Please enter your age: 18
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above example, if the age entered is equal to or more than 18, it breaks out of the loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continue statement
&lt;/h2&gt;

&lt;p&gt;When a program encounters a continue statement in Python, it skips the execution of the current iteration when the condition is met and lets the loop continue to move to the next iteration. It is used to continue running the program even after the program encounters a break during execution.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for letter in 'Flexi ple': 
if letter == ' ': 
        continue 
    print ('Letters: ', letter)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;p&gt;&lt;span id="section3"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Letters: F
Letters: l
Letters: e
Letters: x
Letters: i
Letters: p
Letters: l
Letters: e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example, the program will skip the space ‘ ‘ in the word and continue with the rest of the iteration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pass statement
&lt;/h2&gt;

&lt;p&gt;The pass statement is a null operator and is used when the programmer wants to do nothing when the condition is satisfied. This control statement in Python does not terminate or skip the execution, it simply passes to the next iteration.&lt;/p&gt;

&lt;p&gt;A loop cannot be left empty otherwise the interpreter will throw an error and to avoid this, a programmer can use the pass statement.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for letter in 'Flexiple': 
if letter == 'x': 
        pass 
    print ('Letters: ', letter)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Letters: F
Letters: l
Letters: e
Letters: x
Letters: i
Letters: p
Letters: l
Letters: e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you can see in the above example, even though the condition was met, the pass statement didn’t do anything and execution moved to the next &lt;a href="https://wiki.python.org/moin/Iterator"&gt;iteration&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing Thoughts
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we read about the different types of control statements in Python - break, continue and pass. Different control statements have different functions and can be used according to the need in the program. One can read about other Python concepts &lt;a href="https://flexiple.com/python-loop-through-list/"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Different Assignment operators in Python</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Fri, 01 Jul 2022 08:42:21 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/different-assignment-operators-in-python-42o8</link>
      <guid>https://forem.com/hrishikesh1990/different-assignment-operators-in-python-42o8</guid>
      <description>&lt;p&gt;Assignment operators in Python are in-fix which are used to perform operations on variables or operands and assign values to the operand on the left side of the operator. It performs arithmetic, logical, and bitwise computations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Assignment Operators in Python
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Simple assignment operator in Python
&lt;/li&gt;
&lt;li&gt;  Add and equal operator
&lt;/li&gt;
&lt;li&gt;  Subtract and equal operator
&lt;/li&gt;
&lt;li&gt;  Multiply and equal operator
&lt;/li&gt;
&lt;li&gt;  Divide and equal operator
&lt;/li&gt;
&lt;li&gt;  Modulus and equal operator
&lt;/li&gt;
&lt;li&gt;  Double divide and equal operator
&lt;/li&gt;
&lt;li&gt;  Exponent assign operator
&lt;/li&gt;
&lt;li&gt;  Bitwise and operator
&lt;/li&gt;
&lt;li&gt;  Bitwise OR operator
&lt;/li&gt;
&lt;li&gt;  Bitwise XOR Assignment operator
&lt;/li&gt;
&lt;li&gt;  Bitwise right shift assignment operator
&lt;/li&gt;
&lt;li&gt;  Bitwise left shift assignment operator
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Simple assignment operator in Python
&lt;/h2&gt;

&lt;p&gt;The Simple assignment operator in Python is denoted by = and is used to assign values from the right side of the operator to the value on the left side.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;p&gt;&lt;span id="section2"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = b + c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Add and equal operator
&lt;/h2&gt;

&lt;p&gt;This operator adds the value on the right side to the value on the left side and stores the result in the operand on the left side.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
a += 10
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section3"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Subtract and equal operator
&lt;/h2&gt;

&lt;p&gt;This operator subtracts the value on the right side from the value on the left side and stores the result in the operand on the left side.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 10
a -= 5
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section4"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Multiply and equal operator
&lt;/h2&gt;

&lt;p&gt;The Multiply and equal operator multiplies the right operand with the left operand and then stores the result in the left operand.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
a *= 2
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section5"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Divide and equal operator
&lt;/h2&gt;

&lt;p&gt;It divides the left operand with the right operand and then stores the quotient in the left operand.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 10
a /= 2
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section6"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Modulus and equal operator
&lt;/h2&gt;

&lt;p&gt;The modulus and equal operator finds the modulus from the left and right operand and stores the final result in the left operand.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 10
a %= 3
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section7"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Double divide and equal operator
&lt;/h2&gt;

&lt;p&gt;The double divide and equal or the divide floor and equal operator divides the left operand with the right operand and stores the floor result in the left operand.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 11
a //= 3
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section8"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Exponent assign operator
&lt;/h2&gt;

&lt;p&gt;It performs exponential or power calculation and assigns value to the left operand.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 2
a **= 3
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section9"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Bitwise And operator
&lt;/h2&gt;

&lt;p&gt;Performs Bitwise And operation on both variables and stores the result in the left operand. The Bitwise And operation compares the corresponding bits of the left operand to the bits of the right operand and if both bits are 1, the corresponding result is also 1 otherwise 0.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 3
b = 5
a &amp;amp;= b
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section10"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The binary value of 3 is 0011 and the binary value of 5 is 0101, so when the Bitwise And operation is performed on both the values, we get 0111, which is 7 in decimal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bitwise OR operator
&lt;/h2&gt;

&lt;p&gt;Performs Bitwise OR operator on both variables and stores the result in the left operand. The Bitwise OR operation compares the corresponding bits of the left operand to the bits of the right operand and if any one of the bit is 1, the corresponding result is also 1 otherwise 0.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
b = 10
a |= b
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section11"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The binary value of 5 is 0101 and the binary value of 10 is 1010, so when the Bitwise OR operation is performed on both the values, we get 1111, which is 15 in decimal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bitwise XOR operator
&lt;/h2&gt;

&lt;p&gt;Performs Bitwise XOR operator on both variables and stores the result in the left operand. The Bitwise XOR operation compares the corresponding bits of the left operand to the bits of the right operand and if only one of the bit is 1, the corresponding result is also 1 otherwise 0.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
b = 9
a ^= b
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section12"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;12
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The binary value of 5 is 0101 and the binary value of 9 is 1001, so when the Bitwise XOR operation is performed on both the values, we get 1100, which is 12 in decimal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bitwise right shift assignment operator
&lt;/h2&gt;

&lt;p&gt;This operator performs a Bitwise right shift on the operands and stores the result in the left operand.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 15
b = 2
a &amp;gt;&amp;gt;= b
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section13"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The binary value of 15 is 1111, so when the Bitwise right shift operation is performed on ‘a’, we get 0011, which is 3 in decimal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bitwise left shift assignment operator
&lt;/h2&gt;

&lt;p&gt;This operator performs a Bitwise left shift on the operands and stores the result in the left operand.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 15
b = 1
a &amp;lt;&amp;lt;= b
print (a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;30
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The binary value of 15 is 1111, so when the Bitwise right shift operation is performed on ‘a’, we get 00011110, which is 30 in decimal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing Thoughts
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we read about different types of assignment operators in Python which are special symbols used to perform arithmetic, logical and &lt;a href="https://realpython.com/python-bitwise-operators/"&gt;bitwise&lt;/a&gt; operations on the operands and store the result in the left side operand. One can read about other Python concepts &lt;a href="https://flexiple.com/python/arithmetic-operators-in-python/"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Different Comparison operators in Python</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Wed, 29 Jun 2022 11:03:56 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/different-comparison-operators-in-python-5edf</link>
      <guid>https://forem.com/hrishikesh1990/different-comparison-operators-in-python-5edf</guid>
      <description>&lt;p&gt;Comparison operators, also known as relational operators in Python, compare the values on either side of them and returns a boolean value. They tell whether a statement is True or False according to the condition. In this tutorial, we will discuss 6 different types of comparison operators in Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  List of comparison operators in Python
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Greater than
&lt;/li&gt;
&lt;li&gt;  Less than
&lt;/li&gt;
&lt;li&gt;  Equal to
&lt;/li&gt;
&lt;li&gt;  Not equal to
&lt;/li&gt;
&lt;li&gt;  Greater than or equal to
&lt;/li&gt;
&lt;li&gt;  Less than or equal to
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Greater than
&lt;/h2&gt;

&lt;p&gt;Denoted by &amp;gt;, the greater than operator checks if the value on the left side is greater than the value on the right side. It returns True if the condition is satisfied, otherwise returns False.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 5
y = 10
res = x &amp;gt; y
res1 = y &amp;gt; x
print (res)
print (res1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section2"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FALSE
TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Less than
&lt;/h2&gt;

&lt;p&gt;The less than operator is denoted by &amp;lt; sign and compares the values present on either side. If the value present on the left side is smaller than the value on the right side, it returns True otherwise it returns False.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 5
y = 10
res = x &amp;lt; y
res1 = y &amp;lt; x
print (res)
print (res1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
FALSE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you compare two different data types, for example, int (5) and float (5.0), both greater than and less than operator will return False as both values are equal.&lt;br&gt;&lt;br&gt;
And when comparing strings like, “Nick” and “nick”, the operators compare their ASCII values. Since the ASCII value of “A” is 65 and “a” is 97, “nick” is greater than “Nick”.&lt;/p&gt;

&lt;p&gt;&lt;span id="section3"&gt;&lt;/span&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Equal to
&lt;/h2&gt;

&lt;p&gt;This operator is denoted by == and it returns True if both the values present on either side are equal.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 5
y = 5
z = ‘5’
res = x == y
res2 = x == z
print (res)
print (res2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
FALSE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section4"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;This operator returns False when x and z are compared and that is because x is an integer and z is a string. Hence, they are unequal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Not equal to
&lt;/h2&gt;

&lt;p&gt;Symbolic representation of Not equal to operator is != and it returns True if one value is not equal to the other present in the condition.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;span id="section5"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FALSE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Greater than or equal to
&lt;/h2&gt;

&lt;p&gt;This operator (&amp;gt;=) only returns True if the value on the left side is greater or equal to the value on the right side.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 5
y = 5
z = 10
res = x &amp;gt;= y
res2 = x &amp;gt;= z
print (res)
print (res2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section6"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
FALSE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Less than or equal to
&lt;/h2&gt;

&lt;p&gt;The last operator in the list is less than or equal to (&amp;lt;=). It compares the values and returns True if the value on the left side is smaller than or equal to the value to the value on the right side.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 5
y = 5
z = 10
res = x &amp;lt;= y
res1 = x &amp;lt;= z
print (res)
print (res1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can also compare Tuples with these operators. The Tuple with more elements will be greater and if both have the same number of elements then the operator compares elements with each other.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;pre&gt;&lt;code&gt;tup1 = (1,2,3)
tup2 = (1,2,3)
tup3 = (1,2)
tup4 = (1,5,3)
print (tup1 == tup2)
print (tup3 &amp;lt;= tup1)
print (tup1 &amp;gt;= tup4)&lt;/code&gt;&lt;/pre&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;p&gt;In the 3rd case, the tup1 and tup4 have the same number of elements. Then, the operator compares elements. It compares the first element (1 and 1). Since both are equal, it moves to the second element (2 and 5). Now that 5 is greater than 2, it stops here and returns False.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing Thoughts
&lt;/h2&gt;

&lt;p&gt;We discussed 6 different types of Comparison &lt;a href="https://realpython.com/python-operators-expressions/"&gt;operators&lt;/a&gt; in Python. The comparison operators compare the value and return a boolean value. One can read about other Python concepts &lt;a href="https://flexiple.com/python/python-exponents"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Different Arithmetic operators in Python</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Wed, 22 Jun 2022 10:53:19 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/different-arithmetic-operators-in-python-34he</link>
      <guid>https://forem.com/hrishikesh1990/different-arithmetic-operators-in-python-34he</guid>
      <description>&lt;p&gt;In this tutorial, we will discuss all the basic Arithmetic operators in Python. This is a relatively easy concept. We have used these operations in Mathematics in our school, now we will see how to use these operators in Python to perform basic arithmetic operations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&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
&lt;/li&gt;
&lt;li&gt;  Modulus
&lt;/li&gt;
&lt;li&gt;  Exponentiation
&lt;/li&gt;
&lt;li&gt;  Floor division
&lt;/li&gt;
&lt;li&gt;  Order of precedence
&lt;/li&gt;
&lt;li&gt;  Closing Thoughts
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Addition
&lt;/h2&gt;

&lt;p&gt;This operator is used to add two values present on either side of the operator.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;span id="section2"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Subtraction
&lt;/h2&gt;

&lt;p&gt;This operator is used to subtract the value present on the right side of the operator from the value present on the left side of the operator.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 5
y = 2
sub = x - y
print (sub)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section3"&gt;&lt;/span&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Multiplication
&lt;/h2&gt;

&lt;p&gt;This operator is used to find the product of the two values present on either side of the operator.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;span id="section4"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Division
&lt;/h2&gt;

&lt;p&gt;This operator is used to find the quotient. The value present on the left side of the operator acts as a Dividend and the one on the right side is Divisor.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 5
y = 2
div = x / y
print (div)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section5"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A division operation always results in a floating-point number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modulus
&lt;/h2&gt;

&lt;p&gt;This operator is used to find the remainder. The value present on the left side of the operator acts as a Dividend and the one on the right side is Divisor.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 8
y = 3
mod = x % y
print (mod)

a = -5
b = 2
res1 = a % b
print (res1)

m = 5
n = -2
res2 = m % n
print (res2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section6"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2
       -1
       1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The remainder will be positive if the Dividend is positive and vice-versa. Even if the Divisor is negative but the Dividend is positive, the remainder will be positive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exponentiation
&lt;/h2&gt;

&lt;p&gt;This operator is used to raise the first value to the power of the second operator&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;span id="section7"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Floor division
&lt;/h2&gt;

&lt;p&gt;The Floor Division operator is used to floor the result to the nearest integer.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x = 5
y = 2
flo = x // y
print (flo)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section8"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Order of precedence of Arithmetic operators in Python
&lt;/h2&gt;

&lt;p&gt;Arithmetic Operators in Python follow a basic order of precedence. When more than one operator is used, they are executed according to this order:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;

&lt;tbody&gt;

&lt;tr&gt;

&lt;th&gt;Operator&lt;/th&gt;

&lt;th&gt;Purpose&lt;/th&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;()&lt;/td&gt;

&lt;td&gt;Parentheses&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;**&lt;/td&gt;

&lt;td&gt;Exponent&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;%, *, /, //&lt;/td&gt;

&lt;td&gt;Modulos, Multiplication, Division and Floor division&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;+, -&lt;/td&gt;

&lt;td&gt;Addition and Subtraction&lt;/td&gt;

&lt;/tr&gt;

&lt;/tbody&gt;

&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The operator listed at the top of the table will be executed first.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print (((5 + 4) / 3) * 2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section9"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here, as you can see according to the order of precedence, Parentheses will be computed first. So inside the innermost parenthesis, there is an addition operator.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing Thoughts on Arithmetic Operators in Python
&lt;/h2&gt;

&lt;p&gt;We discussed 7 different types of Arithmetic &lt;a href="https://realpython.com/python-operators-expressions/"&gt;operators&lt;/a&gt; in Python. Make sure you remember the order of precedence because that affects the outcome of all operations performed in Python. One can read about other Python concepts &lt;a href="https://flexiple.com/python/python-exponents"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python Reserved Words List - Your Complete Guide</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Mon, 20 Jun 2022 10:04:54 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/python-reserved-words-list-your-complete-guide-2mof</link>
      <guid>https://forem.com/hrishikesh1990/python-reserved-words-list-your-complete-guide-2mof</guid>
      <description>&lt;p&gt;There is a restriction while naming identifiers that there are some restricted words that are built-in to Python which cannot be used as an identifier. Python reserved words (also called keywords) a predefined meaning and syntax in the language which Python uses for its syntax and internal processing. In this tutorial, we will discuss what those keywords are.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Reserved words
&lt;/li&gt;
&lt;li&gt;  Keywords
&lt;/li&gt;
&lt;li&gt;  Display all keywords
&lt;/li&gt;
&lt;li&gt;  Check if the name is included in the reserved word list
&lt;/li&gt;
&lt;li&gt;  Closing Thoughts
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reserved words in Python
&lt;/h2&gt;

&lt;p&gt;Here is the list of all the reserved words in Python.&lt;br&gt;&lt;br&gt;
Note - This list may change with different versions of Python. Python 3 has 33 while Python 2 has 30 reserved words. The print was removed from Python 2 keywords and added as a built-in Python function.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;

&lt;tbody&gt;

&lt;tr&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;def&lt;/td&gt;

&lt;td&gt;if&lt;/td&gt;

&lt;td&gt;raise&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;None&lt;/td&gt;

&lt;td&gt;del&lt;/td&gt;

&lt;td&gt;import&lt;/td&gt;

&lt;td&gt;return&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;elif&lt;/td&gt;

&lt;td&gt;in&lt;/td&gt;

&lt;td&gt;try&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;and&lt;/td&gt;

&lt;td&gt;else&lt;/td&gt;

&lt;td&gt;is&lt;/td&gt;

&lt;td&gt;while&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;as&lt;/td&gt;

&lt;td&gt;except&lt;/td&gt;

&lt;td&gt;lambda&lt;/td&gt;

&lt;td&gt;with&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;assert&lt;/td&gt;

&lt;td&gt;finally&lt;/td&gt;

&lt;td&gt;nonlocal&lt;/td&gt;

&lt;td&gt;yield&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;break&lt;/td&gt;

&lt;td&gt;for&lt;/td&gt;

&lt;td&gt;not&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;class&lt;/td&gt;

&lt;td&gt;form&lt;/td&gt;

&lt;td&gt;or&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;continue&lt;/td&gt;

&lt;td&gt;global&lt;/td&gt;

&lt;td&gt;pass&lt;/td&gt;

&lt;/tr&gt;

&lt;/tbody&gt;

&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All the keywords except True, False and None are in lowercase and they must be written as they are. These cannot be used as variable names, function names, or any other identifiers.&lt;br&gt;&lt;br&gt;
If any of the keywords is used as a variable, then we will get the error message SyntaxError: invalid syntax&lt;/p&gt;

&lt;p&gt;&lt;span id="section2"&gt;&lt;/span&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Keywords
&lt;/h2&gt;

&lt;h3&gt;
  
  
  False
&lt;/h3&gt;

&lt;p&gt;It is a boolean operator that represents the opposite of True.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print (5 == 10)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FALSE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since the values are not actually equal, it returns False.&lt;/p&gt;

&lt;h3&gt;
  
  
  def
&lt;/h3&gt;

&lt;p&gt;The def function is used to define a function or a method in Python.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def welcome(name):
       print (f"{name}, Welcome to Flexiple")

welcome ("Ben")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ben, Welcome to Flexiple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A function 'welcome' is defined using the def statement.&lt;/p&gt;

&lt;h3&gt;
  
  
  if
&lt;/h3&gt;

&lt;p&gt;An if statement is used to make a conditional statement. If the condition is True, then some action is performed.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = 19
If age &amp;gt;= 18:
       print ("You are eligible to vote.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are eligible to vote.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since the age is greater than 18, the condition is True and the print command is executed.&lt;/p&gt;

&lt;h3&gt;
  
  
  raise
&lt;/h3&gt;

&lt;p&gt;The raise statement is used to raise an error. These errors are visible in the traceback and they cancel the execution of the program if not handled properly.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;enter = "nick"
if not type(enter) is int:
       raise TypeError("Only integers are allowed.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TypeError: Only integers are allowed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;TypeError is raised if the variable does not contain integers.&lt;/p&gt;

&lt;h3&gt;
  
  
  None
&lt;/h3&gt;

&lt;p&gt;There is no null value in Python. The None is an object that represents the absence of a value. It is like an empty object.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = None
if age is None:
       print ("Invalid result")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Invalid result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The age variable has no value to it. This satisfies the condition in the if statement.&lt;/p&gt;

&lt;h3&gt;
  
  
  del
&lt;/h3&gt;

&lt;p&gt;The del statement is used to delete an object in Python.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name = [‘Ben’, ‘Nick’, ‘Steph’]
del name[1]
print (name)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[‘Ben’, ‘Steph’]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;'Nick' is removed from the list.&lt;/p&gt;

&lt;h3&gt;
  
  
  import
&lt;/h3&gt;

&lt;p&gt;This statement is used to import modules to the project.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy
import math
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This statement will import the NumPy and the math library into the project.&lt;/p&gt;

&lt;h3&gt;
  
  
  return
&lt;/h3&gt;

&lt;p&gt;This keyword is used to exit a function or a method and return some value.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def sub(x, y):
       return x + y
print (sub(5, 4))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The function returns the sum of the two variables.&lt;/p&gt;

&lt;h3&gt;
  
  
  True
&lt;/h3&gt;

&lt;p&gt;It is a boolean operator that represents if the value is True&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print (10 == 10)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The values are same so it returns True.&lt;/p&gt;

&lt;h3&gt;
  
  
  elif
&lt;/h3&gt;

&lt;p&gt;Shorthand for else if, checks if some other condition holds when the condition in the if statement is false.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = 18
if age &amp;gt; 18:
       print ("You are eligible to vote.")
elif age == 18:
       print ("You can vote if you are a registered voter.")
else: 
print ("You are not eligible to vote.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You can vote if you are a registered voter.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The condition in the if statement was not True. Hence, the elif statement looked for other conditions that are True.&lt;/p&gt;

&lt;h3&gt;
  
  
  in
&lt;/h3&gt;

&lt;p&gt;The in statement is used to check if an element is present in an iterable like list or tuple.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name = ['Ben', 'Nick', 'Steph']
exist = 'Steph' in name
print (exist)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;'Steph' is present in the name list.&lt;/p&gt;

&lt;h3&gt;
  
  
  try
&lt;/h3&gt;

&lt;p&gt;The try statement is used to make a try… except statement. The try statement starts a block of code that is tried to execute. If it fails, the except block catches the error.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
b = 0 
try:
       div = a/b
except ZeroDivisionError:
       print ("Divisor cannot be zero.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Divisor cannot be zero.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The divisor is 0, which is not possible. So the except block catches the error.&lt;/p&gt;

&lt;h3&gt;
  
  
  and
&lt;/h3&gt;

&lt;p&gt;It is one of the logical operators that returns True if both of the statements are True.&lt;br&gt;&lt;br&gt;
The Truth table for the and operator is as follows:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;

&lt;tbody&gt;

&lt;tr&gt;

&lt;th&gt;A&lt;/th&gt;

&lt;th&gt;B&lt;/th&gt;

&lt;th&gt;A and B&lt;/th&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;/tr&gt;

&lt;/tbody&gt;

&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
b = 10
c = 20
stat1 = b &amp;gt; a
stat2 = c &amp;gt; b
result = stat1 and stat2
print (result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Both the statements are True and that is why the and operator returns True.&lt;/p&gt;

&lt;h3&gt;
  
  
  else
&lt;/h3&gt;

&lt;p&gt;Conditional statement that tells to perform alternate action if the condition in the if statement is False.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = 16
if age &amp;gt;=18:
       print ("You are eligible to vote.")
else:
       print ("You are not eligible to vote.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are not eligible to vote.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The condition in the if statement was not True, so the alternate action is executed.&lt;/p&gt;

&lt;h3&gt;
  
  
  is
&lt;/h3&gt;

&lt;p&gt;This statement is used to check if the two variables are equal.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
b = 5
print (a is b)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Both the variables point to the same memory place.&lt;/p&gt;

&lt;h3&gt;
  
  
  while
&lt;/h3&gt;

&lt;p&gt;This statement is used to start a while loop. It continues iteration until a condition is no longer True.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num = [1, 2, 3]
i = 0

while i &amp;lt; len(num):
       print (num[i])
       i = i + 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The loop will run till the value of i is greater than the length of the list.&lt;/p&gt;

&lt;h3&gt;
  
  
  as
&lt;/h3&gt;

&lt;p&gt;The as statement in Python re-assigns a returned object to a new identifier. Basically, it creates an alias.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import datetime as dt

today = dt.date.today()
print(today)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The datetime is identified as dt in the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  except
&lt;/h3&gt;

&lt;p&gt;Part of the type… except errorhandling structure in Python. Tells what to do when an exception occurs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
b = 0 
try:
       div = a/b
except ZeroDivisionError:
       print ("Divisor cannot be zero.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Divisor cannot be zero.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As the divisor was zero, the except code block caught the error.&lt;/p&gt;

&lt;h3&gt;
  
  
  lambda
&lt;/h3&gt;

&lt;p&gt;A lambda function in Python is an anonymous function. It can take any number of arguments but only have a single expression.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;numbers = [1, 2, 3]
cube_nums = map(lambda x: x ** 3, numbers)
print(list(cube_nums))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1, 8, 27]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The cube of the variable is an anonymous function.&lt;/p&gt;

&lt;h3&gt;
  
  
  with
&lt;/h3&gt;

&lt;p&gt;The with statement is used to simplify the exception handling.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;with open("file.txt", "r") as file:
    lines = file.read()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  assert
&lt;/h3&gt;

&lt;p&gt;The assert statement in Python is used for debugging.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def divide(a, b):
    assert b != 0, "Divisor cannot be zero."
    return a / b

divide (5, 0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Divisor cannot be zero.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  finally
&lt;/h3&gt;

&lt;p&gt;The finally statement is an optional part of try… except error. It always executes the code regardless of whether an error was thrown or not.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = 5
b = 0 
try:
       div = a/b
except ZeroDivisionError:
       print ("Divisor cannot be zero.")
finally:
       print ("Error handling complete.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Divisor cannot be zero.
Error handling complete.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The print statement under the finally will always execute no matter if there is an error or not.&lt;/p&gt;

&lt;h3&gt;
  
  
  nonlocal
&lt;/h3&gt;

&lt;p&gt;This keyword is used in functions inside functions to create anonymous functions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def outer():
  x = "Welcome"
  def inner():
    nonlocal x
    x = "to Flexiple"
  inner() 
  return x
print(outer())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;to Flexiple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  yield
&lt;/h3&gt;

&lt;p&gt;The yield function ends a function and returns an iterator.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def nums():
    i = 0
    while True:
        yield i
        i += 1

for num in nums():
    print(num)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
4
5
6
7
.
.
.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is an infinity loop and will never end.&lt;/p&gt;

&lt;h3&gt;
  
  
  break
&lt;/h3&gt;

&lt;p&gt;It is a control flow statement used to come out of a loop.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = 19
if age &amp;gt;= 18:
       print ("You are eligible to vote.")
       break
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are eligible to vote.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As soon as the condition is satisfied, the break statement ends the loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  for
&lt;/h3&gt;

&lt;p&gt;The keyword is used to create a for loop.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;num = [1, 2, 3]
cube = []
for number in num:
    cube.append(number ** 3)

print (cube)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1, 8, 27]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This loop will run till all the elements in the list are gone through it.&lt;/p&gt;

&lt;h3&gt;
  
  
  not
&lt;/h3&gt;

&lt;p&gt;It is another logical operator that returns False when the value is True and vice versa.&lt;br&gt;&lt;br&gt;
The truth table for not operator:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;

&lt;tbody&gt;

&lt;tr&gt;

&lt;th&gt;A&lt;/th&gt;

&lt;th&gt;not A&lt;/th&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;/tr&gt;

&lt;/tbody&gt;

&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  class
&lt;/h3&gt;

&lt;p&gt;The class keyword is udes to define a class in Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  from
&lt;/h3&gt;

&lt;p&gt;This statement is used when you can to include a specific part of the module.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from math import sqrt
print(sqrt(9))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The whole math module is not imported, only a specific function is imported into the project.&lt;/p&gt;

&lt;h3&gt;
  
  
  or
&lt;/h3&gt;

&lt;p&gt;It is a logical operator that returns True if any one of the statements is True.&lt;br&gt;&lt;br&gt;
Here is the truth table for or operator&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;

&lt;tbody&gt;

&lt;tr&gt;

&lt;th&gt;A&lt;/th&gt;

&lt;th&gt;B&lt;/th&gt;

&lt;th&gt;A or B&lt;/th&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;/tr&gt;

&lt;/tbody&gt;

&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stat1 = True
stat2 = False
result = stat1 or stat 2
print (result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;One of the statements is True and according tot the truth table, the or operator will return True.&lt;/p&gt;

&lt;h3&gt;
  
  
  continue
&lt;/h3&gt;

&lt;p&gt;It is a control flow statement used to continue to the next iteration of a loop. Unlike break, the continue statement does not exit the loop.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = [12, 14, 15, 16, 18]
for number in age
print ("Not eligible")
if age &amp;gt;=18:
continue      
print ("You are eligible to vote.")
break
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Not eligible
Not eligible
Not eligible
Not eligible
You are eligible to vote.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The condition in the if statement is not satisfied by the first element. The loop should end there but due tot he continue statement, the loop continues.&lt;/p&gt;

&lt;h3&gt;
  
  
  global
&lt;/h3&gt;

&lt;p&gt;Accessing a global variable is simple as any other variable but to modify a global variable, you need to use the global keyword.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = 18

def check():
       global age
       age = 16

check()
print (age)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;16
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The age variable is a global variable and we cannot change it's value without using the global statement.&lt;/p&gt;

&lt;h3&gt;
  
  
  pass
&lt;/h3&gt;

&lt;p&gt;It is a null statement in Python that will do nothing.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;p&gt;&lt;span id="section3"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def sub(a, b)
  pass
class Student
  pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It is used as a placeholder for future code. It simply prevents getting errors when an empty code is run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Display all keywords
&lt;/h2&gt;

&lt;p&gt;We can display the full list of all the keywords in the current version of Python by typing the following command in the Python interpreter.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import keyword
print (keyword.kwlist)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qzli8Ocz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ik.imagekit.io/6eslefmcf/flexiple-blog/image1_29e6kOizq%3Fik-sdk-version%3Djavascript-1.4.3%26updatedAt%3D1655718277810" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qzli8Ocz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ik.imagekit.io/6eslefmcf/flexiple-blog/image1_29e6kOizq%3Fik-sdk-version%3Djavascript-1.4.3%26updatedAt%3D1655718277810" alt="" width="880" height="141"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And to find out the number of reserved words in Python.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print (len(kewyord.kwlist))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section4"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LPWUQBoI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ik.imagekit.io/6eslefmcf/flexiple-blog/image2_L7YhAcGA3%3Fik-sdk-version%3Djavascript-1.4.3%26updatedAt%3D1655718302566" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LPWUQBoI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://ik.imagekit.io/6eslefmcf/flexiple-blog/image2_L7YhAcGA3%3Fik-sdk-version%3Djavascript-1.4.3%26updatedAt%3D1655718302566" alt="" width="505" height="58"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Check if the name is included in the reserved word list in Python
&lt;/h2&gt;

&lt;p&gt;To check if the name is a part of the list of reserved keywords in Python, we can use the keyword.iskeyword() function.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import keyword
print (keyword.iskeyword(“global”))
print (keyword.iskeyword(“print”))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section5"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE&lt;br&gt;
FALSE&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Closing Thoughts&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Python reserved words designate special language functionality. No other &lt;a href="https://realpython.com/defining-your-own-python-function/"&gt;variable&lt;/a&gt; can have the same name as these keywords. We read about all the reserved keywords and how to check if the name is a keyword or not. One can learn about more Python concepts &lt;a href="https://flexiple.com/python/identifiers-in-python"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>What are Identifiers in Python?</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Wed, 15 Jun 2022 08:47:39 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/what-are-identifiers-in-python-3236</link>
      <guid>https://forem.com/hrishikesh1990/what-are-identifiers-in-python-3236</guid>
      <description>&lt;p&gt;In this tutorial, we will answer the question - what are Identifiers in Python. An identifier is a user-defined name given to identities like class, functions, variables, modules, or any other object in Python. Here we will discuss the rules for writing identifiers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Rules for writing Identifiers
&lt;/li&gt;
&lt;li&gt;  Valid Identifiers Example
&lt;/li&gt;
&lt;li&gt;  Invalid Identifiers Example
&lt;/li&gt;
&lt;li&gt;  Python Keywords
&lt;/li&gt;
&lt;li&gt;  Testing the Validity of Python Identifiers
&lt;/li&gt;
&lt;li&gt;  Python Identifier Naming Best Practices
&lt;/li&gt;
&lt;li&gt;  Closing Thoughts
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Rules for writing Identifiers in Python
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; The identifier is a combination of character digits and underscore and the character includes letters in lowercase (a-z), letters in uppercase (A-Z), digits (0-9), and an underscore (_).&lt;/li&gt;
&lt;li&gt; An identifier cannot begin with a digit. If an identifier starts with a digit, it will give a Syntax error.&lt;/li&gt;
&lt;li&gt; In Python, keywords are the reserved names that are built-in to Python, so a keyword cannot be used as an identifier - they have a special meaning and we cannot use them as identifier names.&lt;/li&gt;
&lt;li&gt; Special symbols like !, @, #, $, %, etc. are not allowed in identifiers.&lt;/li&gt;
&lt;li&gt; Python identifiers cannot only contain digits.&lt;/li&gt;
&lt;li&gt; There is no restriction on the length of identifiers.&lt;/li&gt;
&lt;li&gt; Identifier names are case-sensitive.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Python Valid Identifiers Example
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  abc123&lt;/li&gt;
&lt;li&gt;  abc_de&lt;/li&gt;
&lt;li&gt;  _abc&lt;/li&gt;
&lt;li&gt;  ABC
&lt;span id="section3"&gt;&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;  abc&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Python Invalid Identifiers Example
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  123abc&lt;/li&gt;
&lt;li&gt;  abc@&lt;/li&gt;
&lt;li&gt;  123
&lt;span id="section4"&gt;&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;  for&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Python Keywords
&lt;/h2&gt;

&lt;p&gt;Here is the list of some reserved keywords in Python that cannot be used as identifiers.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;

&lt;tbody&gt;

&lt;tr&gt;

&lt;td&gt;False&lt;/td&gt;

&lt;td&gt;def&lt;/td&gt;

&lt;td&gt;if&lt;/td&gt;

&lt;td&gt;raise&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;None&lt;/td&gt;

&lt;td&gt;del&lt;/td&gt;

&lt;td&gt;import&lt;/td&gt;

&lt;td&gt;return&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;True&lt;/td&gt;

&lt;td&gt;elif&lt;/td&gt;

&lt;td&gt;in&lt;/td&gt;

&lt;td&gt;try&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;and&lt;/td&gt;

&lt;td&gt;else&lt;/td&gt;

&lt;td&gt;is&lt;/td&gt;

&lt;td&gt;while&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;as&lt;/td&gt;

&lt;td&gt;except&lt;/td&gt;

&lt;td&gt;lambda&lt;/td&gt;

&lt;td&gt;with&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;assert&lt;/td&gt;

&lt;td&gt;finally&lt;/td&gt;

&lt;td&gt;nonlocal&lt;/td&gt;

&lt;td&gt;yield&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;break&lt;/td&gt;

&lt;td&gt;for&lt;/td&gt;

&lt;td&gt;not&lt;/td&gt;

&lt;td&gt;await&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;class&lt;/td&gt;

&lt;td&gt;form&lt;/td&gt;

&lt;td&gt;or&lt;/td&gt;

&lt;td&gt;async&lt;/td&gt;

&lt;/tr&gt;

&lt;tr&gt;

&lt;td&gt;continue&lt;/td&gt;

&lt;td&gt;global&lt;/td&gt;

&lt;td&gt;pass&lt;/td&gt;

&lt;/tr&gt;

&lt;/tbody&gt;

&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;span id="section5"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;As you can see here all the keywords except 'True', 'False', and 'None' are in lowercase, therefore they must be written as they are.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the Validity of Python Identifiers
&lt;/h2&gt;

&lt;p&gt;The str.isidentifier() function is used to check the validity of an identifier but, this method doesn’t take reserved keywords into consideration. So, we can use this function with keyword.iskeyword() to check if the name is valid or not.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print ("abc".isidentifier())
print ("123abc".isidentifier())
print ("_abc".isidentifier())
print ("for".isidentifier())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TRUE
FALSE
TRUE
TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, we know “for” is a reserved keyword so, it is an invalid identifier.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def is_valid_identifier(x):&lt;br&gt;
    Return x.isidentifier() and not keyword.iskeyword(x)

&lt;p&gt;print(is_valid_identifier("for"))&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Output:&lt;br&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;span id="section6"&gt;&lt;/span&gt;&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FALSE&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Python Identifier Naming Best Practices&lt;br&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; Only class names are started with capital letters (Student, Employee).&lt;/li&gt;
&lt;li&gt; Multiple words in a variable are separated by an underscore (is_valid()).&lt;/li&gt;
&lt;li&gt; If an identifier begins with an underscore, it means it is a private identifier. This does not make the variable private. It is only for the ease of the programmer to easily distinguish between private variables and public variables.&lt;/li&gt;
&lt;li&gt; Python built-in magic methods use double underscores around the names (&lt;strong&gt;len&lt;/strong&gt;). Therefore, double underscores are used only when you are dealing with mangling in Python.&lt;/li&gt;
&lt;li&gt; Using longer name than one character is always preferred (index = 1 is better than i = 1).
&lt;span id="section7"&gt;&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt; Camel case are used while naming the variables (studentAddress, studentId). Camel case use a capital letter to begin the second word in a compound name or phrase, when it is not separated from the first word by a space.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Closing Thoughts on Python identifiers
&lt;/h2&gt;

&lt;p&gt;Python Identifiers are &lt;a href="https://realpython.com/defining-your-own-python-function/"&gt;user-defined&lt;/a&gt; names. We discussed the rules and some best practices while naming identifiers that are good for fellow Python programmers. One can learn about more Python concepts &lt;a href="https://flexiple.com/python/python-initialize-list"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python remove file - How to delete a file?</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Mon, 30 May 2022 10:35:46 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/python-remove-file-how-to-delete-a-file-3lfh</link>
      <guid>https://forem.com/hrishikesh1990/python-remove-file-how-to-delete-a-file-3lfh</guid>
      <description>&lt;p&gt;The files in Python are used for various purposes by the developers. After the developer has worked with the file, it is important to know how to delete it. For example in a large program, the developer would need to create files to store data but would not require them after the execution of the program. This is when deleting the file is a good idea and in this tutorial, we will discuss different ways to delete or remove a file in Python.&lt;br&gt;&lt;br&gt;
In this tutorial, we will discuss various methods to remove a file in Python using the os.remove() and the pathlib module. We will also discuss how to remove an empty and a non-empty directory in Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Removing file in Python using os.remove()
&lt;/li&gt;
&lt;li&gt;  Using the pathlib module to remove a file in Python
&lt;/li&gt;
&lt;li&gt;  Removing empty directory
&lt;/li&gt;
&lt;li&gt;  Removing a non-empty directory
&lt;/li&gt;
&lt;li&gt;  Closing thoughts
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;span id="section1"&gt;&lt;/span&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Removing file in Python using os.remove()
&lt;/h2&gt;

&lt;p&gt;The OS module in Python provides functions for interacting with the operating system. This standard utility module provides a portable way of using operating system-dependent functionality. This module can remove a file or file path but cannot delete a directory. If the specified path is a directory, then the module will raise an OSError.&lt;/p&gt;

&lt;h4&gt;
  
  
  Syntax:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;os.remove(path, *, dir_fd = None)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Case 1: To remove a file 
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os

file = 'file.txt'  
location = "/home/User/Documents"
path = os.path.join(location, file)  
os.remove(path)

print (“The file has been removed")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The file has been removed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above code snippet, we first specify which file we want to delete and where it's located. Then, after joining, we use the os.remove() operation to delete it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Case 2: The specified path is a directory
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os

path = "/home/User/Documents/abcdef"

os.remove(path)
print (“The file has been removed")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section2"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Traceback (most recent call last):
  File "osremove.py", line 15, in 
    os.remove(path)
IsADirectoryError: [Errno 21] Is a directory: '/home/User/Documents/acdef'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here, we do not need to use the 'join' operation as we directly specify the exact location. Make sure to import the OS library before using the os.remove() function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the pathlib module to remove a file in Python
&lt;/h2&gt;

&lt;p&gt;The pathlib module is very useful in removing or deleting a file in Python 3.4 or above. It is similar to the os.remove() and have to create a path object at first.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pathlib
p_obj = Path(".")
type(p_obj)
file = pathlib.Path("file_1/file.txt")
file.unlink()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section3"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;When an instance of the Path class is created, a WindowsPath or PosixPath will be returned according to the machine you’re working on. And the unlink() function is used to remove the file or the symbolic link.&lt;/p&gt;

&lt;h2&gt;
  
  
  Removing empty directory
&lt;/h2&gt;

&lt;p&gt;The above two approaches cannot be used to remove a folder. The os.rmdir() function in the OS module can delete an empty directory in Python.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
directory = "/home/User/Documents/abcdef"
os.rmdir('directory')

print (“The directory is removed.”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The directory is removed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The os.rmdir() function can only be used to delete an empty directory. If you specify a folder that contains files, the following error will be returned.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os

directory = "/home/User/Documents/abcdef/ghi"

os.rmdir('directory')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section4"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Permission denied: '/home/User/Documents/abcdef/ghi' Directory 'ghi' can not be removed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Removing a non-empty directory
&lt;/h2&gt;

&lt;p&gt;You can use the high-level file operation module, shutil to remove a file or collection of files. You can use this module in the same way as the os.rmdir() function but here you can also remove the non-empty directories. All the contents inside the directory are removed as well.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import shutil
path = /home/User/Documents/abcdef
shutil.rmtree('path')

print (“All the files inside the directory are removed with the directory”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section5"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;All the files inside the directory are removed with the directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Just remember that you cannot remove a single file with the shutil.rmtree() function. For deleting a single file, you can use the os.remove() function and the pathlib module that's been illustrated above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing thoughts
&lt;/h2&gt;

&lt;p&gt;In Python, removing a file is a very common operation. The os.remove() function and the pathlib module can remove a single file. While the os.rmdir() function removes an empty &lt;a href="https://docs.python.org/3/library/filesys.html"&gt;directory&lt;/a&gt; and the shutil module removes the non-empty directory in Python. You can learn other Python concepts &lt;a href="https://flexiple.com/python/open-python"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to print a list in Python?</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Fri, 27 May 2022 06:05:19 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/how-to-print-a-list-in-python-o93</link>
      <guid>https://forem.com/hrishikesh1990/how-to-print-a-list-in-python-o93</guid>
      <description>&lt;p&gt;Python has many in-built data structures to make programming faster and more efficient than any other language. All these data structures are mutable and sequential in nature and store huge data collection in various formats. Python’s list data structure is built for simplicity and flexibility. In this tutorial, we will discuss various ways to print a list in Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Introduction
&lt;/li&gt;
&lt;li&gt;  Using the * symbol to print a list
&lt;/li&gt;
&lt;li&gt;  The join() function to print a list
&lt;/li&gt;
&lt;li&gt;  Using the map() function to print a list in Python
&lt;/li&gt;
&lt;li&gt;  In Python, print list using for loop
&lt;/li&gt;
&lt;li&gt;  Closing thoughts
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;span id="section1"&gt;&lt;/span&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to Python print list
&lt;/h2&gt;

&lt;p&gt;A list can contain any number of elements of different data types such as integer, float, string, etc. and in Python, printing a list is a simple task that can be executed using various methods. This tutorial covers some of the methods to print lists in Python.&lt;/p&gt;

&lt;p&gt;&lt;span id="section2"&gt;&lt;/span&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Using the * symbol to print a list in Python
&lt;/h2&gt;

&lt;p&gt;To print the contents of a list in a single line with space, * or splat operator is one way to go. It passes all of the contents of a list to a function.&lt;/p&gt;

&lt;p&gt;We can print all elements in new lines or separated by space and to do that, we use sep=”\n” or sep=”, ” respectively. The below example illustrates this.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = [Jon, Ned, 8, 99]
print (*list)

print ("printing lists separated by commas")
print (*list, sep=",")

print ("printing lists in new line")
print (*list, sep="\n")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section3"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Jon Ned 8 99
printing lists separated by commas
Jon, Ned, 8, 99
printing lists in new line
Jon
Ned
8
99
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Using join() to print a list in Python
&lt;/h2&gt;

&lt;p&gt;If the list contains strings as elements, then using the join() function is the smart choice. It simply joins the strings and then prints the list. If the list has integers, then this function will join them to a string first and then print the string. This example shows how it's done:&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = ["Jon", "Ned", "Arya"]
print (' '.join(list))

list_1 = [1, 2, 3, 4, 5]
print str(list_1)[1:-1] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section4"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;John Ned Arya
1, 2, 3, 4, 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Using map() function to print list in Python
&lt;/h2&gt;

&lt;p&gt;The map() function takes two arguments: a function to apply to each element of a list, and a list. It returns a map object (which is an iterator) after applying the given function to each item of a given iterable. Then the join() function joins the elements of the list using a separator as mentioned in the earlier method. Here's how it's done:&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = [1, 2, 3, 4, 5]
print(' '.join(map(str, list))) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section5"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 2 3 4 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  In Python, print list using for loop
&lt;/h2&gt;

&lt;p&gt;One of the standard methods to print a list in Python is using the for loop. You can traverse the list from the 0th index to len(list) and print all the elements in the sequence.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = ["Jon", "Ned", "Arya"]

for i in range(0, len(list)):
     print(list[i])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Jon
Ned
Arya
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Moreover, you can also print the list using for loop without mentioning the range as shown below:&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = ["Jon", "Ned", "Arya"]

for item in list:
     print(item)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section6"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Jon&lt;br&gt;
Ned&lt;br&gt;
Arya&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Closing thoughts&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Printing the list is one of the everyday &lt;a href="https://docs.python.org/3/tutorial/datastructures.html"&gt;tasks&lt;/a&gt; while coding your program and getting the expected output. Therefore, we discussed different ways in Python to print the list. One can learn about other tasks related to the Python list &lt;a href="https://flexiple.com/python/python-initialize-list"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python Initialize List - How to do it?</title>
      <dc:creator>hrishikesh1990</dc:creator>
      <pubDate>Thu, 26 May 2022 05:16:14 +0000</pubDate>
      <link>https://forem.com/hrishikesh1990/python-initialize-list-how-to-do-it-30cp</link>
      <guid>https://forem.com/hrishikesh1990/python-initialize-list-how-to-do-it-30cp</guid>
      <description>&lt;p&gt;Python List is a collection of ordered values and can hold any type of value. It is a container where we can insert, delete or modify the existing values as the list is mutable in Python. Unlike sets, the list can hold the same value multiple times and considers each as a separate item. In this tutorial, we will read how to initialize a list in Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  Introduction to Python Initialize List
&lt;/li&gt;
&lt;li&gt;  Initialize using the square brackets in Python
&lt;/li&gt;
&lt;li&gt;  Using the list() function to initialize the list
&lt;/li&gt;
&lt;li&gt;  Using comprehensions to initialize the list
&lt;/li&gt;
&lt;li&gt;  Initialize using * operator
&lt;/li&gt;
&lt;li&gt;  Closing thoughts
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;span id="section1"&gt;&lt;/span&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to Python Initialize List
&lt;/h2&gt;

&lt;p&gt;In Python, a user can perform a single task using different ways. Similarly, in order to initialize a list in Python, there is more than one way to do that and we will discuss a few in this tutorial.&lt;/p&gt;

&lt;p&gt;&lt;span id="section2"&gt;&lt;/span&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Initialize lists using the square brackets in Python
&lt;/h2&gt;

&lt;p&gt;If you want to create an empty list with no values in Python, the square bracket is the way to initialize the list with empty values. You just have to declare a non-value list by specifying a set of square brackets without item values.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = []
print (list)

list = [1,2,3,4]
print (list)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section3"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[]
[1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Using the list() function to initialize the list in Python
&lt;/h2&gt;

&lt;p&gt;It is another way to create an empty list without values in Python as the list() function creates the list from the iterable object.&lt;/p&gt;

&lt;p&gt;An iterable may be a container, a sequence that supports iteration, or an iterator object. If no parameter is specified, then a new empty list is created.&lt;/p&gt;
&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list_1 = list()
print (list_1)

res = []
print (data == res)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section4"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[]
TRUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since the square bracket approach is more instructive and concise, it is preferred over the list() function approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using comprehensions to initialize the list in Python
&lt;/h2&gt;

&lt;p&gt;In order to initialize the list with default values, we can use the comprehension method. It consists of square brackets containing an expression followed by a for clause and further followed by an optional if clause. The expression can be any type of object that you want to put on the list. Since the user is initializing the list with zeros, the expression will just be 0.&lt;/p&gt;

&lt;p&gt;List comprehension is an easy way to define a list based on an iterator because it is elegant, simple, and widely recognized.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = [i for i in range(5)]
print (list)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section5"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0,1,2,3,4]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This method is way faster than using for and while loops to initialize lists in Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  Initialize lists using the * operator in Python
&lt;/h2&gt;

&lt;p&gt;Another approach to initialize the list with multiple values is the * operator. The syntax is [object]*n where n is the no of elements in the array.&lt;/p&gt;

&lt;p&gt;This method allows us to create a list with a specific number of predefined values.&lt;/p&gt;

&lt;h4&gt;
  
  
  Input:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list = [5]*10
print (list)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;span id="section6"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Output:
&lt;/h4&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[5,5,5,5,5,5,5,5,5,5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is the fastest method among all the methods discussed to initialize the list in Python.&lt;/p&gt;

&lt;p&gt;The only drawback of using the * operator to initialize a list in Python is while declaring 2d arrays as it creates shallow lists i.e only one list object would be created and all the indices would refer to this object which can be inconvenient. That is why in the case of 2d arrays, comprehensions are the better way to initialize a list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing thoughts
&lt;/h2&gt;

&lt;p&gt;Initializing the list is one of the basic things to know while working with lists. We have discussed square brackets and the list() function to create empty lists and &lt;a href="https://www.w3schools.com/python/python_lists_comprehension.asp"&gt;comprehensions&lt;/a&gt; and the * operator to create a list with multiple values. One can learn about other Python concepts &lt;a href="https://flexiple.com/python/list-of-lists-python"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
