<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Introschool</title>
    <description>The latest articles on DEV Community by Introschool (@introschool).</description>
    <link>https://dev.to/introschool</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%2F721702%2F636573f8-57e0-4e9d-bcee-dce969bcc9a7.png</url>
      <title>DEV Community: Introschool</title>
      <link>https://dev.to/introschool</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/introschool"/>
    <language>en</language>
    <item>
      <title>Can You Solve This Simple Python Challenge?</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Sat, 02 Jul 2022 14:44:03 +0000</pubDate>
      <link>https://dev.to/introschool/simple-python-challenge-5c4k</link>
      <guid>https://dev.to/introschool/simple-python-challenge-5c4k</guid>
      <description>&lt;p&gt;You are running a lottery company, and you have distributed 100 tickets. Now, as the head of the company, you know that the winning ticket number has 7 as the last digit. You made an automatic portal for users to check whether they have won or not.&lt;br&gt;
How will you fetch the last digit of the lottery number? Let's say The lottery number is 5678927, and you want to display Hurray. You won the lottery as your last digit is 7 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PS: Solve this using only Arithmetic Operators&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Solution &lt;a href="https://www.youtube.com/watch?v=6_7OkZpOEXE"&gt;Click Here&lt;/a&gt; and &lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe for more challenges&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>challenge</category>
      <category>programming</category>
    </item>
    <item>
      <title>Simple Python Exercise</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Tue, 28 Jun 2022 11:14:28 +0000</pubDate>
      <link>https://dev.to/introschool/simple-python-exercise-3k1f</link>
      <guid>https://dev.to/introschool/simple-python-exercise-3k1f</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Modules and packages In Python</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Sat, 04 Jun 2022 16:12:51 +0000</pubDate>
      <link>https://dev.to/introschool/modules-and-packages-2o3h</link>
      <guid>https://dev.to/introschool/modules-and-packages-2o3h</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Modules and Packages
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Modules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is Module?&lt;/p&gt;

&lt;p&gt;Modules are simple files with .py extensions. When you do programming, most of the time your code base is so large that it’s not easy to maintain that in the one file. So you divide your code base into smaller chunks and you can keep those smaller chunks of code into the different file. These files are called modules. &lt;/p&gt;

&lt;p&gt;Modules also provide reusability of code. If you find that functions which are more frequently used you can write that into one module and use that module where ever you need. &lt;/p&gt;

&lt;p&gt;To create a module, just create a file with .py extension. Here we will create a module name ‘greet.py’. See the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# greet.py module

def hello(name):
    print(f'Hello {name}')


def say_morning(name):
    print(f'Good Morning {name}')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we create the one module name ‘greet’ and there are two functions in it. Let’s see how you can get these functions into another module.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Import Module in Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Import statement&lt;br&gt;
The import keyword is used to get the function definitions into another module. To use the functions we use dot(.) operator. We will import the module ‘greet’ that we just created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Import module

import greet

greet.hello('Ramesh')
# Output: Hello Ramesh

greet.say_morning('Kumar')
# Output: Good Morning Kumar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from … import … Statement&lt;br&gt;
If you want to import some specific object you can use from … import statement. See the belo code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from greet import hello

hello('Kumar')

# Output: Hello Kumar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from … import *&lt;br&gt;
If you want to import all the objects of the module then you can use below syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;form greet import *

hello('Kumar')
# Output: Hello Kumar

say_morning('Kumar')
# Output: Good Morning Kumar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Module Search Path&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;When Python interpreter encounters import statement, it searches for that particular module in built-in modules that are already in Python, if it’s not found then looks in the current directory in which the module is present. In the last, it searches in the installation-dependent directories configured at the time Python is installed.&lt;/p&gt;

&lt;p&gt;Note: To make sure that the module is found in the script that you are writing, keep module and script in the same directory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Packages&lt;/strong&gt;&lt;br&gt;
Packages are the directories containing multiple modules and sub-packages. In computer, to organize your files you put them in folders, so you can easily access them. You make an organized hierarchy of directories to maintain the files.&lt;/p&gt;

&lt;p&gt;In the same way, packages are helpful in organizing your modules and scripts. When you are working on a large application, It contains lots of modules. So it is easy to put similar modules in one package and different module in a different package. &lt;/p&gt;

&lt;p&gt;Note: To initialize a package, it should contain a file called &lt;strong&gt;init&lt;/strong&gt;.py in order for Python to understand it as a package. This file can be left empty but it generally it contains initialization code. But in Python version 3.3, it is not necessary for a package to have &lt;strong&gt;init&lt;/strong&gt;.py file. it can still be present if package initialization is needed. But it is no longer required.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uiBY-eck--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj5tr5jcnnxssyzx0vxw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uiBY-eck--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jj5tr5jcnnxssyzx0vxw.jpg" alt="Image description" width="720" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use the dot(.) operator to access function inside the sub-packages and modules inside them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Packages

import pkg

from pkg import sub_pkg_a.mod_a1

from pkg.sub_pkg_b import mod_b1, mod_b2

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

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>tutorial</category>
      <category>python</category>
      <category>datascience</category>
    </item>
    <item>
      <title>File handling in python</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Thu, 02 Jun 2022 15:57:40 +0000</pubDate>
      <link>https://dev.to/introschool/file-hadling-in-python-193a</link>
      <guid>https://dev.to/introschool/file-hadling-in-python-193a</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  File Handling in Python
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is File Handling?&lt;/strong&gt;&lt;br&gt;
The File Handling is the way of performing operation on the file present in your computer system. A file is a named location of data in the computer memory. To perform an operation on the file, first you have to open the file. After getting done with the operations, the file needs to be closed.&lt;/p&gt;

&lt;p&gt;Computer stores files in the binary format. There are so many file types like image files, exe files, csv files, but while handling we generally divide files into two categories - text files and binary files. Python gives you option to open the file in both binary and text format. We will see them in detain in the below section.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Open a File?&lt;/strong&gt;&lt;br&gt;
Opening the file is the first step of performing any operation on the file. To open a file, we can use Python’s built-in function open(). The open() function takes the path of the file as an argument. It returns the file object. You can also specify the modes of operations like reading, writing  or format of the file like binary or text. See the below code.&lt;/p&gt;

&lt;p&gt;Note: If you don’t specify the mode in open function then the default is reading in text mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# File Handling
'''
Syntax
open(file_path, mode)
'''
# Opening file for reading in text mode.
file = open('file1.txt')

# Opening file for writing in text mode.
file = open('file1.txt', 'w')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Different Modes of Opening a File&lt;br&gt;
Modes are there to tell the Python interpreter that you opening file for reading or writing. You want to open it in text format or binary format. Let’s see them below in detail.&lt;/p&gt;

&lt;p&gt;‘r’&lt;br&gt;
This is default mode. The ‘r’ mode opens a file for reading.&lt;br&gt;
‘t’&lt;br&gt;
This is also default mode. This mode is used to open a file in text format.&lt;br&gt;
‘b’&lt;br&gt;
This mode is used to open a file in binary format. &lt;br&gt;
‘w’&lt;br&gt;
This mode is used to open a file for writing. If the file doesn’t exist then it creates a new file.&lt;br&gt;
‘x’&lt;br&gt;
This mode is used to create and writing to a new file.&lt;br&gt;
‘a’&lt;br&gt;
This mode is used for appending at the end of the file.&lt;br&gt;
‘+’&lt;br&gt;
This mode is used for reading and writing.&lt;/p&gt;

&lt;p&gt;Simply - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you want to read the file, use ‘r’&lt;/li&gt;
&lt;li&gt;If you want to read and write the file, use ‘r+’&lt;/li&gt;
&lt;li&gt;If you want to overwrite the file, use ‘w’&lt;/li&gt;
&lt;li&gt;If you want to append to the file, use ‘a’&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Read and Write Operations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You know that how to open a file for reading and writing. Now you will get to know that how to perform reading and writing operation. Python has some built-in function for reading and writing a file. Let’s see them in the below section.&lt;br&gt;
Writing a file&lt;br&gt;
Let’s create a new file called new.txt and add some content to the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f = open('new.txt', 'w')

f.write('This is a new file.\n')
f.write('This is the second line.\n')
f.write('This is the last line.\n')

f.close()

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First we created a new file called ‘new.txt’ 
using the mode ‘w’. Remember if the file does 
not exist then it creates the new file.&lt;/li&gt;
&lt;li&gt;Python’s built-in function write() is used to 
write a file. To write the string or sequence of 
bytes(for binary files) write() function is 
used. The write() function returns the number of 
characters written to a file.&lt;/li&gt;
&lt;li&gt;You can see that we used ‘\n’ in the strings. 
It’s a new line character. If you see the 
‘new.txt’, It will look like this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This is a new file.
This is the second line.
This is the last line.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the last we use close() function to close the 
file.
&lt;strong&gt;Reading a file&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To read a file there are various built-in function like read(n) or readlines(). Let’s read the file that we just created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f = open('new.txt', 'r')

f.read(6)
# Output: 'This i'



f.read()
# Output: 's a new file.\nThis is the second line.\nThis is the last line.\n'

f.read()
# Output: ''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First we open the file in the read mode. We 
don’t need to specifically the mode for reading 
because it is default. &lt;/li&gt;
&lt;li&gt;Python’s built-in function read() is used to 
read the file. The read(n) function takes a 
number as an argument and returns the number of 
characters in the file. If the number is not 
specified, it reads up to the end of the file.&lt;/li&gt;
&lt;li&gt;Once the end is reached it returns the empty 
string. &lt;/li&gt;
&lt;li&gt;You can use readline() method to read a line in 
the file. Each time you call this method, it r 
returns a line from the file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f = open('new.txt', 'r')

f.readline()
# Output: 'This is a new file.\n'

f.readline()
# Output: 'This is the second line.\n'

f.readline()
# Output: 'This is the last line.\n'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;You can use readlines() method to get the list 
of the lines in the file.&lt;/li&gt;
&lt;li&gt;The tell() method is used to find the file 
position and seek() method is used to change the 
cursor position.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f = open('new.txt', 'r')

f.read(6)
# Output: 'This i'



f.read()
# Output: 's a new file.\nThis is the second line.\nThis is the last line.\n'

f.read()
# Output: ''

f.tell()
# Output: 68

f.seek(0)  # bring the cursor to the initial position

f.readline()
# Output: ['This is a new file.\n', 'This is the second line.\n', 'This is the last line.\n']
f.close()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can also use a for loop to read lines of the 
file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f = open('new.txt', 'r')

for line in f:
    print(line)

'''
# Output:
This is a new file.

This is the second line.

This is the last line.
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to Close a File?
&lt;/h2&gt;

&lt;p&gt;This is the last step in File handling process. You know that to close a file we use Python’s built-in function close(). This function will only work if there is no error after f.open(...) statement. If there is any error then the Python interpreter will not call f.close() method because it reads the code line by line and on founding any error it stops.&lt;/p&gt;

&lt;p&gt;To make sure that the file gets closed whether the error occurs or not, with statement is used. See the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;with open('new.txt', 'r+') as f:
    lines = f.readlines()


print(lines)
# Output: 
# ['This is a new file.\n', 'This is the second line.\n', 'This is the last line.\n']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you use with statement, you don’t need to explicitly use the close() function. The with statement automatically close the file &lt;br&gt;
after getting done with the read and write operations.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>programming</category>
      <category>python</category>
      <category>datascience</category>
    </item>
    <item>
      <title>python guessing game</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Wed, 01 Jun 2022 17:49:15 +0000</pubDate>
      <link>https://dev.to/introschool/python-guessing-game-47pa</link>
      <guid>https://dev.to/introschool/python-guessing-game-47pa</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Guessing Game&lt;/strong&gt;&lt;br&gt;
Here comes the interesting part of the learning. Learn things by building stuff is the best way of learning. In this section, we are going to make a simple game in which computer will randomly select the number from 1-50 and we will ask the user to guess the number. If he selects the number in 5 guesses then he will win the game otherwise he will lose.&lt;/p&gt;

&lt;p&gt;To randomly selects the number we will use Python’s built-in Random module. Let’s see what is random module and how you can use it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Random Module&lt;/strong&gt;&lt;br&gt;
To make the Guessing Game, we will use Python’s built-in random module. The random module is used to generate random numbers. The random module has so many built-in functions that are used to generate random numbers. Let’s see some of the random module functions.&lt;/p&gt;

&lt;p&gt;First of all, we have to import the module to use it.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;randint&lt;br&gt;
random.randint(a, b)&lt;/p&gt;

&lt;p&gt;The randint function of the random module takes two integers as an argument and generates one random number in the range [a, b] including both the numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;random.randint(2,9)
# Output: 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;random&lt;br&gt;
random.random()&lt;/p&gt;

&lt;p&gt;This function is used to generate a floating point number between 0 and 1.&lt;br&gt;
random.random()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;random.random()
# Output: 0.8795690805656851
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choice&lt;br&gt;
random.choice(seq)&lt;/p&gt;

&lt;p&gt;This function selects one random element from a sequence. If the sequence is empty, Interpreter raises IndexError.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;random.choice([1, 4, 5, 8, 11])
# Output: 4

random.choice(('a', 'b', 'c'))
# Output: 'c'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;randrange&lt;br&gt;
random.randrange(begin, end, step)&lt;/p&gt;

&lt;p&gt;This function is used to generate a randomly selected element from range(start, stop, step).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;random.randrange(5, 20)
# Output: 11

random.randrange(13, 33, 2)
# Output: 17
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see the random module documentation for more functions and other details.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s Start the Game&lt;/strong&gt;&lt;br&gt;
What’s the Game?&lt;br&gt;
*The computer will randomly select a number from 1 to 50.&lt;br&gt;
*A user will have 5 chance to guess the number.&lt;br&gt;
*To make the game interesting we can help the user to guess &lt;br&gt;
 the correct number.&lt;br&gt;
*If he guesses a number greater than the actual number then &lt;br&gt;
 we will tell him “Your guess is too high”.&lt;br&gt;
*If he guesses a number smaller than the actual number then &lt;br&gt;
 we will tell him “Your guess is too low”.&lt;br&gt;
*If he guesses the correct number in the given 5 chance then &lt;br&gt;
 It’s a win.&lt;br&gt;
*Otherwise, It’s a lose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to make it?&lt;/strong&gt;&lt;br&gt;
To make this game, we will simply create a file name game.py and we will write our entire code in this file. But before start writing the program, we will write pseudo code. The pseudo code is a way to structure your thinking process. We will break the problem into smaller parts and then we will try to solve it.&lt;/p&gt;

&lt;p&gt;Guessing Game Pseudo Code&lt;/p&gt;

&lt;p&gt;1.Start the game.&lt;br&gt;
2.Print the ‘How to play guide”&lt;br&gt;
3.Generate the random number from 1 to 50.&lt;br&gt;
4.Take the user input.&lt;br&gt;
5.Compare user input with the number that computer selected.&lt;br&gt;
6.If it’s equal then print ‘You win the game’.&lt;br&gt;
7.If it’s lesser then print ‘Your guess is too low’.&lt;br&gt;
8If it’s greater then print ‘Your guess is too high’.&lt;br&gt;
9.Repeat from step 4 to step 8 four more times to give him 5 &lt;br&gt;
 chance.&lt;br&gt;
 10.At last, if he is unable to guess then print ‘Sorry, you &lt;br&gt;
  lost the game’.&lt;/p&gt;

&lt;p&gt;*To make this game we will write the function and all the &lt;br&gt;
 logic of the game inside the function. So every time you &lt;br&gt;
 call the function the game will start. You can also do it &lt;br&gt;
 without making the function but by making a function, it &lt;br&gt;
 will make your code clean and clear. Functions also describe &lt;br&gt;
 as a group of statements and expression that perform a &lt;br&gt;
 specific task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# game.py

def guess_game():
    pass

# Here we use pass statement, so the interpreter will run the function without error.

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

&lt;/div&gt;



&lt;p&gt;Now let’s write the how to play guide. To write it we will use the print function.&lt;br&gt;
&lt;/p&gt;

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


# Number selected by the computer.
random_num = random.randint(1,50)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Taking input from the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;guess_num = input('Guess the number: ')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have to give the user 5 chance, and there will be some repetitive steps. To implement this we can use for loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for chance in range(5, 0, -1):
    if chance:
        print(f'You have {chance} chance to guess the number.')
        guess_num = input('Guess the number: ')
        if int(num) == random_num:
            print('Hurray!, You guess the correct Number')
            break
        elif int(guess_num) &amp;gt; random_num:
            print('Your guess is too high.')
        elif int(guess_num) &amp;lt; random_num:
            print('Your guess is too low.')
else:
    print(f'Sorry, you lost the game.\n The correct number was          {random_num}')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*First, we started a for loop using range function. You know &lt;br&gt;
 that range function takes three parameters: start, stop and &lt;br&gt;
 step. We give the start parameter 5, end  0 and step -1 &lt;br&gt;
 because we want to print the number of chances left every &lt;br&gt;
 time the user guesses the number.&lt;br&gt;
*Next, we write a for...else condition. The else block just &lt;br&gt;
 after for is executed only when the loop is NOT terminated &lt;br&gt;
 by a break statement. Inside for loop, in if condition, we &lt;br&gt;
 are taking the truthy values of variable chance. &lt;br&gt;
*In nested if condition we are comparing the number guess by &lt;br&gt;
 the user and random number generated by the random.randint() &lt;br&gt;
 function. According to the result, we are printing the &lt;br&gt;
 statements. We know that the type of the output of input &lt;br&gt;
 function is always the string that’s why we are using int() &lt;br&gt;
 function to convert it into the integer.&lt;br&gt;
*Once the user guesses the correct number, we don’t want our &lt;br&gt;
 loop to continue, that’s why we used break statement in case &lt;br&gt;
 of both numbers are equal.&lt;br&gt;
 *The moment it becomes zero the program will not enter into &lt;br&gt;
 the if condition. It will directly go to the else condition &lt;br&gt;
 and print the statement.&lt;/p&gt;

&lt;p&gt;See the entire code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# game.py

import random

# Function definition
def guess_game():
    print("Welcome to the Guessing Game.\nThe computer has selected one random number from 1 t0 50.\nGuess the number.\nLet's Start")
    random_num = random.randint(1, 50)
    for chance in range(5, 0, -1):
        if chance:
            print(f'You have {chance} chance to guess the number.')
            guess_num = input('Guess the number: ')
            if int(guess_num) == random_num:
                print('Hurray!, You guess the correct Number')
                break
            elif int(guess_num) &amp;gt; random_num:
                print('Your guess is too high.')
            elif int(guess_num) &amp;lt; random_num:
                print('Your guess is too low.')
    else:
        print(f'Sorry, you lost the game.\n The correct number was {random_num}')


guess_game()   # calling the funciton

# Output: 
'''
Welcome to the Guessing Game.
The computer has selected one random number from 1 t0 50.
Guess the number.
Let's Start
You have 5 chance to guess the number.
Guess the number: 25
Your guess is too high.
You have 4 chance to guess the number.
Guess the number: 13
Your guess is too high.
You have 3 chance to guess the number.
Guess the number: 6
Your guess is too high.
You have 2 chance to guess the number.
Guess the number: 3
Your guess is too high.
You have 1 chance to guess the number.
Guess the number: 2
Hurray!, You guess the correct Number
'''

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

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>python</category>
      <category>career</category>
      <category>programming</category>
    </item>
    <item>
      <title>BUILT IN FUNCTIONS - Python</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Tue, 31 May 2022 16:35:42 +0000</pubDate>
      <link>https://dev.to/introschool/built-in-functions-3a6k</link>
      <guid>https://dev.to/introschool/built-in-functions-3a6k</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Built-in Functions&lt;/strong&gt;&lt;br&gt;
In this section, we will discuss common built-in functions of all the data types and data structures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Numbers&lt;/strong&gt;&lt;br&gt;
abs()&lt;br&gt;
The abs() function return the absolute value of a given number. An input number could be an integer, float or complex.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = -20

abs(s)

# output: 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;float()&lt;br&gt;
The float() function return a floating point number from a number or string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = 2
float(s)
# output: 2.0

x = '32.44'
float(x)

# output: 32.44
# String should contain only digits.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;int()&lt;br&gt;
The int() function return an integer number from a number or string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = -3.43

int(s)
# output: -3

x = '45'

int(x)
# Output: 45
# String should only contain digits.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;round()&lt;br&gt;
The round() function rounds off to the given number of digits and returns the floating point number, if no number of digits is provided for round off, it rounds off the number to the nearest integer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# round(nmber, number of digits)
s = 30.654

round(s)
# output: 31

round(s, 1)
# Output: 30.7

round(s, 2)
# Output: 30.65
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt;&lt;br&gt;
capitalize()&lt;br&gt;
The capatilize() function returns a string with first letter capitalized and all other characters lowercased. It doesn't modify the original string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = 'we Are leArnIng PythON'

new_s = s.capitalize()
print(new_s)
# output: We are learning python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;lower()&lt;/p&gt;

&lt;p&gt;The lower() ftnction return an lowercase string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = 'We are learning Python'

new_s = s.lower()
print(new_s)

# output: we are learning python


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

&lt;/div&gt;



&lt;p&gt;upper()&lt;br&gt;
The upper() function return an uppercased string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = ‘We are learning Python’

new_s = s.upper()
print(new_s)

# output: WE ARE LEARNING PYTHON

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

&lt;/div&gt;



&lt;p&gt;title()&lt;br&gt;
The title() function returns a string with the capitalized first letter of each word.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = ‘We are learning Python’

new_s = s.title()
print(new_s)

# output: We Are Learning Python

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;List&lt;/strong&gt;&lt;br&gt;
append()&lt;br&gt;
The append() function adds a single item to the existing list. It doesn't return a new list; rather it modifies the original list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = [1, 2, 3.45, 7, 'Python', False]

s.append('Hello World')

print(s)

# output: [1, 2, 3.45, 7, 'Python', False, 'Hello World']

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

&lt;/div&gt;



&lt;p&gt;insert()&lt;br&gt;
The insert() function inserts an element at a given index. It doesn’t return anything. It modifies the existing list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# insert(index, element)
s = [1, 2, 3.45, 7, 'Python', False]

s.insert(2, 'Hello World')

print(s)

# output: [1, 2, 'Hello World', 3.45, 7, 'Python', False]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;remove()&lt;br&gt;
The remove() function searches for the given element in the list and removes the first matching element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = [1, 2, 3.45, 7, 'Python', False, 'Python']

s.remove('Python')

print(s)

# Output: [1, 2, 3.45, 7, False, 'Python']

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tuple&lt;/strong&gt;&lt;br&gt;
tuple()&lt;br&gt;
The tuple() function is used to create a tuple in Python. It takes any iterable like list, string, or dictionary as a parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tup1 = tuple('String')
print(tup2)
# Output: ('S', 't', 'r', 'i', 'n', 'g')

tup2 = tuple([1,2,3,4,5])
print(tup3)
# Output: (1, 2, 3, 4, 5)

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Dictionary&lt;/strong&gt;&lt;br&gt;
get()&lt;br&gt;
The get() function returns the value for the specified key if key is in dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vehicle = {'type': 'Car', 'color': 'Blue', 'price': 500000}

print('vehicle_type:', vehicle.get('type'))
print('vehicle_color:', vehicle.get('color'))

# output
# vehicle_type: Car
# vehicle_color: Blue

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

&lt;/div&gt;



&lt;p&gt;keys()&lt;br&gt;
The keys() function returns a view object that displays a list of all the keys in the dictionary. You can use for loop to get all the keys using this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vehicle = {'type': 'Car', 'color': 'Blue', 'price': 500000}

print(vehicle.keys())
# Output: dict_keys(['type', 'color', 'price'])

for key in vehicle.keys():
    print(key, ':', vehicle[key])
# output
# type : Car
# color : Blue
# price : 500000

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

&lt;/div&gt;



&lt;p&gt;values()&lt;br&gt;
The values() function returns the view object that displays the list of all the values in the dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vehicle = {'type': 'Car', 'color': 'Blue', 'price': 500000}

print(vehicle.values())
# Output: dict_values(['Car', 'Blue', 500000])

for value in vehicle.values():
    print(value)
# output
# Car
# Blue
# 500000

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

&lt;/div&gt;



&lt;p&gt;items()&lt;br&gt;
The items() function returns a view object that displays a list of dictionary's (key, value) tuple pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vehicle = {'type': 'Car', 'color': 'Blue', 'price': 500000}

print(vehicle.items())
# Output:dict_items([('type', 'Car'), ('color', 'Blue'), ('price', 500000)])

for key, value in vehicle.items():
    print(key, ':', value)


# output
# type : Car
# color : Blue
# price : 500000

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

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>programming</category>
      <category>python</category>
      <category>career</category>
    </item>
    <item>
      <title>Functions In Python</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Mon, 30 May 2022 18:07:12 +0000</pubDate>
      <link>https://dev.to/introschool/functions-3e5j</link>
      <guid>https://dev.to/introschool/functions-3e5j</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are the Functions?&lt;/strong&gt;&lt;br&gt;
 Till this point, you have seen the built-in functions like print(), type(), etc. Functions are a specific set of code statements that are designed to perform a specific task. You can think of functions as a machine which is designed for a specific task. It can or can not take inputs and gives the desired output on the base of its definition.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UX2q6mLi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1c91omyslvdaap728pa.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UX2q6mLi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1c91omyslvdaap728pa.jpg" alt="Image description" width="720" height="540"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;How to Define a Function?&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Function
def function_name(arguments):
    '''
    Body of the function.
    '''

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

&lt;/div&gt;



&lt;p&gt;*A  def  keyword is used to create a function.&lt;br&gt;
*If arguments are needed in the function you can give them &lt;br&gt;
 inside the parenthesis( ).&lt;br&gt;
*Functions Arguments: Function arguments are also called *parameters. These parameters are like placeholders that you &lt;br&gt;
 can use inside a function. You can give as many parameters &lt;br&gt;
 as needed in the function.&lt;br&gt;
*Inside the body of the function, you can write statements &lt;br&gt;
 and expression that gives a function an ability to perform &lt;br&gt;
 the given task.&lt;br&gt;
 *You can also give a function description inside a &lt;br&gt;
 docstring. Docstring(‘’’ ‘’’) is basically to describe what &lt;br&gt;
 the function does.&lt;br&gt;
*A function can have an optional return statement. A return &lt;br&gt;
 statement is used to give output value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Let's create a function that can take two numbers and gives the sum of those number as an output.

def add(a,b):
    '''
    Function to add two numbers
    '''
    sum = a + b
    return sum


# Create a function which takes a name as an argument and say Hello to that name.

def say_hello(name):
    print(f'Hello {name}')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*The function add takes two numbers and return the sum. In &lt;br&gt;
 this function return statement is used.&lt;br&gt;
*The function say_hello takes a name as an argument which &lt;br&gt;
 would be a string data type and print the message saying ‘hello ’. In this function, there is no need to use a &lt;br&gt;
 return statement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calling a Function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now you know how to define a function, but to use a function in your code you have to call a function. Let’s see how you can call a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Calling a function
add(4,5)
# Output: 9

add(9,10)
# Output: 19

say_hello('Kumar')
# Output: Hello Kumar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Global and Local Variables&lt;/strong&gt;&lt;br&gt;
You know what a variable is but when you write a function it’s really important to know the difference between global and local variables.&lt;/p&gt;

&lt;p&gt;Global Variables&lt;br&gt;
Global variables are the variables which have global scope. It means that global variables are visible throughout the program.&lt;/p&gt;

&lt;p&gt;Local Variables&lt;br&gt;
Local variables are the variables which have local scope. Local variables are defined inside the function. It means that they are visible only inside the body of the function. You can not access them outside of the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Global and Local Variables 

x = 2

def func1():
    print(a)

func1()
# Output: 2
'''
Here you can see that x is a global variable that's why you can access this inside a function. 
# Global and Local Variables 

x = 2

def func1():
    print(a)

func1()
# Output: 2
'''
Here you can see that x is a global variable that's why you can access this inside a function. 
'''

def func2():
    y = 'string'
    print(y)


print(y)
'''
Output:
NameError: name 'y' is not defined

This code gave an error because in the global scope there is no variable y and here we are accessing the variable y in the global scope.
''' 


func2()

# Output: string
'''
But if you call function func2 the output will be 'string', because y is a local variable inside the function func2 so this function has access to the variable y.
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can give the same name to the global and local variable, Python interpreter will treat them as a different variable because they are defined in a different scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;msg = 'Hello World'

def greet():
    msg = 'Hello Python'
    print(f'local: {msg}')


greet()
print(f'global: {msg}')

# Output
# local: Hello Python
# global: Hello World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>programming</category>
      <category>python</category>
      <category>career</category>
    </item>
    <item>
      <title>Python Course Intro</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Sun, 29 May 2022 08:00:29 +0000</pubDate>
      <link>https://dev.to/introschool/python-course-intro-3h3l</link>
      <guid>https://dev.to/introschool/python-course-intro-3h3l</guid>
      <description>&lt;p&gt;This is a course intro video of Python for Data Science Course&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>python</category>
      <category>datascience</category>
      <category>programming</category>
    </item>
    <item>
      <title>Errors In Python</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Sun, 29 May 2022 07:38:32 +0000</pubDate>
      <link>https://dev.to/introschool/errors-in-python-3pg</link>
      <guid>https://dev.to/introschool/errors-in-python-3pg</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you write any program, it’s hard to write an error-free program. Whenever you make mistakes while writing the program, Python interpreter throws an error message. In this section, we will see the common errors that occur while writing a program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax Errors&lt;/strong&gt;&lt;br&gt;
Every programming language has its own syntax. The syntax is particular of writing the code. So if you make any mistake in syntax, the python interpreter throws a syntax error with an error message. See the below code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Syntax error

list = [1, 2, 3, 4, 5]

for elm in list
    print(elm)
'''
for elm in list
      File "&amp;lt;stdin&amp;gt;", line 1
    for elm in list
                  ^
SyntaxError: invalid syntax
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you can see that in for loop colon(:) sign is missing that’s why Python throws this error. So whenever you encounter syntax error, look at your code syntax.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exceptions&lt;/strong&gt;&lt;br&gt;
Even if your syntax is correct, Python throws an error after running the program. These types of error called runtime errors or exceptions. Let’s see some common exception.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TypeError&lt;/strong&gt;&lt;br&gt;
TypeError is raised when a function is applied to incorrect object. See the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def add2(n):
    return n + 2

add2('hello')

'''
Output: TypeError: must be str, not int
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;IndexError&lt;/strong&gt;&lt;br&gt;
IndexError is raised when the index of any sequence datatype(String, LIst, tuple) is out of range. See the below example.&lt;br&gt;
&lt;/p&gt;

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

print(l[5])

'''
Output: 
IndexError: list index out of range
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NameError&lt;/strong&gt;&lt;br&gt;
NameError is raised when a variable is not found in the local or global scope. See the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tax_cut = 50

def bill(amount):
    pay = amount+taxcut
    return pay

bill(100)

'''
Output:
NameError: name 'taxcut' is not defined

The error occurs because taxcut is not in a global or local scope.
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;KeyError&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The keyError is raised when the key is not found in the dictionary. See the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;d = {1: 'a', 2: 'b'}

print(d[3])

'''
Output:
KeyError: 3
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;IndentationError&lt;/strong&gt;&lt;br&gt;
IndentationError is raised when there is incorrect indentation. See the below example.&lt;br&gt;
&lt;/p&gt;

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

for elm in l:
print(elm)

'''
Output:
IndentationError: expected an indented block
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ZeroDivisionError&lt;/strong&gt;&lt;br&gt;
ZeroDivisionError is raised when the second operand of division or modulo operation is zero. See the below example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(1/0)
# Output: ZeroDivisionError: division by zero

print(1%0)
# Output: ZeroDivisionError: division by zero
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>Control Flow In Python - Part 2</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Mon, 25 Oct 2021 15:58:33 +0000</pubDate>
      <link>https://dev.to/introschool/control-flow-in-python-part-2-1ane</link>
      <guid>https://dev.to/introschool/control-flow-in-python-part-2-1ane</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The range() Function&lt;/strong&gt;&lt;br&gt;
The range function is used to get sequence of numbers. The syntax of &lt;strong&gt;range()&lt;/strong&gt; function is &lt;strong&gt;range(start, stop, step)&lt;/strong&gt;. Here you can give start parameter, stop parameter and you can also give step parameter, by default value is 1 for step parameter.&lt;/p&gt;

&lt;p&gt;In the range function, start and step parameter are optional. The stop parameter is the upper limit, It means that function generates numbers up to this number, it range doesn’t include this number.&lt;/p&gt;

&lt;p&gt;You can use range function to print numbers in a particular range. You can also use range function to iterate over the list, tuple, string data structure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# range function
for i in range(5):
    print(i)
'''
# Output:
0
1
2
3
4
'''

# print even numbers from 0 to 10
for i in range(0,10,2):
    print(i, end=', ')

'''
# Output:
0, 2, 4, 6, 8,
'''

# iteration over list.
lst = ['hello', 2, 4.3, 0]

for i in range(len(lst)):
    print(lst[i])

'''
# Output:
hello
2
4.3
0
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;While Loop&lt;/strong&gt;&lt;br&gt;
While loop executes statements and expression until the condition is true. See the while loop syntax below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# While Loop


while &amp;lt;condition&amp;gt;:
    &amp;lt;statements&amp;gt;

# Example
i = 1
while i &amp;gt; 0:
  print(i)
  i -= 1

'''
Output:
10
9
8
7
6
5
4
3
2
1
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see in the above example that while loop prints the variable i until the condition &lt;strong&gt;i &amp;gt; 0&lt;/strong&gt; was true, The moment &lt;strong&gt;i&lt;/strong&gt; become 0, the loop gets terminated.&lt;/p&gt;

&lt;p&gt;The while loop can continue for infinite times if you don’t terminate the loop. So check the condition and statement that you are putting in while loop. For example, if we wouldn’t decrement i, then this loop would have been an infinite loop because every time the condition would be satisfied.&lt;/p&gt;

&lt;p&gt;The while loop requires already defined variables unlike for loop. If you didn’t define the variable that you are using in the loop, the interpreter will give error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pass, Break and Continue Statement&lt;/strong&gt;&lt;br&gt;
Now you have an idea that how the flow of the loops works? You can alter the flow by using these statements. They affect the flow of the loop in a different-different way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pass Statement&lt;/strong&gt;&lt;br&gt;
Pass statement doesn’t affect the flow, it just works as a placeholder. Suppose you write a  condition, if the condition is satisfied it follows the body of . If you didn’t write any logic inside the body of , the python interpreter will give some error, to avoid that error you can write pass statement for now. By using the pass statement, the interpreter will run the loop as it is.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in range(10):
    if  i == 3:
        pass
    print(f'num:{i}')

print('out of the loop')

# Output
num:0
num:1
num:2
num:3
num:4
num:5
num:6
num:7
num:8
num:9

out of the loop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Break Statement&lt;/strong&gt;&lt;br&gt;
Break statement, as you can get the idea from the name that it is used to break the loop. It generally used after if conditional statement. Once Python interpreter comes across break statement, it terminates the loop. See the example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in range(10):
    if  i == 3:
        break
    print(f'num:{i}')

print('out of the loop')

# Output
num:0
num:1
num:2

out of the loop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that loop gets terminated once it encounters i is equal to 3. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continue Statement&lt;/strong&gt;&lt;br&gt;
Continue statement also affects the flow of the loop. It is generally used after  conditional statement. If you want to skip over the part of the loop then you can use this statement. See the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in range(10):
    if  i == 3:
        continue
    print(f'num:{i}')

print('out of the loop')

# Output:
num:0
num:1
num:2
num:4
num:5
num:6
num:7
num:8
num:9

out of the loop

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

&lt;/div&gt;



&lt;p&gt;Here you can see that interpreter skips the part where i is equal to 3. So this is how you can use &lt;strong&gt;continue&lt;/strong&gt; statement.&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Control Flow In Python</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Mon, 18 Oct 2021 17:30:32 +0000</pubDate>
      <link>https://dev.to/introschool/control-flow-in-python-4h4a</link>
      <guid>https://dev.to/introschool/control-flow-in-python-4h4a</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If-Else&lt;/strong&gt;&lt;br&gt;
In this session, we will learn the decision making part of programming. Sometimes you want your code to run only when a certain condition is satisfied. We will see how you can do it in this chapter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic if Statement&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Basic If syntax
x = 2
if x == 2:
    print('x is:', x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By looking at the above code you can understand that this code will print x only if x is equal to 2. In this code, ‘x’ will not get printed if it is anything else other than 2.&lt;/p&gt;

&lt;p&gt;So &lt;strong&gt;if statement&lt;/strong&gt; evaluates the condition first and executes the statement inside the body only when the condition is true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if &amp;lt;condition&amp;gt;:
    &amp;lt;statement&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;If-Else Statement&lt;/strong&gt;&lt;br&gt;
If...else statement is used when you want to specify what a program should do when the condition is false. See the below syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# if...else
if &amp;lt;condition&amp;gt;:
    &amp;lt;statement&amp;gt;
else:
    &amp;lt;statement&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In if...else syntax, if the condition is true,  inside the &lt;strong&gt;body of if&lt;/strong&gt; will be executed and if the condition is false then the  inside the &lt;strong&gt;body of else&lt;/strong&gt; will be executed.&lt;br&gt;
See the below example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name = 'Kumar'

if name == 'Kumar':
    print(f'Hello {name}')
else:
    print("You are not 'Kumar'")


# Output: Hello Kumar
'''
In the above code snippet, first &amp;lt;if&amp;gt; evaluates the condition name == 'Kumar', which is true, so the &amp;lt;statement&amp;gt; inside the body of &amp;lt;if&amp;gt; got executed. If the condition would have been false then the interpreter would come to &amp;lt;else&amp;gt; statement.
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;If--Elif--Else Statement&lt;/strong&gt;&lt;br&gt;
If you want to check multiple conditions then you can use if...elif...else syntax. Here &lt;strong&gt;elif&lt;/strong&gt; is short for &lt;strong&gt;else if&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# if...elif...else

if &amp;lt;condition&amp;gt;:
    &amp;lt;statement&amp;gt;
elif &amp;lt;condition&amp;gt;:
    &amp;lt;statement&amp;gt;
else:
    &amp;lt;statement&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you know that  and  statements will execute only if the condition is true, if both the conditions are false then the  statement will execute.&lt;br&gt;
&lt;/p&gt;

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

if x == 2:
    print('Inside the body of if')
elif x == 5:
    print('Inside the body of elif')
else:
    print('Inside the body of else')


# Output
# Inside the body of elif
'''
Because only &amp;lt;elif&amp;gt; condition is true
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;For Loop&lt;/strong&gt;&lt;br&gt;
Now we will learn how to use &lt;strong&gt;for&lt;/strong&gt; loop. For loop is used to iterate over data structures like String, List, Tuple and Dictionary. &lt;br&gt;
If you are asked to print each value in a string or list, How would you do that? You might be thinking that using index can be one option. But it is a tiresome task. See the below code.&lt;br&gt;
&lt;/p&gt;

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

print(s[0])
print(s[1])
print(s[2])
print(s[3])
print(s[4])
print(s[5])

# Output
# 1
# 2
# 3
# 4
# 5
# 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For loop makes it easy to access each value of any sequence type data structure. We will see that how you can use For loop to get the value of String, List, Tuple and Dictionary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt;&lt;br&gt;
String is a sequence of characters. To access each character, we can use For loop. See the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# String
s = "Python is awesome"

for char in s:
    print(char)

# Output
# P
# y
# t
# h
# o
# n
# 
# i
# s
# 
# a
# w
# e
# s
# o
# m
# e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the For loop syntax, &lt;strong&gt;char&lt;/strong&gt; is a variable that refers to characters in the string. The loop runs from the starting of the string and stops at the end of the string. In the first iteration, char refers to the first character, in next iteration char refers to the second character and keeps on accessing all the characters of the string.&lt;/p&gt;

&lt;p&gt;Char is just a variable, you can name it according to yourself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List&lt;/strong&gt;&lt;br&gt;
List is a sequence of different types of data values. See the below code to access list values using For loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# List

lst = [1, 2, True, 4.234, False, 'List']

for elm in lst:
    print(elm)

'''
Output:
1
2
True
4.234
False
List
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above for loop syntax, the variable refers to each data value. So in each iteration each data value gets printed.&lt;br&gt;
Tuple&lt;br&gt;
Tuples are also the same as list but the difference is you can not change these values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Tuple
tup = (1, 2, True, 4.234, False, 'List')

for elm in lst:
    print(elm)
'''
Output:
1
2
True
4.234
False
List
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Dictionary&lt;/strong&gt;&lt;br&gt;
In the dictionary, there are three ways you can iterate the dictionary.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Iterating through all keys.&lt;/li&gt;
&lt;li&gt;Iterating through all the values.&lt;/li&gt;
&lt;li&gt;Iterating through all key-value pairs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Iterating through all keys&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person = {'name':'Kumar', 'age':23, 'email': 'kumar.com'}

for key in person:
    Person[key]
'''
# Output:
'Kumar'
23
'Kumar.com'
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Iterating through all the values&lt;/strong&gt;&lt;br&gt;
For iterating through values, there is a method called values() that we can use to access dictionary values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person = {'name':'Kumar', 'age':23, 'email': 'kumar.com'}

for value in person.values():
    print(value)
'''
# Output:
Kumar
23
Kumar.com
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Iterating through all the key-value pairs&lt;/strong&gt;&lt;br&gt;
If you want to iterate through all the key-value pairs then you have to use the method called items(). See the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person = {'name':'Kumar', 'age':23, 'email': 'kumar.com'}

for key, value in person.items():
    print(f'{key}:{value}')
'''
# Output:
name:Kumar
age:23
email:kumar.com
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Set&lt;/strong&gt;&lt;br&gt;
Using for loop we can access each element of the set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s = {1, 2, 4, "hello", False}

for elm in s:
    print(elm)

'''
# Output
False
1
2
4
hello
'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Data Structures In Python - Part 2</title>
      <dc:creator>Introschool</dc:creator>
      <pubDate>Sat, 16 Oct 2021 17:03:07 +0000</pubDate>
      <link>https://dev.to/introschool/data-structures-in-python-part-2-2l70</link>
      <guid>https://dev.to/introschool/data-structures-in-python-part-2-2l70</guid>
      <description>&lt;p&gt;&lt;a href="https://www.youtube.com/channel/UCQ8FDc6mi2BxxUSz8zcsy-A"&gt;Subscribe to our Youtube Channel To Learn Free Python Course and More&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the Dictionary?&lt;/strong&gt;&lt;br&gt;
Dictionaries are an unordered collection of objects. It means that the Dictionary doesn’t support indexing, instead of it,  Dictionary is a collection of key-value pairs. In the &lt;strong&gt;List&lt;/strong&gt;, each value has an index but in the &lt;strong&gt;Dictionary&lt;/strong&gt; each value is associated with the particular key, that’s why the Dictionary is an unordered collection of different values or object. To create a dictionary curly braces{ } are used.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7lf-bSXk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h01etdtfakmhayzzvqud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7lf-bSXk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h01etdtfakmhayzzvqud.png" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;How to Define a Dictionary?&lt;/strong&gt;&lt;br&gt;
To create a dictionary curly braces{ } are used. There are various ways you can define a dictionary. See the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;d = {'game': 'Cricket', 'type': 'One-day', 'over': 50, 'players': 11}
type(d)
# Output: &amp;lt;class 'dict'&amp;gt;

print(d)
# Output
# {'game': 'Cricket', 'type': 'One-day', 'over': 50, 'players': 11}

# dict() function
'''
You can pass the list of tuples, where each tuple will be a key-value pair.
'''
t = dict([('game', 'Cricket'),('type', 'One-day'),('over', 50),('players', 11)])
'''
You can also use mixed type keys to create a dictionary.
'''
c = dict([(1,[1, 2, 3]), ('name', 'Ramesh')])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to Access Dictionary Value?&lt;/strong&gt;&lt;br&gt;
You can access a dictionary value by its key. Just like List, you can use square brackets to access a value, Instead of an index, write a key in the brackets. See the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Accessing a dictionary value
d = {'game': 'Cricket', 'type': 'One-day', 'over': 50, 'players': 11}

print(d['game'])
# Output: Cricket

print(d['over'])
# Output: 50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Dictionaries are Mutable&lt;/strong&gt;&lt;br&gt;
Yes, Dictionaries are mutable, you can change the dictionary value by using its key. See the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Changing Dictionary Values
c = dict([(1,[1, 2, 3]), ('name', 'Ramesh')])

print(c)

# Output
# {1: [1, 2, 3], 'name': 'Ramesh'}


'''
Suppose if you want to change the 'name' in this dictionary then how would you do that?
'''
c['name'] = 'Kumar' 

print(c)
# Output
# {1: [1, 2, 3], 'name': 'Kumar'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The ‘in’ Operator&lt;/strong&gt;&lt;br&gt;
You can use ‘in’ operator to check whether the key present in the dictionary or not. If the key is present, it will return True otherwise False.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# The 'in' Operator
d = {'game': 'Cricket', 'type': 'One-day', 'over': 50, 'players': 11}

print('game' in d)
# Output: True

print('type' not in d)
# Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Set&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;What is Set?&lt;/strong&gt;&lt;br&gt;
Set is an unordered collection of immutable data values. It means that the &lt;strong&gt;List&lt;/strong&gt; and the &lt;strong&gt;Dictionary&lt;/strong&gt; cannot be a value in the &lt;strong&gt;Set&lt;/strong&gt;. The Set doesn’t contain duplicate values, all values in the set will be unique. Set is unordered collection because it doesn’t support indexing. To define a set you can use curly braces or Python’s built-in function &lt;strong&gt;set()&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aoLPS1vE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4l3hkjtf9hxjt4igxe2n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aoLPS1vE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4l3hkjtf9hxjt4igxe2n.png" alt="Image description" width="666" height="222"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;How to Define Set?&lt;/strong&gt;&lt;br&gt;
To define a set you can use either { } or you can use Python’s built-in function set(). The set() function takes any data object which has an index like &lt;strong&gt;String, List, and Tuples&lt;/strong&gt;. See the below code. To define an empty set, instead of curly braces use set() function. The interpreter assumes { } as dictionary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Define an empty Set
b = {}
t = set()

type(b)
# Output: &amp;lt;class 'dict'&amp;gt;

type(t)
# Output: &amp;lt;class 'set'&amp;gt;

set1 = set('Books')
set2 = set([1,1,2,3,4,4,5,6])
set3 = set(('one', 'two', 'one', 'three', 'four', 'two'))

print('set1:', set1)
print('set2:', set2)
print('set3:', set3)

# Output
# set1: {'B', 'k', 's', 'o'}
# set2: {1, 2, 3, 4, 5, 6}
# set3: {'four', 'two', 'one', 'three'}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How to Add or Remove Element from the set?&lt;/strong&gt;&lt;br&gt;
You can not access an individual value in the set but you can definitely add or remove the value. See the below code. To add the value in the set you can use built-in function &lt;strong&gt;add()&lt;/strong&gt; and for removing the value you can use &lt;strong&gt;discard()&lt;/strong&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Adding the value
s = {4, 'Text', True, False, 3.14}
s.add('Hello')

print(s)
# Output
# {False, True, 3.14, 4, 'Text', 'Hello'}

# Removing the value
s.discard(True)
print(s)

# Output
# {False, 3.14, 4, 'Text', 'Hello'}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Set Operations&lt;/strong&gt;&lt;br&gt;
You can perform all the operations that you can perform on the mathematical set. Let’s see them in detail.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Union&lt;/strong&gt;&lt;br&gt;
The Union of two sets is a set of all values present in both the sets. You can use | operator or &lt;strong&gt;union()&lt;/strong&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Union of sets

x = {1, 4, 6, 3, 9}
y = {'a', 'b', 'c', 4}

xy = x | y
print('xy', xy)
# Output
# {'c', 1, 3, 4, 6, 9, 'a', 'b'}

# Using union() function.
x.union(y)
# Output
# {'c', 1, 3, 4, 6, 9, 'a', 'b'}

y.union(x)
# Output
# {'c', 1, 3, 4, 6, 9, 'a', 'b'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Intersection&lt;/strong&gt;&lt;br&gt;
The intersection of two sets is the set of common values present in each set. You can use &amp;amp; operator or &lt;strong&gt;intersection()&lt;/strong&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Intersection
x = {1, 4, 6, 3, 'c'}
y = {'a', 'b', 'c', 4}

# Using &amp;amp; operator
x_and_y = x &amp;amp; y
print(x_and_y)
# Output
# {'c', 4}


# Using intersection() method.
x.intersection(y)
# Output: {'c', 4}

y.intersection(x)
# Output: {'c', 4}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Difference&lt;/strong&gt;&lt;br&gt;
The difference of two sets is the set of values that are only present in the one set not in the other set. See the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Difference
x = {1, 4, 6, 3, 'c'}
y = {'a', 'b', 'c', 4}

# Using ‘-’ operator
x_diff_y = x - y
print(x_diff_y)
# Output
#{1, 3, 6}


y_diff_x = y - x
print(y_diff_x)
# Output
# {'a', 'b'}

# Using difference() method.
x.difference(y)
# Output:{1, 3, 6}

y.difference(x)
# Output: {'a', 'b'}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Symmetric Difference&lt;/strong&gt;&lt;br&gt;
The symmetric difference of two sets is the set of values that are present in both the sets except that are common values. You can use ^ operator or symmetric_difference() method to get the symmetric difference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Symmetric Difference
x = {1, 4, 6, 3, 'c'}
y = {'a', 'b', 'c', 4}

# Using '^' operator
x_sdiff_y = x ^ y
print(x_sdiff_y)

# Output
# {1, 3, 6, 'a', 'b'}


# Using symmetric_difference() method.
x.symmetric_difference(y)
# Output:{1, 3, 6, 'a', 'b'}

y.symmetric_difference(x)
# Output: {1, 3, 6, 'a', 'b'}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The ‘in’ Operator&lt;/strong&gt;&lt;br&gt;
Now you are familiar with the ‘in’ operator. See the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# The 'in' Operator
y = {'a', 'b', 'c', 4}

print('c' in y)
# Output: True

print(5 not in y)
# Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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