Python Full Course – Learn Python in 12 Hours | Python Tutorial For Beginners | Edureka

Python is more than just
a programming language. It is also a great
place to begin. If you're just starting to code with the popularity and
versatility that python bags. No wonder it is a great time
to Learn Python Programming. Hi. I welcome you all to
this full court session on Python Programming and what follows is hopefully
a crash course of everything that you need to know
to start out with python, but before we begin, Begin, let's talk
about our agenda for today. So we're going to start out by
introducing you to python here.

We are also going to talk
about the market trends and overview of python. Also, we're going
to give you a guided way of becoming a python developer. Now next. We are going to talk
about the step-by-step installation of a python IDE and we are going
to also help you run your first Python program
across various ideas. Now next we're going to talk
about python Basics here. We're going to talk about
comments variables data types and Traitors in Python now
followed by which we are going to talk about a few popular
python libraries like numpy and sciPy now next. We're going to get
a little deeper here. We're going to talk
about file handling and functions in Python. We also going to discuss Concepts such as object
oriented programming classes and inheritance in Python
now followed by that. We have a final topic which is web development
and web scraping in Python here.

We are also going to talk
about Frameworks associated with python like Django flask
and web 2 pi with that. I come to the end of the agenda. Also currently take up
this time to subscribe to us. And don't forget to hit
that Bell icon to never miss an update from the
Edureka YouTube channel. Also check out our Python
Programming certification course the link to which is
in a description box below. So without Much Ado,
let's get started. Fighting is the fastest growing
language in terms of developers libraries and applications that it can be used
for it could be machine learning artificial intelligence
web development anything that you can think of python
has always got you covered.

Now before we get started, please subscribe to the channel
and turn on notifications for all of our future
videos with that. Let's go ahead with the agenda
for today's session. We shall understand. What python We is and why it is so popular
thereafter the features that python has and where it
is used in the industries. Finally. We can take a look at
how to get started off with the python Basics
and end our session with the career opportunities that by then holds for us.

Let's move ahead
with the first topic for today. What is python well python is a general-purpose
programming language, which is high-level easy to learn and dynamically
initialized the development of python started out as
a hobby for its creator. Your Divine resume because he wanted
to make a language that was beautiful
to look at and easy for everybody to read to do this
he used indentations instead of curly braces to basically
describe the blocks of code that came inside the language
the language went on but did not receive love as it was slow compared
to the other languages now with the rise
of machine learning and artificial intelligence
python has come into the spotlight because it makes the work
much more productive and much more easy
why Why is that? Well it is because of
the amazing computing power that we have.

We just won't work to be
much more productive. Even if it takes a lot of time so that basically wraps
of this topic of what does python having that understood let us move ahead and understand why
python is popular comparing it to the other languages python
is the best language to get started off
with it's easy syntax and high level features make
it one of the best language for anybody to get started
off with programming. Maybe kids or veterans it is
the language for everybody. The next reason is that python is an open
source language meaning that it is free
for anybody to use every day.

There are thousands
of programmers who come together online
in making python better and efficient you modify
the code you break the code and you make the code
you're allowed to do it without any problems. Moving ahead. Bison can be used to make almost anything gy
applications web applications. Mobile app server side coding
artificial intelligence machine learning algorithms anything that you want to make
python will always have the way to do it lastly. There is a huge
community of people who come together to make
the libraries or modules that can be used
to obtain a Solutions just for an example machine learning
algorithms are already available and you can use them
to obtain your Solutions. But your productivity right up there you code
is much more lesser. You can see why people
around the world Four bytes and so much features make
a language attractive and that is what python is made
up of features that make anybody want
to start coding with it. Let us now see
the different features that python has in store for us. The most well-known feature of
python is its Simplicity python has made programming fun because it is simple it makes
you think move for your solution rather than the syntax
the next important feature is that python is
an open source language, which means that it is free for anybody to use
use modifications to python are also allowed
without any problems which brings us to its next feature portability
python supports portability, which means that you
can write your code and share it with anybody
that you want to and it would work the same way as it does for you when you run the code this
makes movements of projects and systems much more easier.

Our next feature are the
embedding properties chances are that certain languages
May perform certain functions better than python, but that does not stop you. As python suppose adding code of other languages into itself
to run those functions, which makes python all
the more powerful with that. Let us move over to the next
feature interpretation python is interpreted line by line, which means the management
of memory and CPU and debugging of the code much more simple
if you wonder by now whether python is the language
to get started off with let me tell you that it is python has
a huge Library support which would help you
to obtain solutions to your problems easier. You can get started off with
data science web development on the go with python. You may have had questions. Like how do developers
make applications that are so well
related to a domain that is because
of object-oriented Concepts python supports. Oops, meaning that you can model a real
word problem into your code and have security for it such that access to
them is restricted which helps you replicate
real world scenarios. Now that we know all
the amazing features that python has for us.

Why don't we look
at a few of the most? Alone companies who use
Python Google is the most known Tech Giant who uses python to provide better search features
to its users Dropbox is a cloud platform to save
data online its client and server applications
have been coded using python Netflix
uses machine learning with python to learn the taste of its users cluster
them into groups and then recommend them shoes
to retain them for longer the National Security
Agency uses python for cyber security analysis, and for the encryption
and decryption purposes. The BitTorrent application which is used for peer-to-peer communication
started out as a simple python file NASA scientists use
Python to perform calculations which helps them reduce time
and makes their work easier. So these are the major companies
who use python as you may know python is
a very important language and it would definitely be beneficial if you start learning
with now you would wonder how do we get started off
with learning python? Let me help you with that. So to get started off with learning this amazing
programming language you would firstly need the basics which are variables
datatypes and operators' which helps you
to understand data and the different data types that you can use such as
numeric lists tuples and so many more naming data
and Performing operations which can help you to obtain
logic or simple additions or subtractions and so forth once you understand that you can move
ahead to understand res which can be used to store data
in a structured manner nextly understand
the flow control twerking and how you can manipulate
it using Loops such as the for Loop in the while loop
and conditions which are the if else statements you can then
study about how to make methods which are basically used
to perform certain functions which can be as simple as adding numbers to performing
the most complex of work that you can think
of liter learn how files are handled where you can read data
from files and write data to the files you can then
learn about Hoops by understanding classes and objects and were
they important This is and finally to master it
all you need to practice python as much as you can because practice is
what makes you better at it.

Once you are done
understanding the basics. What do you do you master it? There are a variety of careers that are at your disposal
stick to the one that you feel is your goal
and start mastering it which brings us
to the career opportunities that by then holds for us web
app development is an option that you can choose you have
Frameworks such as Django and flowers that can. Can be used to create web
applications game development is also a career option that is available where you can create AI enemies
and bosses and graphic textures. Accordingly. Big Data analysis
is a booming field which can be used to obtain
data helpful to make decisions and help take risks for better profits web app
testing is also an option where you can report
bugs and make sure that a website works as needed data scientist
machine learning engineer artificial intelligence are
some of the fields that Everybody wants to get into and it is clearly one
of the jobs that looks like it would have a long life cycle smart iot
devices are another place where you can use Python and build better infrastructure
for connecting the world.

So those are some of the most
well-known career opportunities that python has for you. There are many more such as a software developer automation
engineer and much more. So now I hope all of you know, what python is and why
everybody loves it so much. I hope all of you
would consider learning. Learning python because it is just fun to learn and easy to program with Netflix is the leader
of its plan for video streaming and for all take savvis.

This Market giant has revealed that python is the secret
to its success before we begin just
make sure you subscribe to our Channel and hit
the Bell icon to stay updated with all the latest
Eddie Rekha videos coming back towards the session. Let's first begin with a small
introduction to Netflix and We shall move on to see how Netflix uses python in various sectors
such as for its CDN, which is open connect Fordham and engineering and machine
learning big data analytics and scientific experimentations video encoding animations
security and finally for monitoring and auto remediation.

So without any further delays, let's get started Netflix as we all know is an American
company which renders video-on-demand Services. It has about a hundred and
forty eight million subscribers through out the world and the number however keeps
growing each day in a period of approximately two decades
Netflix has emerged as the king of its clan
for the biggest TV series and movies throughout the world being the fastest
growing brand of America and having a revenue
of twenty point five billion till June 2019. It's enough for it
to be an eye-catcher. Thereby interesting all
into its technical spheres. Let's move on to see how Netflix uses python
in its various domains. Engineers at Netflix admit that they use Python
for the full content lifecycle from deciding which content
to fund all the way to operating the CDN that serves the final video
248 million subscribers.

Now that we've taken the name
of Syrian over here. Let's move on to see what
this is and how it makes use of python the CDN or
content delivery Network that Netflix makes use
of is open connect. This basically comes into picture when you
hit the play button. All the content delivered
to the end user is looked after by this CDN
open connect basically requires various other software's
to design built and operated which are in turn
written in Python. Not just this the network devices underlying
this CDN our python applications since python is prominent
in solving network issues. Now that we are aware of the
first component open connect. Let's move on to see how Netflix uses
python for its demand engineering the And
engineering team is responsible for handling Netflix clouds
Regional fail overs traffic Administration
capacity operations management, which is looking after the limit
up to which the content can be made serviceable
and Fleet efficiency. The library is used by
this team are the numpy and the Sci-Fi Library, which is used for performing
numerical analysis boat or three which is the software
development kit of the Amazon web services for python.

This helps python
developers integrate. On into AWS. Thereby allowing development
in the infrastructure radius, Q or r q, which is a python Library which helps to keep
track of the tasks that are present in the queue
and allows their execution. Thereby allowing the management
of asynchronous workloads flask Netflix uses flask for python web development
Netflix uses flask apis to bind all of the
previous segments together. Not just this Netflix also
makes use of Jupiter know Books along with interact which is an extension for Jupiter on a large scale
Jupiter is known to be popular for data analysis. It serves very well
in operation data analysis and visualization which in turn helps in
detecting capacity regressions. Now, let's move on to see how python is used for machine learning machine
learning ranges from creating personalization algorithms to figuring out
the use cases personalization algorithms helped to train
the machine learning models as As per the Netflix standard it also provides personalized
recommendations outlines on a day-to-day
basis label Generations Etc.

The library is required
to learn deep neural networks are tensorflow Kara's
and python watch whereas XG boost and light GBM for gradient
boosted decision trees. Netflix has also developed quite
a few higher level libraries that help in combining
with the work area such as fact logging feature
extraction publishing Etc. Apart from all this Netflix also
makes use of meta flow to create machine learning projects. The Big Data team is responsible
to execute the ETL or the extract transform load
and ad hoc pipelines. A major part of this orchestration
is written in Python. This team uses a scheduler
which runs on jupyter notebooks with paper mill to produce
job types with templates. For example, spark Presto Etc. In addition to this the team
has also created an event. In driven platform which is built
completely on python. They've created a number
of events and combined it into a single one allowing
Netflix to filter react and Route events. Okay. So now let's move on to see how python is used
for scientific experimentations.

This platform is basically
created for experimentations and to allow A/B Testing guys
a be testing is also called a split testing and it deals with comparing
two versions and figuring out the better performing. Among them the scientific
experimentation team can also present new Innovations
in data statistics and visualization. The python framework that has implemented
here is metrics report which is based on Pi Pika and allows writing of
reusable parameterised queries for the statistics sector by arrow and rpy to are used
to calculate the statistics in either python or are plotly helps
in visualizations video encoding or media cloud. During this team
is responsible for encoding and re-encoding tasks
for the Netflix catalog.

Python is used approximately
450 projects such as the V math which is video multi-method
assessment fusion and mezzanine file system
computer vision solution, which deals with imagery using
Archer Etc Netflix animation and envy FX python forms
the base for all animations and visual effects
at Netflix Maya and nuke which are 3D and 2D. D computer graphic applications
are united using python. Now, let's move on to see how Netflix uses python for its information
security Netflix uses python pad information systems for auto remediation
security automation risk classifications Etc. The most active open
source project of this team is security monkey Netflix
also uses bless which stands for basham's
Lambda M Farrell SSH service to protect secure shell. Sources report kid
is used to Grant.

I am permissions and TLS certificates
are allotted through Lemma. Both of these tasks
rely mainly on python. Finally. Let's move on to see how python is used for monitoring and auto
remediation the monitoring and auto remediation team
is also known as Insight engineering team, they build and execute tools for operational Insight
Diagnostics Auto remediation and altering for most
of its services. Steam makes use of python. For example The Spectator
python client Library. This library is used
for recording dimensional time series along with these
libraries products like Winston and bolt are also built
on python Frameworks, which are flask unicorn and flask rest plus summing
it all up one can easily claim that python is the driving force
for Netflix vital has to Followed all
its rivals in popularity and this popularity is directly
proportional to money-making.

So before we begin just
make sure you subscribe to our Channel and hit
the Bell icon to stay updated with all the latest
Eddie Rekha videos coming back towards this session. We shall first take a look
at who are python developers and what are their job Trends then we shall take a look
at the average salary is drawn by these developers
based on three factors, which are experienced
location and skill set. So without any further delays,
let's get started. A python developer just like
any other developer is someone who designs programs and
deliver software applications, but using python some
of the most important responsibilities include writing
effective code for back and components testing and debugging programs
creating applications that can be integrated
with the present ones Etc. The current salary trend of these developers
has also remarkably increased but before taking a look
at that here is a survey that reasons out why python developers are heavily
paid pythons popularity in 2019 is record-breaking according to stack Overflow
python has emerged as the most question language leaving behind its Fierce
competitor JavaScript GitHub grants python top slot
in the race for popularity.

So as you can see on the screen
python stands first Java second followed by JavaScript Etc. This popularity is also a reason
for the growth in job trends for python developers. These developers are
in great demand all over the world in August. In 19 in deed shows about 69,000 openings
for a python developer. Most of these jobs are
in sectors like web development Big Data machine learning
data science Etc, New York city has
the most number of job postings for python developers
followed by Chicago and San Francisco. So given this I know you
all will be eager to know. What is the average salary
drawn by these developers the average salary
depends on many factors. The three most important factors
are experienced lucky.

Asian and skill set. So talking about
a python developers experience and entry-level python
developer earns a minimum of two point four lakhs
per annum the upper limit. However, depends on
the organizations and the skillset possessed by
the developer on an average the python developer salary at an entry level is
about 5 lakhs per annum in India and about
88,000 dollars in the US. The next level of these developers is becoming
a senior python developer and at this level
the average salary. Comes about 8 lakhs
per annum the biggest leap in salaries is seen after
the senior level for developers.

So now let's move on
towards the next factor, which is location salaries
of python developers also, very geographically
in the US the best location for a python developer seems to
be California having an average of hundred and
twenty-two thousand dollars per year California stands at the top of the list
for best book locations for python developer when it comes to India
the best location for us. Software developer with
python skills is good ground having an average pace care of seven like thirty
one thousand per year. Okay. So now moving on towards
the next very important factor, which is skill set having
the knowledge of python along with other skills
proves to be a very crucial Factor influencing
python developer salaries, according to CV compiler
the most in-demand skills preferred along
with python are AWS and Django the average salary
for a python developer having knowledge of Django
is about 6 lakhs. For annum which is much higher compared to the average
seen earlier in the session how to become
a python developer.

So guys, I will be discussing everything related or
python developer, you know, who is a python developer. What are the various job roles
available in the market who can become
a python developer and then prerequisites
in everything around, you know, if you're looking to you know,
make a career in Python. Let's move forward and have
a look at the agenda for today. So this is what we
will be discussing today.

We'll Begin by understanding
who is a python developer and why one should even
consider python as a you know, as a preferred programming
language then the question is, how should I start? I mean, how should I
go about becoming a python developer then
we'll focus on various job rules for a python developer and let
me tell you there are a lot of job roles out there, right? So if you think
about python you have a lot of fields lot of domains that you can go in right then
a few projects for practice.

I mean you can just
And it on the internet and and it's available
and I believe the best way to learn anything is
to start working on it and you should start
working on the project. So I'm going to give you
a small introduction to few of the projects that
you can start with. Now the question is
who is a python developer. So let me tell you
that first of all a python developer does not it
is a very subjective term. I would say why
because you know, there are a lot of domains. There are a lot
of different types of job roles available
in available in Python, right? So when I say python developer
does not necessarily mean I'm talking about
a software engineer does not necessarily
mean I'm talking about a web developer or
a mobile app developer, right? So a python developer
is a very vast field.

I mean something
which doesn't exist right? Because there are certain fields or sub domains in Python
that you can, you know, come up with a job
rule around that. That's what I mean. Right? So, you know, he can be a software
developer a software. You can be developing
web apps mobile apps he might be even into testing right because you can use
Python with selenium. Then he can become
a data analysis as well or he can be a data scientist
machine learning engineer artificial intelligence
Engineers are different types of job roles available
in the market. Next up we are going
to focus on you know, why become a python developer because everything exists
for a reason, right? And let's try to figure out why one should even consider python
is a programming language.

When you have Java JavaScript and other different
programming languages and the best answer
given to this question is by stack Overflow. So have a look
at the graph guys, right? I don't have to explain anything
here because the red line the red curve that you
are seeing is of python, right? So from 2012 to 2018, you can see that it's
it's an exponential. Growth, right. This is this is it's
a straight line. I'm sorry, right? So yeah, I mean it's growing pretty fast
and I would also tell you one thing guys are always make
sense to learn something when you know, there's a demand there's no you can not you know, so when there are
no tights, right, so just to explain you that now python comes with
really really cool features. So let me just talk
about those features. First of all,
it is very very easy to learn.

So all the people
who are actually scared of coding don't you don't have
to be scared of python. I'm being really honest because it is very very easy
to write code in Python. The syntax is very easy, right then tons
of libraries guys. If you are talking about machine learning web
development numeric computation scientific computation, whatever comes to your mind
any type of application python gives you a very
good Library around that whether it's
computer vision anything you can think of right? So there are a lot of libraries available with python
that you can use for. The purposes right next day's
it is free and open source that I think a lot
of you might already know, right and the best part
is it has a very active Community guys
right high demand as I've just proved with the stock word flow
graph apart from that since python is not only used
for one particular domain or one particular purpose.

So if You Learn Python,
you can go into any field right? It's like, you know
a typical Indian household, you know, pay parents who tell their kids
to go ahead and study. Engineering and then he
can decide what you want to do. Well something similar
but this makes more sense. Right? So these are
the various features guys, right and few
companies few Giants who are using Python and let
me tell you guys each and every company out there in the market
nowadays use Python, right? I have written
down few big names so that you can actually
relate Google NASA, you know, Firefox YouTube Netflix Facebook Dropbox Raspberry Pi
IBM Walt Disney, all of them are using
Python and Very happy about the services and you know, basically whatever the python
whatever python comes with right next up. We are going to talk
about salary Trends. This is something that you
can see it on your screen, but I would definitely tell
you guys it is a average number and generally a data scientist
is not going to earn you know, 8 lakh per annum 8 lakh rupees per annum it'll be
definitely more than that.

It's just an average. We have taken it
from a pay scale. It is definitely more
than in that I'm telling you that through my experience, right and devops engineer also earns a lot more than what
it is here apart from that. There is also a start around
the python developer salary in popular cities, right? So we have San Francisco which was paying somewhere in on
137 thousand eight hundred three hundred eighteen nine US dollars
to python developers, which is pretty great. If you ask me and I am
definitely sure it is a way above then 150 thousand dollars
in us as well. Right, but for now, let's focus on how should I
start how to you know, go about becoming
a python developer.

Obviously everything starts
from Basics, right? You have to understand
the fundamentals to reach to certain level. So first of all install python, go ahead type on Google
install python, right? You'll go to
their official website. You'll find lot of lot
of things out there. I can actually show you
that let me just open it. So if you click
on install python, you'll be directed to this
website download python here. Just select the version select
the OS that you are using and you are good to go
right choosing an ID is a you know,
it varies from person to person. I prefer pycharm. You can also download python. Let me just take you
to one more link. download pycharm you'll be
directed to a jetbrains website and here we go so this is go ahead click
on the community version because the professional version is you know you have to pay
some amount for that right so go ahead click on the
community version download it and it's very cool guys because it gives you
autocomplete features and a lot of other benefits as well you
don't have to manually go and install the libraries
using CMD you can just go ahead use Python and do it right choosing an IDs done
a simple hello world program Right.

So I've already
installed python. I have Pi term. I'm just going to show you
how easy it is to write code in Python, right? So, let me just
quickly open my by charm and all I will do here is print. Hello world. All right. I just have to click and select
The Interpreter as well. Let me just go to the settings. I'll just go to The Interpreter. This top to select
The Interpreter and we are good to go. Now, let's go ahead and
try executing again. It is again saying that you
haven't selected an interpreter. I just did that's weird. Let's see if I can see there is an interpreter just waiting
to minutes to process. Let's just wait for that
and we'll go back to our slides till then
and will continue. So I'll tell you how to execute
a simple hello world program get just give me like
five minutes after that. Let's see what we
have next year. So we are going to talk about
little bit about the basics.

So obviously as I've told
you earlier as well to become a python developer
to become data scientists or or Euro to go
to a revel in your in your career you have to start
everything from Basics right so we have talked or EV
all we already talked about how you can install python how you can install python IDE which is pycharm right now let's
talk about what are the basics that you actually need
to learn now people who are from a programming
background can easily understand this but people who are not let's just focus
on them so variables and data types you
need to understand how to declare variables how to bother the different
types of of variables that we can declare so
they are numeric variables that there can be you know
list couple sets dictionaries all those data types you
need to study there is a separate tutorial on all
of these you can go ahead and check out that in the python playlist but for now let's focus
here what I'm talking about then we have
functions exceptions and input/output operations how you input /output
operations basically mean how you can open a file
how you can delete the file how you can give our input
to the programming language right if My input something
the user wants to input some variable value, right? So input/output operations plus how to open
close files delete files are certain things append
certain things in a file.

So all those things apart from
that exception handling, right? What about 1×0 of some some term
like that comes which has no answer right? So how will you handle those
exceptions that will be covered and exception handling
there are functions which are nothing
but useful code blocks, right so that you
don't have to again and again right the same thing right if you have for example if you want to calculate
All ten times in a program you don't have to write
the logic 10 times.

You can write a function and execute it 10 times just
an example guys, then Loops control statements
and conditional statements which are very important. Right? I am pretty sure you guys know
what our Loops right? If you have a set of you know, if there's a logic
that you want to repeat again and again and you have
a condition defined then you can go ahead
and use Loops for that. Right? So there are different types
of loop there is there is a while loop right? There is a for Loop and yeah. They're nested Loops as well. We're inside one Loop.

You can Define one more
Loop condition statement if L if if statement, so if a particular condition
is true execute this if it is not then execute
the next statement. So those kind of things are called conditional
statements data structures. Then you have hoops Concepts what oops Concepts
basically, you know, your polymorphism
encapsulation classes objects how to declare them. What are Global variables, you know, all those things
that it's basically a very vast field hoops, and it is very very important and python is one
of those programming languages which have object-oriented as
well as procedural Concepts, right and file handling. I've just told you in the beginning itself how to
open close delete add append all those operations
with a file right how you can do that with the help
of python, right? So now let me just go
ahead open my pycharm and again and I'll execute
that hello world program. so I think Kobe can execute it now just a second guys it
is just indexing right now or how about I go ahead
and create one more python file let us name it as test and I'll type here
rent hello world and here we go yep so with one line of code
I can do this try doing that in Java So guys that was a very
simple hello world program that I've written.

There are separate tutorials. I'm again and again
telling you guys. All right. So now let's talk
about the job roles, which I'm pretty sure
everyone is waiting for it. Next we have job rules
as I was as I was mentioning. So there are software engineers
and developers writes. These people might
be writing apis for your web app right there. These people might be, you know, helping
with mobile application. These might be
mobile application developer web application development. Those right so basically what
or desktop GUI developers or game developers all
those people, right? So what sort of skills, you know Industries look
for and in such a for such a profile, right? So code python Basics, right which I've just
mentioned at the beginning where I was talking about
data types variables functions Hoops Concepts file handling conditional statements Loops
control statements all those things right
apart from that.

You need to have basic
knowledge about the web. I'm works right object
relational mappers restful apis. You need to understand
all these terms guys. I cannot go into detail
of all of these terms, but just to give
you a knowledge. Basically you need to understand
how the web works. You should you should know the
basics of web front-end back-end and you should be aware
about of libraries such as Django and flask which are very
famous python libraries for web application development. Right database knowledge is a must because
where is your data? Anyway going after you know, somebody does any sort
of activity on it. They'll go to a database. Right? So that database knowledge
is very important for any developer out
there in the market when a topic of talk
about script writing. So scripting is
a little bit different than programming, right? So scripting
basically is suppose. I want to execute 7 program
sequential e, right. So what I can do is
I can write a script that can execute
those seven programs in an order that I have defined, right? So it basically automates a lot
of tasks right in this case.

I can write a script that will
automatically take my data. And you know create a schema
and store in the database. So the load of other things that you can do with
a particular script, right? So just wanted to tell
you the difference between a scripting
and programming and I hope you I hope you have understood
what you need to understand what you need to learn. What are the skills required
in order to become a developer whether you are
a web application developer or any sort of developer, right? Let's move forward
guys and let's see which is the job role. We are going to focus on next. So we're going to talk about
A python web developer, right? We just spoke about a developer a web developer like
in the previous slide as well. So here it's all
about, you know, understanding the web
HTML CSS Django flask MVC mvt architecture model
view controller template.

So these are all things that you
need to understand right? I mean, these are few things
which you will know once you start going and researching in
that particular field, right database knowledge as I've told you it It is a must
for any sort of developer. Right script writing
is also very important because without scripting guys,
there's no automation. Right any automation tool that you use round also
uses script, right? So just to clear the doubt, you know, scripting is also
very very important right now. Let's see which dobro we
are going to focus on next. Alright, so a data
scientist sexiest job of the 21st century right now. What do you need to learn
to become a data scientist? What scales are Industries
looking for in a data scientist? So you definitely require core skills write
code python skills, which have just discussed
mathematics and statistics is the code or you can say
the foundation of a person who wants to
become data scientist.

That is very very important is
these fundamental topics are very very important guys in people generally
ignore them, right? So basically, Programming
core python skills mathematics and statistics apart from
that you also require skills, like, you know data
visualization data wrangling you might have to clean the data
before processing it right. Then there's a scale called ed8
Data exploratory data analysis where you just figure
out you just look at the data understand the data
what it is talking about.

What should I predict
what I can't predict which grows are useful for me
which columns a useless for me. Can I subtract a couple of columns in come up
with the new column that might be
more useful for me. So these are the things
that you know, you should have that it
only comes with experience and that's how it works apart from that a very important
skill is machine learning and artificial intelligence. So you need to be very, you know, you need
to understand all the machine learning algorithms. You need to understand where I can use which sort of
a machine learning algorithm and if you want you might come up with a different
algorithm is with So how you can achieve
that with python? So if it's python there are a lot of libraries
that you can work on.

So there's a library
called pandas which is Euro for creating data frame. So you can import any sort of
data with the help of Partners whether it's a tsv file CSV
file Excel file doesn't matter. You can import that data. You can perform basic operations
joining concatenation merging any sort of operation. Then you have numpy because python does not support
anything called arrays. There's no there's nothing cool air is right. So there are numpy array is that you need to create
with the help of numpy package? Right.

So any sort of Matrix operation you can perform
the help of number. So I get learner is
in the library used for machine learning. So it has predefined methods
for different algorithms whether it is KN K means
all those algorithms. There are there are
predefined functions or methods in this particular library that you can use and very cool feature
about this libraries that it comes
with sample data set so you can practice those data
sets you can you can Practice those datasets the way you want.

I mean you getting
data sets guys. You don't have to download it. What else you
what else do you want? So I've just received
a very good comment. The explanation is
very good and helpful. Thank you mumtaz. Is it easy to learn
– Ravi ready? Well, let me tell you this is
the easiest programming language that I've ever come across. Okay. So should have already
has one more questions. I am fresher to Learn Python. Is it useful in future, please tell me Well python
is growing at A very very, you know at a very good rate you I just showed you the graph of stack Overflow python is
very it's in demand right now and whether it is
any domain python is useful and definitely it will take
over all the other languages in another five years, right because of the kind
of community that they have in the kind of packages
that they come with right. So let's move forward guys. So now we're going to talk
about data analyst right? So data analyst is someone who understands Theta
and who understand a lot of things who understand
the entire data lifecycle who can take care
of data wrangling who can take care
of data exploratory analysis, right all those things but they have only implemented
simple linear regression models, right they you
know are not aware of those complex algorithms or some neural networks and some complex machine
learning algorithm which can be
unsupervised for example k-means so they build prediction
model simple regression models, you know sales forecasting
and things like that.

They are very good
with data manipulation and they have the scale which is very important
and it is called as data driven problem solving approach
so you need to understand you know what sort of approach should I take
for this particular data and that only comes
with experience right so that's how things work because you know you
cannot just apply one algorithm to all the data sets that are there in the market
right you need to figure out what sort of a problem is it is it a clustering
problem is it a you know all those things are
basically I don't want to go into too much detail here but that's what
a data analyst is right So, let's see emerging job role.

So Ai, and ml engineer
artificial intelligence or more properly also called as
machine learning and generous. These people are not bothered
about data pre-processing. They get the good data. They get the data where they have
to predict something. It might be a regression problem where
they're predicting something. It might be a clustering problem where they might be clustering
different people, right? It might be
a classification problem where they're classifying whether the given
Input is X or Y right so that's what
the major job role of machine learning engineer or an AI engineer is so they require programming
skills data science skills and machine learning, right? So that is what basically
an AI am L engineer should have right apart
from that neural networks is what people are talking
about right now is it is a buzzword in the industry
and it takes machine Learning To The Next Step and it
is called Deep learning. I cannot go into detail here. I hope you guys can understand but deep learning is very
very interesting eyes. And there are a lot of libraries that python has
for deep learning one.

It's tensorflow. Right and it is a it is given to us by Google. So I hope you guys
trust Google right? So, you know, it's it's it's
a very good library and I find it
pretty interesting. The I have separate tutorials on tensorflow is will write
I have worked on tensorflow so you can go ahead
and check out my videos. Next is python
automation testing. so what is python automation
testing is basically you know you're using okay
let's talk about selenium because I can see only selenium
in the slide so selenium you can write scripts
in Python using selenium right you can perform functional
testing basically you know testing login of any website
testing any feature whether it's login whether it's search engine
or any sort of feature whether the link is clickable
the button is working all sort of functional testing or you can say user acceptance
testing can We're done with the help of python
in a very automated fashion.

Next is a deep
learning engineer. So deep learning
engineering focuses mainly on neural network. So he'll need to
understand different types of neural networks. Whether it's a
recurrent neural network. It can be
a convolutional neural network. It can be RBM autoencoders, you know fully
connected networks or single layer
multi-layer perceptron, so they should be they
should have that thing where they can understand all these different
types of networks and have good experience
in working on applications such as video processing
image processing. Your division, you know
speech to text text to speech image recognition. So how do you think that the Facebook Auto
attack feature works, right? So it works with the help
of deep learning only right and Right, so that's how that's how it is. Now comes the roadmap guys. Okay, so I have you know, I'll talk about each and each
and every job role one by one. So how you can
master code python. So what you need to understand
you need to learn variables and data types file handling
exception handling Hoops concept data structures.

I Traders generators writes
these type of things where basics of programming you
need to understand right then. Well, let's talk
about master web Frameworks. So Django or flask
whatever you prefer. 8T Cantor is basically
4 gy base the web apps, right? Then we have
MVC MVC architecture that is basically model
view controller and template that you need to understand
HTML CSS is a must for any web
developer gets right. It's there's no rocket science. ER I think people
should be aware about it that web developers have
to learn HTML CSS. Okay, just a second
towards data science. If you want to go start a sticks applied math
data visualization analysis, basically any sort
of data manipulation. You need to understand
that on top of it. You need to understand machine
learning and you have you know, python libraries to make
your life easy machine learning and artificial intelligence.

You need to be very good with the machine
learning algorithms understand, you know libraries like scikit-learn tensorflow
probability and statistics. You should be very good with From that neural networks
and deep learning if you are looking
to become a neural network deep learning engineer, right? So deep learning again. There is a neural
network architecture that you need to understand
some machine learning and deep learning. There's a very thin line here but deep learning is nothing but
an advanced machine learning, right so don't
get confused here. Both are the subsets
of artificial intelligence. Right artificial intelligence
is an umbrella term which encompasses machine learning
and deep learning together.

So this is though. I don't want you to guy. I don't want you guys
to be confused about it. I mean, it's very easy
to understand machine learning. The next step after machine learning is deep
learning which Neural networks. It's nothing but
Advanced machine learning. And opencv for computer
vision web scraping with bs4 predictions models Etc
is what you should be knowing. The opencv is basically
a library, which is used for computer vision again, I have a separate tutorial
and opencv as well. So you guys can check that out apart from that web scraping is
nothing but scraping data or collecting data from
different websites web pages that you can easily do right
and prediction models is I think you guys are
already aware of Let's take a quick look at why you
should consider learning python.

Well guys python is
a general-purpose language, but it has a wide range
of applications ranging from web development scientific
and mathematical Computing and even design your own
graphical user interfaces. So you can make use of Django
and bottle for web development. You can make use
of numpy and sympathy for mathematical computations and you can design your own
games using pi game as well and so much more guys and Also, the syntax of the language
is really really clean and the length of the cord
is relatively short. It's fun to walk in Python because it allows you
to think about the problem rather than focusing
on the syntax itself guys and every Fortune 500 company that exists today uses python
in one way or the other guys, you don't even have to do
any digging to know this fact.

And again, as I said python is extremely
popular among both the startups and established industry Giants and programming in Python
is really fun guys it's easier to understand
and write python code again why because the syntax
feels natural guys and on that note let us come to
the main agenda of the session which is to help you
all to install and setup python let us begin so
guys to begin with and install python the easiest way is to come to the official
documentation page and go about from there so
here I have opened up the official python.org page and we are in the download
section of the page as you can check the URL where at python or Ork
/downloads / Windows guys since this tutorial
is mainly focused on installing python for Windows we are here guys just in case if you had to install a Linux or something the steps are
quite different from what we do for Windows however coming
back the latest Python 3 version releases python
three point seven point two and the latest python
to release is two point seven point one five well based on your requirement
and you needs at this point of time you should already know
which version of python that you should use
and just in case if you Don't you can actually
install both of these versions python 2 and Python
3 into your machine and go bar from there
as well guys.

Well, as you can check out
three point seven point two is the latest version
of python at the time that this session
was curated guys. So basically we need to go and download this
from the official site. Well, all you need
to do is click on the latest release version
there and we'll take you to the download section desk. However, the first section is
actually all of the changes and the new features added
in Python 3 point 7, and there are multiple
documentation you are as well. So basically See, this is all the change log
of this particular version of python guys. Well, all you need
to do at this point of time is to scroll down to the file section and then
search for Windows out here.

Well, as you can see there
are multiple versions to install right? So you actually get
an embeddable zip file which is actually a zip file where you have to unzip it
and then install it manually or you actually have
an executable installer guys, and if you can notice there are
two versions here as well. One is the 32-bit version
and the other one is 64 bit version guys
will basically you need to know if your machine is either
running a 32-bit version of Windows or a 64-bit version of Windows guys
but however do note that the 32-bit version is
actually backwards compatible with 64-bit as well so
what I mean by that is in case if you have a 64-bit machine
you can still go ahead and install python 32 bit and it would work
absolutely fine but if you have a 32-bit windows
then you will not be allowed to install the 64-bit version
guys I hope I'm clear with that and now that you
would be familiar with your particular version of Windows both are actually of the same install our as well
well as soon as you go ahead and download it and basically
all you need to do is open it later guys giving it an administrative
privileges is a choice but then it is always
recommended so as soon as you run it as an admin you'll be greeted
with the following screen guys so basically it's telling me
the python version right now and it is automatically
selected 64-bit version for my machine guys so basically you can actually
customize installation at this point you
can choose the location and the features you
need as well and all of that one main thing
that I want you guys to do is Make sure that this particular
option is checked.

It says add python
3.72 the path. I will let you know why
this is really important. But just make sure to check this
at this point guys. And all you need to do
is hit install now and python is ready in
your machine guys will basically as you can already see
that it says that a program called Idol
is also installed with it. Right? So Idol is nothing
but a graphical user interface, which is used to work
with python guys. So let me quickly open up idle
to show you what it actually is. Well, as you can check
out it is basically a python 3.7 shell guys. So here you can actually type
out anything that you want. So let us say printer. Hello, Ed, Eureka. As soon as I hit enter
that is executed, right? So basically you can run any of the Python programs
here as well.

So let me go ahead and do another hex
equal to 10 print X into 2. So X into 2 is basically 10
into 20 and that is good. Right. So basically provides a GUI for
python guys as simple as that, but do know that
if you actually have a Windows machine there is
a very good chance that python might already come
installed on your machine guys. However, there is
one more thing. That you need to do. Well that is to
actually check out your environment variable guys. So basically you need
to right click on my computer and go to properties guys
and in properties, you need to go
to Advanced system settings and environment variables
and here you need to check if the path of the user variable actually points to your python
installation location guys.

So this is basically why
we had to have the check box during the installation. Well, if this is not the case
in you have to manually come here and add the path
in the system variable guys. So why is this required? I'm pretty sure you guys
could have already guessed it at this point, but let me quickly go over
and show you a demo. Let me open up my command prompt
and if python is in my path, as soon as I hit python it is supposed to open up
the interpreter and be ready for me to execute commands guys.

And since I already have
the path established it is actually done. So it is as simple as this guy's well installing python is
actually pretty straightforward and simple but let
me quickly push you on another concept right? Well, so next up on the session will actually
check out the different. Development environments
available for python guys. Well python has
a large supporting community and there are numerous
active forums online which can be handy. If you're stuck anywhere guys,
well at Ed Eureka, we have a vast Community
for python lots of blogs and these amazing videos created by our subject
matter experts as well. So make sure to check them out. Alright, so we have multiple
development environments for python guys.

So we have pider for Eclipse. We have pycharm. We have notepad plus plus and Bluefish for you
all my Users as well. We have Komodo and whim
to Guys these are some of the many IEDs
that's out there that you can develop code in. Well, I suggest
you use something that you're comfortable with
and then go from there guys. Well choosing an IDE is like
choosing an ice cream flavor. You need to first try it
out practically and see if it suits
your needs perfectly. If it does then go ahead
and make use of it guys. Well personally in my case. It has been a long journey
with python guys. I have tried multiple IDs and I have a personal
liking towards pycharm. It is really simple and amazing to work
with and I'm sure a majority of the entire Community agrees
with me when I say that pycharm is the number
one IDE for python guys.

Let's talk about how you can write a simple
hello world program in Python or before talking about
a simple hello world program. Let me talk about
the python interpreter or python is also a piece of
software called an interpreter. Interpreter is the program. You'll need to run
the python code and scripts. Technically The Interpreter
is a layer of software that works between your program and your computer hardware
to get your code running now depending upon
the python implementation that you are using
The Interpreter can be when you're writing
a program in C. It's going to be C Python and if you're writing
the program in Java, it's going to be
J python or jython. And then we have a program
written in Python itself. Then we have y pi and for
the program implemented in.net there is going to to be
ironpython as The Interpreter.

So whatever form The Interpreter
takes the code you write will always be run
by this program. So therefore the first
condition to be able to run Python scripts or Python program is to have The Interpreter correctly
installed on your system. Now The Interpreter
is able to run python code in two different ways, which is basically as a script or a module and the next one
is as a piece of code, which is typed into
an interactive session. So talking about the hello
world program guys in Python if you To write a simple
hello world program. It's very easy. You just have to write
a print statement and inside the print statement. You just have to
specify the string which is hello world
inside the inverted commas. So let's take it up
to the command prompt guys, which I have opened
the interactive session already. So to print
the hello world program. What I'll do is I'll
just mention hello world over here as a string
inside the Commerce.

And when I press enter it
is going to show me the output as hello world. So this is as easy
as it looks guys, so This is how you run a simple
hello world program in Python. The syntax is pretty easy since it is Python Programming
and one of the Salient features of python is the easy syntax. So what you have to do is
just write a print statement and inside the print statement. We have written a string which is hello world
inside the inverted commas. So now that we are done
with how we can write a hello world program in Python. Let's see how we will run
it using a DOT py file and other different
approaches as well guys. So I'll exit from here now. Okay, let me open Idol guys, which is what you get
when you install python guys, so I'll make a file
which is a new file, of course, so I'll just write
print hello world over here. Now I'll save it guys so
I'll save it on desktop and I'll just write
it as Hello dot p y so this is going to be
my DOT py file guys.

So now when I run
this I am getting the output as hello world. So this is how you run
py file in idle guys. So this is
the python shell guys. So to print the same thing, I'll just write hello
and you recall learner. Let's see what is going
to happen now. Okay now when I This it's going to show me
that the string that I have provided over here. Now one more thing. I want to show you guys when I
open my desktop over here. I have a file which is demo
and hello as well. So these are my DOT
py file extension guys. So to run it and using
the command prompt, what I have to do is
I'll just write python over here and mention the file that I have saved using
the dot py file extension and you will see that okay, we are not in the same directory as so you have to make sure
you should be in the direction.

Every where your file
is actually saved, so now when I run Python
and mention the file name, I'm getting the output
as hello world now. I'm check the file. I checked the file over here. As you can see I'm getting
the output over here. So this is how you actually
execute a DOT py file guys and a DOT PDF file is
nothing but a simple file which has a python code and it is saved
with an extension dot P Y which contains the code
or the script guys. We always like to have options
in everything but choosing the best among them especially
in case of ideas gets confusing. So if you have any issues
regarding Here is the top 10 best ideas for python help you narrow down on the most
suitable one for you. So before we begin just
to make sure you subscribe to our Channel and hit
the Bell icon to stay updated with all the latest
editor acre videos moving on towards the session.

We shall first begin
with understanding what exactly is an IDE and the basic features
of it following that we shall take a look
at the top 10 best ideas for Python and the factors that need to be in mind before selecting one of these so
without Out any further dues, let's move ahead
straight away to learn what exactly is an IDE guy's ID e stands for integrated
development environment. It's a graphical user
interface web programmers write their code and produce
their final products and IDE basically unifies
all essential tools required for software development and testing this in turn helps the programmer
to maximize his output now that you know, what is an IDE, let's move on to see what are
the basic features of an ID. many of us do not
know the difference between code editors and IDs
code editors are applications that are able to write
and manipulate source code they can either be
Standalone applications or can be integrated into ID he's the only feature
a code editor should support is being able to edit
text on the other hand and IDE is
a complete environment where you can create
software applications in addition to code editors IDs also have other features
such as syntax highlighting which is used to Mark the syntax of the base language
in different colors and fonts the auto completion
feature is designed to minimize the time consumption
a debugger is available which is required
to test and debug the source code IDE
is also consists of compilers now these are tools that translate source code
from one language to another finally IDE is
can either be language-specific or may have support for multiple
languages the choice relies on the user to single out and embrace the ideas
of This choice now that you know basic
features of an IDE, let's move on to see what are the top 10
best ideas for python at opposition 10 is Idle.

It's a cross-platform
open-source IDE, which comes as a default
implementation along with python and it's written completely
in python as well. It's name is presumed to be
in honor of Eric idle who's one of the founding
members of Monty Python. This IDE is considered
to be extremely suitable for the education industry
due to With Simplicity, it also provides special features such as
availability of a python shell with syntax highlighting a multi window text editor
program animation or stepping which refers to executing
one line of code at a time breakpoints are available
to ease the debugging and the call stack is clearly
visible at position 9 is Thani.

This is an idea that was
developed for beginners. It provides step-by-step
assistance to the programmer. It has separate windows that are provided
to secured function calls line numbers are available to the user to keep
track of each line log of the user actions is available so as to assist the user
in future statement stepping without breakpoints is
also possible moving on towards the next IDE which takes the eighth slot is Adam Adam is an open-source
cross-platform IDE built using web Technologies Adam is based on the electron framework which is built by GitHub it
also provides some remarkable features such as support for
third-party packages and themes so as to form at the editor
Adams APM allows installation and management of packages
it also provides support for a number of languages
other than python such as C C++ Java Etc Adam also consists of
an exception reporting package at the 7th place is Eric python Eric python is an
open-source cross-platform IDE which is written completely
in Python its source code is available freely
And can be studied and recreated by anybody some of the quality features provided
by Eric python are formattable window layout formattable syntax
highlighting code folding, which is selectively showing or hiding some part
of your code.

It is also furnished
with a class browser and has built-in
support for unit. Testing and Django
at the sixth position is Wing this cross-platform IDE
was created by Wing where it is a lightweight IDE and designed to allow
quick programming. It comes in three variants
namely Wing Pro Wing personal and wing 101 Wing Pro is
a professional version which is priced somewhere
between 95 $279 Wing personal and wing 101 on the other hand
are simplified free versions that are available
for students and beginners Wing provides
special features such as automatic multi-process and child process debugging remote debug
process is possible. It also has a module browser and allows refactoring
which is a process. Structuring existing computer
code it also provides Auto completion feature
for non python files as well. Now, let's move on
towards Sublime Text which stands at the fifth
position guys Sublime Text is a cross-platform
IDE priced at $80.

It is developed and C++
and python in addition to python it provides support
for other languages as well. The features of this IDE can
be enhanced using plugins the go to anything feature allows
quick access to files symbols or lines its command palette
provides robust matching for keyboard invocations python-based plug-in
apis are supported. This idea also allows
simultaneous editing and the preferences can be made
project-specific at position. 4 is Rodeo Rodeo is
an open-source cross-platform IDE built in particular
for machine learning and data science Rodeo makes
it very convenient to load and compare data. It also allows data
experimentation and is This to it bites and tutorials
to guide the users. It also provides cheat sheets
for material reference files and packet search
is made very easy. Rodeo is a simple and a lightweight Ide
at the third slot is pydev. This is an open-source
cross-platform third party package with serves
as a plug-in for Eclipse which in turn enables it for python development pydev
provides a remote debugger.

We're in the files, which are not launched in
Eclipse can be debugged it also. It's the code folding feature. So as to selectively hide
or display sections of code, it provides support
for python 2X and 3X syntax. The auto edit feature can automatically
edit the parentheses at self parameter
to the class methods and can also add import keyword
in the import lines standing at number 2 spider is an open-source cross-platform
IDE designed mainly for data analysis and scientists.

It's considered to be a powerful
scientific development IDE. Didn't invite in spider is integrated with many
Scientific Python libraries such as sci-fi numpy
matplotlib pandas Etc pertaining to its scientific use
spider provides Advanced support for editing analysis
and data exploration. It also allows
static code analysis where in the analysis
is performed without actually executing the code the features of this IDE
can be expanded further through plug-in system and API
the IDE that takes the top slot and is at position number one is
my personal favorite pycharm.

It was developed by
the Zeke company jetbrains and it's a cross-platform IDE. It comes in two versions where in the community
version is free and the professional version
is priced at $199 per user pycharm is considered
to be one of the best ideas and also the most
widely used because of its remarkable features such as specialized project views
allowing quick switching between files it
also facilitates.

It's a web development
along with Django flask and web 2 pi pycharm is equipped
with more than thousand plugins so programmers can write
their own plugins to extend its features 81 of the top hundred companies
make use of pycharm before ending the session let me just help you guys
to narrow down on the best idea that suitable for you before choosing an IDE
keep the following points in mind the level of expertise
of the programmer the type of industry or sector where python is being used the ability to buy
commercial versions or stick to the free ones the
kind of software being developed and the need to integrate
with other languages once these points are decided
upon the programmer can easily select among the ideas which we have discussed earlier based on the given features So
no exactly on that note.

Let us start
checking out pycharm. So guys many
programmers nowadays op for python to build
software application, right? So they need the code
to be concise clean and readable as well. They can even accelerate custom
software application development by actually taking advantage of the number of ID
is supported for python. Well a company called jetbrains
has actually developed by charm as a cross-platform IDE for python in addition
to supporting versions. Dew point x + 3 .6 of python
pycharm is also compatible with Windows Linux
and even Mac OS and at the same time the tools and the features provided
by pycharm helps programmers to write a variety of software applications
in Python very quickly and efficiently guys. So the developers
can even customize the pycharm UI according
to their specific needs and preferences also, they can extend the ID
by choosing over. I think they are on 50 plugins
as well to meet their complex. Project requirements. So again, it is a win-win
for everyone starting from the beginner
to the advanced user as well. So pycharm is one of the most widely used IDs
for Python Programming as I mentioned
at present python.

IDE is being used by all
of the large Enterprises like Twitter or VF Pinterest. We have HP, we have semantic
and even group on guys. So this is really a good thing
in terms of Industry traction. So now that that's done
we need to check out why pycharm is so popular. I'm sure you guys were thinking
about about this right? So let me quickly walk you
through all of the features and the tools provided
by pycharm guys. So first we look
at the features and later. We'll move to the tools.

So the first important tool we
have is the code editor guys. So what is
the code editor feature? So basically the intelligent
code editor provided by pycharm enables all of us programmers to write say high-quality python
code directly guys. So the editor enables programs to read code easily through
their different color schemes. Set indents On You
lines automatically pick the appropriate coding style and Avail context-aware
code completion as well. And at the same time
the programmers can also use the editor to expand
the code block to an expression or logical block. They can also Avail
code Snippets format the code identify the errors
and misspellings as well. They can even
detect duplicate code and auto generate code to also
the editor makes it easier for developers to basically
analyze the code on the whole and Identify the errors while writing the code guys now that was an
important feature, right? So next one.

I want to talk about is
code navigation guys. So the smart code navigation
options provided by pycharm basically help
the programmers to edit and improve the code without putting any
extra effort or time. The ID basically makes it easier for the programmers to go
to a class or a file assemble and go along to the Declarations invoked from a particular
reference as well. And the user can even
find an item in. Source code or the code snippet
UI element or a user action almost immediately. So basically they
can further locate usage of various symbols and set
benchmarks in the code. And also at the same time the developers can
even take advantage of the code navigation feature
to scrutinize the code throughout lie in this Mode
called as the lens mode guys. So next up we have refactoring. Well pycharm definitely
makes it easier for the developers to implement
both local and Global changes really quickly
and efficiently guys. So the developers
can even take advantage of the refactoring options
provided by the IDE while writing plane
python code and working with python Frameworks. They can Avail the rename and move factoring for
files glasses functions methods, you'll properties parameters and local and Global
variables as well.

Also likewise, they can improve
the code quality by extracting variables Fields constants and even parameters also pycharm allows programmers to break
up longer classes and methods. Through the extract method. So next up is support for web Technologies guys
python makes it easier for programmers to write various
web applications in Python. So python basically supports Technologies like HTML
CSS JavaScript typescript and even coffeescript, right? So the web developers
can basically use the live editing preview options provided by the ID to view
a single web page simultaneously in the editor as
well as the browser. So this same time
the live edit feature provided by the Enables programmers
to see the changes made to the code instantaneously on a web browser pycharm
further allows developers to Avail a JavaScript debugger
as well as coffeescript and typescript editors
as well do know that it even simplifies isomorphic web application
development as well.

And this is done because it supports
both angularjs and node.js guys. So the last feature is support
for python scientific libraries. So guys pycharm further helps
programmers to use Python more efficiently in in big data and data science
projects as well. So it supports some of the widely used scientific
libraries for python starting from numpy and a condom
and matplotlib as well. So the developers can work
efficiently with all of these scientific libraries by availing the interactive
graphs deep code inside even array viewers
provided by the IDE. They can even run
the repl python console provided by pycharm
to Avail robust features, like on the fly if syntax check
and code inspection as well. and at the same time
programmers can also integrate the ID seamlessly with the IPython notebook
to create innovative solutions without putting extra time and effort as well so that is a really good Advantage
as well right so now that we're done
with the features let me quickly walk you
through the important tools while all these tools definitely
give python the upper hand so let's check it out so the first one will be
checking out is database Tools in addition to supporting
various python libraries and Frameworks pycharm allows developers to work
with a number of relational databases including
Oracle SQL Server MySQL and even postgresql as well so
the developers can further use the ID to run the queries edit the SQL code browse
data alter table data even analyze the schemas as well well guys pycharm further
supports SQL Alchemy library and inject SQL code into code which is written in various
programming languages as well the professional edition of
the ID further makes it easier for the developer Purse
to hide a large volumes of data efficiently through the data grids and next
we have visual debugger.

So guys the visual debugger
provided by the IDE basically helps the programmers
to debug python JavaScript and Django code directly. The developers can use
the inline debugger to see live debugging data directly
on the editor likewise, they can build multiple
python processes simultaneously and step through the code
bypassed libraries as well bite some further creates reusable
and customizable. Duration for each test script
or debugger execution. The user can have an option
to facilitate a remote debugging by integrating the visual
debugger with the remote interpreters directly and the next feature we
have is built-in terminal. Well guys pycharm comes with a local terminal for
Windows Linux and Mac as well. So the built-in
terminal basically enables the programmers to continue
the code and test without ever leaving the IDE. Also the programmers can use the ID to basically run
the python files and configured. Still biting environments. Well, well this is done according to the precise
project requirements as well. So that's good. And at the same time they
can run interactive python or Django consoled directly into the IDE and the console
provides useful features, like code completion automatic
braces management and Dynamics and text change the programmers
even have an option to integrate the console with both local
and remote interpreters.

So the terminal is really
big Advantage guys and next up. We have software testing. So like any other IDs pycharm
also comes with features and tools to simplify
python application testing. It allows developers
to perform unit testing through popular python, testing framework, like knows a tests
and Doc tests as well. So the testers even have
an option to run individual or multiple test files
and test classes guys. They can further integrate
the IDE with coverage dot py to measure the code coverage while testing the
applications as well and while testing multi-threaded
applications the testers And use a Ted concurrency visualization
option provided by the ID to control the application fully and efficiently at the same time pycharm enables users
to deliver high-quality software by implementing behavior-driven
development guys in short. We actually call this as bdd and lastly we have remote
development capabilities guys pycharm allows developers
to connect with various machines and build software
applications remotely. The programmers can Avail
the built-in SSH console provided by the idea
to basically connect to machines and perform various development
tasks remotely through SSH so they can even run debug and profile the
python applications in a remote environment by replacing the local
interpreter with that of the remote interpreter and also pycharm
enables programmers to create reproducible
development environments through a robust tool
called as vagrant guys and this basically
simplifies distributed application development.

And this is done using Docker
the users even have the option to Item seamlessly with
issue tracking systems as well. So in my opinion
that has enough of knowing what it offers. So let us Dive Right
into pycharm now and I'll walk you
through the interface. Let me open up IH am so guys. This is probably
the first screen that pycharm greets you with. So on the left here, you will basically have all
of the codes that you have actually worked with
or any other recent projects that are opened. I have a quite so I have a
handful of projects right here.

So basically this
might be blank for you if you're installing pycharm
for the first time. And there is installing
pycharm is very simple. So it is free and the installation is extremely
straightforward as well. So all you need to do is go
to the official website and it's a single
step download procedure. I already have it installed
on my machine as you can see. So first let's go ahead and create a new project
in pycharm guys. So all you need to do
is hit create new project on the right side and give
a name for the project. So let me just type it
out as pycharm test. And then for now you might
not have the python interpreter. I'll just come back
to this sofa. Let me just hit create and let
pycharm take us to the or UI. So basically it has created
the project folder for us as you can check out on the left
and it is blanket and this part actually queries
all this skeleton procedure.

And this is the time
where it actually sort of for scroll through and checks
all of the installed packages. And also it probably
will take a while and you could actually catch
it rotating somewhere here guys. So this is good. So let us quickly go
and create a new python file that we can write into so
click new news cards file. What? Type of file we trying
to do here sea bass.

So the file we're trying
to do is python here, right so that and you can write
in different languages as well. So basically you can use x HTML XML HTML the DTD
command line as well. So right now
since we're doing python, let me quickly go ahead
and type in Python. So as you can see
we have a scratch file, which is a scratch not py guys so you can basically
right-click refactor and rename this
to whatever you want.

But since this is just a demo
I'll leave it at scratch. So then there are multiple
options to With this value, but if you want to get started really simple just
follow all the procedure until now to create
a scratch file and later. You need to add
the configuration to actually use Python to run this guy's so
we click on ADD configuration. Click on the tiny
plus icon Python, and then we don't have
any configurations, right? So let me name this test config and then the script path
the script path basically is providing the past to
the particular script. So it's pycharm test and then as soon as we come
into the environment, Dormant here is where we
will be actually checking out our interpreter guys. So I have multiple versions
of python installed as you can see. I have three point
seven and I have 3.6 is well, so there is a very good chance
that this might not show for you because you have
not installed Python and it is very simple
to install pipes in guys. So I'll just show you
that in a second.

So this is the part where we actually select
our interpreter 3.7 and all we need to do is okay. So this is actually ready to execute with our
test configuration guys. So now coming back to on
how you can install python. okay so basically we
open file settings and in settings we actually come
to project by jump test case so click on the project
interpreter and on the right side you can actually
check out The Interpreter so basically we have
multiple interpreters you are and for this case I'm going
to use mini conda 3 and that is what I've used so for your case if you have not installed it so
go to the gear icon on the right and click add sure
you can actually use the system interpreter which has Python and days so in my case I've installed it
using an knock on door so it says Anaconda so make sure
you click this and hit OK and you're done this so
apply so now that all that is done right so how can we add all
the packages to python not everything comes in
built right so again go to file settings is pretty much almost same day
so we go to The Interpreter and then we have
the packages tab under this so basically we use
the gear icon to actually check out our interpreter now check
out all the list we have based so basically these are
all of the packages that are installed
for my particular case so these are All of the libraries
that are installed guys, so in case if you need to add
a library hit on the plus icon on the right side, so this type in any
of the libraries that you require right? So there are multiple
installed as well.

As you can see whatever is
in blue is actually installed if I just type in tensorflow,
it says already installed, but then it won't be
in blue for you because you might have
not installed this right. So click on that install package on the left side
and you're good to go how simple is it guys? So now that we're actually
all set up and we're waiting in a scratch file. So let me quickly. Walk you through
a tiny code snippet and we can check out
the advantages here as well. So guys, let me try to quickly
import a package here and not even going
to type the entire thing. Right? So I just basically typed
out the first three letters I MP and it is actually prompting
me to pick up the entire thing. Right? So this is basically
how intellisense walks and visual studio. And this is all the intelligence
of pycharm guys. So it is at this point of time. You can actually choose to type
in the entire thing like ort or you can just again come
back I MP and then you realize that you To use import so all we
need to do is either hit enter or you can hit tab as well and it takes the entire thing.

So this definitely helps reduce a lot of time by providing
good predictions, right? So this was just basically
one line of codes. So imagine if you
have to write hundreds and thousands of lines of code, then this is definitely
a lifesaver in my opinion. So next I'm going to actually
try importing a package. That's a pie game. So import pygame come
to the new line so you can check out everything
is grayed out here, right? So we can actually
change the color by making sure we
actually use something right.

So let me quickly go
and buy game dot in it. For example, as you can see
the color change, right? So this is basically telling us that by game is being used
now simple as that and next. This is another actually
good tip for you guys. So let me quickly
take an example. I will to 10 I'm
going to print I so as you can already guess
this is not very complex code, right? So it is going
to print I As soon as I run this piece of code, I am supposed to get I printed
to be like five times right? So check this out. This was only five times. So let's say you have a piece of code where you have
to change something, right? So let me change
this i2p quickly. And now that this
has been changed to pee since this is a small program. I can probably go ahead
and change this manually, right so I can go ahead and change this to BP
again P1 more Sagan. It took like almost
20 seconds to do this for five times, right? So imagine if someone Has to do this for thousands
of lines of code, so it becomes really annoying.

Right? And this is where another useful feature
of pycharm helps us. So let me quickly select this p
as you can see, this is selected. Every P here
is highlighted, right? So let me quickly right click on it go to refactor
and then hit renamed. So let's insert P. We wanted to biessed as
soon as I hit refactor. Boom as you can
check out, right? So the once this got changed
everything else got changed in just one click and this is
also a lifesaver in my opinion. S so next up there are
multiple keyboard shortcuts you can use as well. So basically it's the same we can use Ctrl F
to actually find something and then use it. Right. So this actually works
even in scope as well. So let's say you're
in the scope of a function or a user-defined function or something and then you
want to find something in that particular scope. So this particular search option
actually works there as well. So basically with coding
you would have done multiple changes, right? So you would have done multiple
changes with your programmer in case you just want to check
out what are all the changes.

Is that you have done? So we actually press alt shift
+ C to actually give us a list of changes that we have actually
done check this out. So these are all of the changes that we
have actually done right? So we deleted something created
on these cards file. So this basically goes
in the reverse order guys. So this is definitely useful in case you actually want
to step back or check out. What are the changes
that got done and then in case if you just want to print
the same thing over and over again, you can do it as well. So let me quickly go ahead and
type out Brent say Edgar a cow or Like These Guys these
are all examples, right? So do not bother about
the exact syntax right now. I'm just trying to show you
how pycharm works here. So basically in case I have
to just hit this print again, so instead of typing
it out or copying and pasting into something there
is actually a short bit better. I'm going to place
the cursor here. I'm going to hit control D.

So control D basically duplicate
this entire line for us. And how cool is that guys? So guys the next feature. I want to show you guys is
basically to select a current column. So let me just quickly select. Ain't your and then
I'm going to use alt and actually scroll guys. I am not sure how you
might actually use this but you can select
the columnar output of it and maybe this might help for your particular
requirement as right. So basically you can use
it for iron tation of the code as well. And then this basically depends
on your requirement, but this is a very good feature
provided by pycharm guys. So basically to run this all
you need to do is Select it or right click run scratch or say you can even click the play icon here
as well to debug it. There is a time. Bug icon on the right. So basically you just place
the debugger wherever you want and you can actually
stop execution at this particular point of time and later move on
from there as well.

So guys, there are
n number of features that pycharm offers
and to keep the session simple. So I basically just
showed you all of the tips and tricks that you
can actually use with it. So guys on the whole pie item is one of the most
popular ideas for python. So the python programmers
can make use of pycharm as licensed software as well. However, jetbrains allows developers to choose between
in three distinct editions of the idea guys Community
professional and educational the developers can always create
a software development cost by opting for the community
edition of pycharm. However, the Community
Edition is free, but it still lacks some of the
advanced features provided by the professional editions case. So jetbrains have been
updating both editions of the Python IDE to make
programmers more productive and simplify custom software
development as well. Let's say for instance the
professional edition of fights.

Mm. Mm 17.3 actually. Is it easier for developers to test
functionalities of the API by providing a built-in
rest client likewise, it accelerates the
web application development by allowing programmers to Avail new features provided
by Django 2.0 and also it allows developers to visualize and analyze the data more efficiently through a data
science model as well guys. So now that we checked
out python in a really good amount of detail. Let me quickly conclude
the session for you guys. So we started out by checking
out what an ID is later. We looked at why we need to make
user ID followed by that. We actually looked
at the different IDs you can make use
of to code with python and lastly we checked out
python in a small amount of detail guys.

So it is at this point of time. I like to tell you
that we have in-depth tutorials and blogs on Python and even
a complete master's program, which will help you become
a certified python expert days. So I highly suggest
you guys check it out. Have you ever asked any And I'm going to explain
the code he wrote a year ago, or have you ever tried reading your own
previously written code. It would become
a very time-consuming and tiring task guys. If you had to reanalyze every
block of code from scratch. Well, the best thing
to do is add a comment. So let's just quickly move ahead and look at what's in store
under this topic firstly. We shall understand
what exactly comments mean and when to use them
then I'll be showing you how to write comments in Python and how they're going
to be interpreted.

It following that we
will be looking at the types of comments that is single line
and multi-line comments and a few shortcuts
related to them. And finally we will be looking
at docstring comments or to be more precise
docstrings as commence. So I hope you are clear
with this moving on towards the first topic
of the session what are commands? No, they're not something there just to increase
the size of your code, but guys, they are indeed very
meaningful comments our program a coherent statements. Describe what a block
of code means and they get very useful, especially when you're writing
large blocks of code. Say for example, you've developed some
software previously. And now you're working
on something that's new and completely different
at this point of time. You find that your previous
software is throwing some error you would
have completely forgotten what you did and how so this is where comments come in
to picture a good code actually consists of relevant comments.

These comments actually
increase the readability. Leti of the program not just
to the programmer but to the others as well now that you know what our comments
let's move on and see when to use them. The best practice is
to write comments as and how you proceed with your code comments
are very useful. But only if they are implemented wisely just keep
the following points in mind when you're
commenting your code. Make sure your comments are
very precise and clear and preferably shot as well. They need to be as specific as
possible to the Talk of code. They're included with please make sure you use
decent language guys and do not repeat your comments as they become redundant now
that you know, what our comments
and their importance. Let's see how to write them
in Python comments in Python are preceded
by a hash character as you can see
on the screen over here.

I have a small example
with some two lines of code. My first line is a comment and my second line
is a print statement. Now, let's move on towards the jupyter notebook
and see how this works. Works now, let's move on
towards a jupyter. Notebook and write some comments
All I'm going to do over here is I'll open
a new python notebook and I will rename this notebook
to rename your notebook guys. All you have to do is
click on the title. Give whatever title you want. And you was renamed. Like I've told you
before come and start with a hash character in Python. So here I'm going to write
a comment preceded by a hash. As you can see my output there is nothing related
to the comment line and whatever I have printed in the print statement
has been returned as my output.

Now. This is how comments work they
do not show up in your output. Now, let's get back
to our presentation and see how they're interpreted, which is exactly what is
our next topic whenever The Interpreter encounters
a hash symbol it omits whatever is present after that the hash character
actually tells The Interpreter to stop reading
whatever is present after That until the end
of that line, so when you're writing comments, whatever is present
after your hash character is going to be emitted
by your interpreter.

Now, what if the hash character
was present inside the string? Let's go to a jupyter notebook
and see what happens. I'm including a hash character within a string
and I will run this. As you can see when I run
this the string is returned which means a hash inside a string means a hash
itself and nothing else. So you cannot write
comments within a string. Okay. So I hope you've understood
how to write comments. Now, let us move ahead and see
what are the types of comments comments
can either be single line or multi-line single
line comments can either appear individually or in line with some other code multi-line
comments have to be preceded by a hash character
in Realign they appear. Now. Let's see a small example
of single line comments. Like I've told you
before single line comments can appear either in
an individual line or in line with some other code.

Now, let's move on towards the jupyter notebook and
write some single line comments. I'll just create a heading
over here to create a heading. All you have to do is go
to code select heading. Give whatever heading
you want as your heading and prefix it by a hash
a single hash tables that it's H1 level
heading to hashes tell that it's h 2 and so on you can use the heading level
of your choice here.

I prefixed my Heading by a single hash which means
it's of level H 1 now, let's write some
single line comments. As you can see over here. My first line of code
is a comment line. I've prefixed this line
by a hash character. And in my last line,
I have an inline comment. This inline comment is present
with some part of the code, as you can see in the output. None of the comments
have been returned. Now, let's get back
to our presentation and see how multi-line comments work. Like, I've already told you
multi-line comments can appear anywhere in your code. But each line needs to be
prefixed by a hash character. Example as you can see
on your screens. I have a hash character
present in the first two lines of my code. After that. I have some code followed by it. You can see in the output that none of these lines
have been returned. Now, let's go to our jupyter notebook and
write some multi-line comments.

As you can see over here. I have three initial
comment lines and all three have been prefixed
by a hash after that. I have some code and you
can see in the output that none of the comment lines
have been returned and whatever code
is present after that and output is returned
based on this code. Now typing a hash everywhere
might be a problem and many of us would not like to do. So, let's look
at some Shortcut methods of how to comment
multiple lines at once. All you have to do is type
your multi line comments. first hold the Ctrl key
and left click wherever you want to insert a hash character just
like how I'm showing your and then type it once and it appears wherever I
have inserted the cursor as you can see on the screen now in case you want to remove
multiple hash characters all at once do the same thing
hold the Ctrl key click on wherever you want to remove
the hash character from and press the backspace key, as you can see from two lines.

I remove the hash character
in a single go. So these are
some Shortcut methods to comment multiple lines. Many of us think that comments
and docstrings are same now, let's move ahead and see what the doc strings and whether they
are actually comments or not doc strings are
not actually comments, but they are
documentation strings. These strings are written
within triple quotes. They are not assigned
to any variable and many other times they're
used as comments as well. Now you'd be thinking
what is the difference between docstrings and comments doc strings
are not permitted by The Interpreter unlike Comments
are emitted by your interpreter and nothing present after the hash character
is going to be read by it on the other hand
doc strings are strings that describe something
about the code docstrings actually tell what
some function is going to do. Whereas the comments will tell
how it is going to do. So, this is the difference
between docstrings and comments. Now, let's go to a jupyter notebook and
see their functionality. Like I've told you before doc strings are written
within triple quotes as you can see in the output.

When I execute this. It Returns the string itself. Whereas in case of a comment
when I execute the comment, it does not return anything which means The Interpreter
does not emit docstrings. Whereas it omits the comment now these doc strings
are efficiently used when you want to describe
something about a class or a function or something else. Now these dogs drinks
can either appear in your out. But or they can be omitted based on where you're
going to place them. Let's try to place
a docstring initially before the code starts. As you can see
in my output the doc string has not been returned. Whereas when I use
the doc string individually without any code and I
executed it you could see that it had returned
the string itself, but when I include
the doc string before the code, and after that, I've included some code lines
and I run this you can see that only the output
for my code is present and nothing related
to the doc string has been returned as my output. Now. Let's try to include
a doc string after some code.

As you can see over here when I included the doc string
after the code. It has returned the output for the code as well
as the string itself. So when you're making use
of Doc strings just be specific of whether you want it
to be returned in your output or not many a times these strings are called rather
than writing it again and again, so I hope you've understood
what our comments and docstrings as well. First of all,
we have to understand. What a bill is a variable is
like a memory location where you store a value now this value you
have stored you may or may not change
in the future now coming back to python to declare a variable we just have
to assign a value to it you don't have to give any additional commands unlike
any other programming languages like C C++ Java but you have to give additional
commands for declaration and assignment purposes let's
take a look at an example here we have two variables X and Y
and we have assigned values to each of them we
have given hundred 2X and Ed Eureka to Y so this is actually how you create a variable
in Python now when I print these variables I
am going to get the output as hundred and adyar a curve you
can also perform operations on these variables using
the arithmetic operators you can perform addition
multiplication subtraction or division as well now
let's try to understand this in the jupyter notebook
as well first of all what I'm going to do is I'm going to declare a variable without assigning
a value to it let's see Happens it is going
to show an error.

The error says name X
is not defined. So let's try again
after giving it a value. Let's say x is equal to 10. It does not give any errors now. So we have successfully
declared a variable here. Let me declare
one more variable. Okay, I'll give it a value 12. Now. Let's try to perform
a few operations on these variables. First of all, let's just perform addition
between X and Y now, let's try to do multiplication. There's one more thing. I want to tell you
about variable declaration that Is variables in Python are
case sensitive meaning and uppercase letter
here is not going to be the same as a lowercase letter. They are going to be
two different variables. Let me show you it
is showing another error which is saying name, why is not defined because we have not assigned
a value to uppercase letter Y, let me give this
another value here. Let me give it 20 so we
have declared two variables here a lowercase value Y
and an uppercase value Y which are going to be
two different variables.

So we have understood
here the Bill declaration how we declare a variable now, let's quickly move on
to various variable data types that we have in Python depending
upon the properties. They possess there are mainly
6 data types in Python. First one is the numbers
on numerical data type. The next one is the string then
we have a list after that. We have a dictionary followed
by a double and in the last we have a set there is
one more variable data type that is range. We will talk
about that in the end because it is mainly used when we are iterating
through values or Or when we are using the for Loop, so let's try to understand all
these in detail numbers are numerical data types mainly
have numerical values and in numbers. Also, we have four
different data types that is integer float complex and Boolean so
integer mainly takes the whole number values without
any decimal point values, but if I add a decimal
point value to a number it is going to become
float and for complex.

We just use J as
an imaginary part and add it to the number for Boolean
it only returns at or false so we use Boolean for only categorical output now
let's try to understand this in jupyter Notebook first of all let
me declare a variable X and give it an integer value
let's say 10 now to check the type of a variable I am
going to use the type function so it is going to show me
the type of this variable let's say x that is NT now if I add
a decimal point value to X let's say 10 .25
and let's check the type of this variable now
we should get flowed as you can see we are getting
float here now to make a number complex I'm just going
to add an imaginary part that is Jay here let's check the type of this variable it is going
to show complex number to understand the Boolean
variable let me take another variable now
I am going to check if 10 is greater than 9 or not so when I check the type of this variable here it
is going to show me that it is a Boolean and when I print this value it is either going
to show me true or false since 10 is greater than 9
it is showing true as output so this was all about it SQL data types now
let's quickly move on to string data type string
data type in Python is written in single or double quotes as you can see here
in the example that I have shown you.

I have two variables X and Y and I have given them
the string values hello and world now to access
the string values. We use the square brackets
with the index number now, you must be wondering
what I index number is so let's take a look
at an example here. I'll show you what index numbers
are in the jupyter notebook. Now, let me declare a variable
and give it a string. Value let's say at Eureka now. Let me check the length
of this string. Let's say so it has a length
of 7 now what our index numbers so index numbers
basically start from 0. So at the letter A here
index number is going to be 0 and it is going to go
until the end of the string. So here at the end is
the letter A. So index number at the letter a is going to be 6 since we have the length
of the string as 7 and index numbers
start from zero now, let's try to access some values from the string using
the next number so when I write
the index number as to I am going to get the value
at the index number that is 2 which is later you now we can
also perform several operations on strings for example
we can change the case of the string we
can replace the values in the string we
are going to see if we can actually replace
values in the strings or not so let's try
to update a value here at the index number 2 here so instead of you let's say
I want D here it is going to show an error which is a type error which says string object
does not support item assignment which means strings are
immutable you cannot change them now to access a series of letters from A String I
can specify a starting index and with the colon here I
can specify the ending index as well let's say I write eight but we only have
seven indexes here let's see what is going to happen here so it has actually
started from the index to that is you here and has gone to the end
of the string but what if I write ending index as
seven since we have the length of the string as Let's see
what it's going to do.

It's going to show
the same thing. But what if I write
checks over there, it is not going
to include the last letter because the ending index
there is not going to include when we are accessing
the values from the string. Now, let's try to do
one more thing here. Let's try to make
all the letters here to uppercase letters as you can see
I've done that similarly. I can make all the latest
lowercase as well. So this was all
about string data type. Okay. One more thing. I want to tell you here
is to access the values from the end of the String I
can specify the index number using the minus here. So what I am going
to get here is starting from the end of the string. I'm going to get
the two letters there. That is at the index number 5. That is K. Similarly. If I write name specify
the index number 2 here it is going
to give me the same value so we can also access the values
in the string like that also.

So this was all
about string data type. Now, let's quickly move on
to list data type a list is a collection of arrays which is changeable and ordered which they have indexes
just like strings so we use the square brackets
to declare a list as you can see here I have the list name fruits
and inside the square brackets I have the list values now
we have to understand that we can declare
different data types in the list not just strings or not just integers
we can merge integers and strings as well or we can also use
other data types in the list as well so
I'm going to show you this in the jupyter notebook so let's declare a list first
give it some integer values first some duplicate values
as well let's just see what happens and a string value
as well as you can see we have successfully
declared a list now when I print the list let's see what all values I will get so
I am getting all the values that have declared here now let me try to access
the values using the index number just like we did in the string as you can see we can access
the values in the list just like we did in the strings as
well using the index number now we can also update the values in the list using
the index number as well so let's just try to update
the value at index number two so instead of 30 I want 35 over So let's just see what it does as you can see we
have successfully updated our value in the list.

Now. Let's try to add
a value using a pin. So what append does
is it will add the value at the end of the list now, let me show you so there is a value
at the end of the list that we have added using
the append function. Now what if I want to add
the value at the middle of the list using
the index number, so what I'm going to do
is I'm going to use the insert function specify the index number
and give it a value. You just say a hundred now when I print the list as you
can see at the index number 5, I have added
a hundred as a value. So the difference between
the insert and apparent is that using the up and you can only add the value
at the end of the list. But when you are using insert
you can add the value specifying the index number now.

Let me do a few operations here. Let me try to reverse the list
here using the reverse function. Now when I print this
the list is diverse. So this was all about list here. Let's quickly move on. To dictionary now and dictionaries are
collection just like a list but it is unordered
changeable and indexed. So we have a key value pair
in a dictionary and we can use the keys as
indexes because they are unique but the values in the keys
can be duplicate as you can see
in the example here. I have the dictionary
name as animals and in the curly brackets, I have declared
the key value pairs.

So let's try this
in the jupyter notebook as well. So I will declare
a dictionary here. Let's just say courses is my dictionary inside
the Curly brackets, I will get key values. Let's just save one and give it a value
comma key value that is 2 and then I'll give
you another value. Let's just say data science. I can give string values
in the key as well. So I'm going to write
here machine learning. Now, let's see
if we have a successfully declared our dictionary. Yes. We have let's try
to print the dictionary. Now as you can see I
am getting all these values with key value pairs. Now, I can access the values in the dictionary using
the keys as indexes and just try to third
over here as you can see. I'm getting the value at the key that is third now
for the similar purpose.

I can use the get function
and specify the key value. There. It is going to show me the same
value now to update a value in the Eddie I'm just going
to write the index number that is our key value here. So instead of machine learning,
let's just say Hadoop. Alright, so when I print the dictionary now it is going
to show me an updated value. Also, I can add the key value
pairs using the square brackets. I'll just specify the key value. Let's just say for here. I'll add machine learning again. Okay. Once again, we have
made a mistake here. We wrote the wrong name. Now as you can see, we have added another value
to our dictionary. So this was all
about dictionary guys. Let's quickly move on to topple
at Apple is an ordered and unchangeable. Now what it means is
it is immutable just like a string we cannot make
any changes in the topple, but we can have the duplicate
values in the top layer as well.

So let's try to understand
this with an example. So I have a couple here which has a name animals
and I have few values here. So let's just do this
in jupyter Notebook as well. So I will My double
as a name animals, so I will give it a value
in round brackets a few integer values first
just to check off course and then I'll add
some values like tiger and just say line and one more I
will give let's say giraffe.

Let me give a duplicate
value here to check if we can actually add
a duplicate value or not. I'll say tiger once again, so I have successfully
created a couple here. Now. Let me access the values
here using the index number. Let's see if we can do. That so this actually means
the tuples are indexed as well. We can use the index values
to access the values from the double now since it is immutable
or we cannot change it. There are not many operations that you can perform
on a topple, but you can count the number
of duplicate values using the count function here. Just going to write the value. Let's say tiger, we have duplicate
value over there. So we will check
how many times tiger is there? So it's going to give
us the count here. So this was all
about topple guys. So let's quickly move on to set
now now a set is a collection.

In just like a list
or a dictionary as well, but it is unordered and there are
no duplicate entries present. Now, let me show you
this with an example in the jupyter notebook. So I will give my set
as the set name and inside the curly brackets
we can have values. Let's say 10, 20 30 40. I'll also give a few duplicate
values just to check if we can have duplicate values
are not seeing value. Let's just said Eureka courses as you can see we
have successfully declared a set here now, let me Me try to print this now as you can see there are
no duplicate values, even though when we
have declared the set it was there now.

Let me try to access the values
using the index numbers. It has shown us an error which says set object
does not support indexing which means a set does not have
any indexes and every time we print a set it is going
to show us a random value. So this was all about set guys
briefly talk about range now. So range is used
whenever we are iterating through values suppose we want
to Numbers from 0 to 10. Let me put it in a list
to get the values. So what I'm going to do is
I'll just write 11 over here and it is going to give
me the values in the list that is from 0 to 10. So this is all about range guys.

Now, let me take
a miscellaneous example now, I'll have a dictionary
with some values again integer values now, let me try to make
a list and try to get the values from A and B as well, let's see if we can do
that now when I print see here. It is going to show me that our list C has the list a
and a dictionary as well. So which shows you
can actually make a list with other data types. For example, you can actually incorporate
a dictionary over there. You can also do that with the topple or asset
and if you want some value that you don't want
to change the future you can actually make it a double
and declare it in a list so that you cannot change
that value in the future. For example, if you don't want to access
any value using the indexes you can make it with set so that it does not
have any indexes.

So that is all about data types. Guys, so there is one more topic that I want to talk about which
is type conversion now suppose we have an integer here that has 10 value
and we have a string as well. Which says now when I try to add these two
variables name and eggs, it is going to show
me a type error, which says unsupported operating
types now for this error, I am going to do
a type conversion here. So let's quickly talk
about type conversion before moving on to the example. So type conversion is basically when you convert
a type of a variable to another Data type so we have all
these functions here which will convert the data type into
their respective counterparts.

Now, let's try to look
at the example now, so we are getting an error here, but what if I change
the data type of integer into string am I going to get
the same error again or not? Let's just see we're not going
to get any errors. So this is what is all
about type conversion. Let me show you
one more example. So we had a dictionary
over there that is with the name be
what I'm going to do is I'm going to use
the list function and specify be over there. So I have actually converted
our dictionary into a list. So this is what is
Type conversion all about. Collections in Python
before moving on let's take a look at the agenda
for this session. So first of all, I will be talking about what
our collections in Python and then I will discuss what is
the collections module in Python and how we can use it and finally I will sum up this session with various
specialized data structures that are present
in the collections module.

I hope you guys are clear
with the agenda Also. I suggest you to subscribe
to a director channel for more exciting tutorials. And also, press the Bell icon
to get the latest updates from madurai go now. That wasting anymore time. Let's understand what our collections in
Python collections in Python are basically
container data types namely list sets topples and dictionary. They have different
characteristics based on the Declaration type
and the usage as well. So let's take a look
at each of them. So talking about list
a list is declared in square brackets guys. It is mutable, which means you can
actually change the values once you have declared
a list and it also stores duplicate values and the elements can be
a accessed using the index has now talking about double
a double is ordered and immutable in nature, which means you cannot change
a value inside a double once we have declared it
an audible can also have duplicate entries present
inside now talking about asset asset is unordered and declared in curly brackets.

It is not indexed which means you
cannot access the elements inside a set using
the index has also it does not have any duplicate
entries present as well not talking about a dictionary
a dictionary has Value Pairs and is mutable in nature which means we can change
the values inside a dictionary and we use the curly brackets
to declare a dictionary as well. So these are the pythons
general purpose built in container data types. But as we all know python always has a little
something extra to offer so it comes with a python
module name collections, which has specialized
data structures. So let's take a look at the
python collections module guys. What is it and
how we can use it. So Python programming language has for collection data types
that I have already told you which Has less double sets
and dictionary but python also comes with a built-in
module known as collections which has specialized
data structures, which basically covers for the shortcomings
of the four data types now connections module in Python Implement
specialized data structures, which provide alternative to pythons built
in container data types.

So let's take a look at those
specialized data structures in collections module. Also, you don't have
to install collections like other python modules guys. It is already
there inside python. You can just import it. Writing this name collections. So I'll show you while we are working
on the use case guys. So taking a look at these specialized
collection data types guys.

So first of all,
we have a name topple. Then we have chain map deck there is counter order
dictionary default dictionary. Then we have User Dictionary
user list and use a string. So we'll be taking a look
at each of them one by one guys. So let's take a look
at name topple guys. So what exactly is named couple
named Apple returns a double with named entry, which means there will be
The name assigned to each value inside a double now, if you look at the topple as
in general, it does not have any any named entries, but with named Apple
we can do that. So it actually overcomes
the problem of accessing the elements using the index
values with named Apple. It becomes easier
to access these values since you do not have
to remember the index values to get the specific elements
now here is an example guys.

So this is what unnamed
apple looks like guys. So let me take up to pycharm
guys will try to implement unnamed couple using
the This module so we are inside the pycharm guys. I hope this is visible to you. So first of all, what we'll do is we'll import
The Collection module and from collections. Okay, as you can see, I
have not installed it anything. You can just write Collections and it will appear
the so from collections. I want to import name
to play guys done. Now, what I'll do
is I'll simply okay. Let me Implement
a name double first.

So I'll just make it
as a and use named up. Over here and over here. I will just provide some values. Let's say the name of my name
double will be courses. I have to put it
in comas case now. I have to give some names like I'll just write course name
and then let's say technology. Now. What I'll do is I'll make
one more variable and I will pass this and provide some values over
here for my course name. I'll write data science. And for technology,
let's say python. Now when I print s over here,
let's see what happens. So as you can see, I'm getting the output
as this courses, which is the name
of My Double and over here. I am getting the named entries
for these values that I have put
inside this double guys. So this is how you can Implement
a name double guys. It's as easy as it looks you just have to import
it from Collections. And after that you have
to implement our name double and inside that I have provided
the Name and the values that are going to be there
for the table guys now, I'll show you one more
thing guys how you can actually get the value or Implement a double
using a list guys.

So let's take a look at that. So what I'll do is
I'll take one more variable. Let's say s now. What I'll do is
I'll just specify using this variable over here
and I will use make and over here. I can just make a list
and I will provide values like let's say
artificial intelligence. And technology is going
to be fighting nice. So if you're wondering why
am I making this course has these courses are available
at our Erica website guys. You can check them
out anytime you want. So now when I print this, let's see what
is going to happen. So I've actually used a list to get a name double guys to get
the values inside a name double.

So this is all
about name double guys. It's actually pretty easy
and you can get named entries for your values
inside the double. So let's take a look
at the next one that we have. Have which is
actually dead guys. It is written as DQ, but we can pronounce this as
deck now talking about deck what actually it is used
for so deck pronounces deck is an optimized list
to perform insertion and deletion easy. So when I say optimized what it actually means
is there is a way where you can actually do it
very precisely and very easily as so let's take
it up I charm again and we'll try to implement this so from collections
instead of named topple.

What I'm going to do is I
am going to Import that guys now what I do is so let me
just specify a list over here. So I'll just write
a few values here. Let's say a deer a Car Guys. Let's see. What's happening here. So now what I'm going to do
is I'm going to use a variable and inside this I
will pass this list. Let's see what we get. If I print this variable guys,
so I'm getting a DQ. I have made a deck
using the list guys. So let me show
you the operations that we can perform in this. So first of all, let me open the value
or add a value guys. So what I'll do is
I'll just open a value. So let's say append
and Let's say python. Yeah, so now when I print this
you will see the different guys.

So we have a deck over here. And after that I
have appended a value or inserted a value using
this append function guys. So which means I
have added the value at the end of the day now if I want to add it like
before the deck guys, like in the beginning
of the deck, what I have to do is I'll
just have to use this method which is opened left. So now we'll see
what is going to happen guys. So this value python is actually
inserted in the beginning of the deck similarly
for removing a value. What I can do is okay. I'll just Now we
have added this value. Let's say I want to actually
remove this value. So what I'll do is I'll just write the dot pop
and let's see what happens. I'll print it again. So as you can see from the value from the end
of the deck is missing now, if we have actually removed it from the deck using
the power function, but let's see if I want
to actually remove this value.

How am I going to do it? I'll just write pop left guys and as you can see See the value
python is also missing here. So this is an optimized version of insertion and deletion
guys using the deck. So this is all about dat guys. Now, let's talk
about the next one that we have which is a specialized
data structure office lie, and that is chain map. So chain map is a dictionary
like class which is able to make single view
of multiple mappings. So it basically returns a list of several other
dictionaries suppose. You have two
dictionaries suppose. We have two dictionaries
with several key value pairs, so This case Jane map
will make a single list of both the dictionaries in it. So as you can see
in this example, we have two
dictionaries A and B. And if I use the chain map, it will return me a single view
of these two values or multiple mappings. So let's take it up
to pycharm guys will try to implement this again.

So I'll remove this
and instead of deck. We are going to use or we are going to import
chain ma'am guys, so it's very simple. So let me declare
two dictionaries guys. So first of all,
I We'll give a value. Let's say 1 and Eureka then the second
key value pair is going to be lets say python. Now, let's take one more.

And inside this I
will give the value. Let's say ML. And the fourth one is going
to be lets say yeah now using the chain map. I'm going to specify
these two dictionaries in this. So let's print a one. Let's see what And so
as you can see, I have made a chain map which has a single view
for multiple mappings, which is a and b guys. So this is what you can do
using the chain map guys. I hope you understand this. So this is a very
basic example guys to let you actually understand
what is happening over here. So we are using
these two dictionaries and we are able to get it
inside a single view guys.

So let's take a look
at the next one that we have which is counter guys. So Counter is also
like a dictionary subclass, which is used to count
hashable objects. Now, what are hashable objects? So let's take a look
at this example. So let's say we have
a list inside this we have different elements. So what counter
is going to do is okay. Let's take it if I jump
to understand this better guys, so I'll remove this
and instead of chain map. Let's say I have come to so
let's take a list guys. So I will specify
some duplicate values because This is what
it is used for to count the hashable objects guys.

Now what I'll do is I'll make
one variable and use the counter in pass a over here. So when I print C now,
let's see what happens. So as you can see, I'm getting a dictionary inside
which I have these values so which is saying the number
of times to has occurred is five number of time
for has occurred is 3 and then again 1 2 and all so when I run this
again I'm getting the same value so this is how you
can actually use counter guys to count the hashable objects
inside any I travel value so we have a list we
can you do it for any other I travel object guys
like a double or set so this is all about counter I hope you understand
this now in addition to the operation you can perform
on a dictionary counter has three more operations
that we can perform so which are basically an element
function a most common function and a subtract function as
well so we'll talk about at them in detail now so talking
about the element function guys so let's see what I women's does
so we'll see elements now so I hear we want
the list so we will put it in the list Constructor guys
and let's print this Okay, let's see.

What are we going to get? So it returns a list containing all the elements
in the counter guys. So as you can see, I'm getting all the values
that I have inside the counter and this is the counter
that I have. So to comes five times
one comes two times and then we have
3/2 times 4/3 times and so on. So this is the function
of elements function which is returning a list
containing all the elements inside the counter and now let's take a look
at the next function that we have which is
the most And function so let's get on to it. So we'll use the C
which is our counter guys. So I'm going to use
the most common here now. So let's see
what I will get here. So I'm actually getting
a sorted list with the count of each elements
inside the counter.

So we have 2/5 times 4/3 x + 1 2 X 3 2 times 5 2 x
+ 6 one time. So this is actually how you can use the most
common function and then we have one more function
which is subtract guys. So Subtract, let me get
one more variable. So I want to subtract let's say so I'm getting to five times. So I'll just
subtract two one time and I'll subtract six one time. So what I'll do now here is
I use the counter and let me use the subtract function guys.

Here it is and I
will pass sub over here. Let's see what happens. Okay. So now when I print
my counter Okay, I will get the values
the most common values again. So now as you can see
2 is coming for X here and 6 is coming 0 times because I have subtracted
using the subtag function. So this was all
about counter guys. Let's talk about
the next data structure, which is soldered dictionary. So order dictionary is
a dictionary subclass which remembers the order
in which the entries were added. Basically, even if you change the value
of the key the position will not be changed because of the order in which It
was inserted in the dictionary.

So let's take it up to pycharm guys will implement
the order dictionary over there. So I will remove all this. And instead of counter,
we will import order dictionary. Now. What I'll do is I will Implement
an order dictionary. Let's say d and now
I'll add a few values. Let's say okay. The first one is going to be e and then second one is let's d
no let me print D over here which is our order dictionary let's see what the output will be
so we have an order dictionary which is saying
on the first value we have e and then so on we have
Eddie wake up all the letters from Eddie recognized so this is how you can actually Implement
an order dictionary guys so let me take a look at what
all functions do I have in this so I have pop update pop item get items from Key set
default values clear copy keys so let me get all the keys
from this When I run this, okay, let me print this.

Now as you can see, I'm getting
the order dictionary Keys, which is one two, three,
four five and seven and similarly I can get
instead of keys. Let's say about all we can get. We can update Bob item. Okay, let's get items. So the functions are
actually similar to what we have for dictionary guys. So this is all about order dictionary guys it
remembers the order in which the elements were put
inside the dictionary you guys. Okay. Let me do one thing is I
will change the value the first let's print this so
you'll understand it better. So now what I will do is I
will change the value at 1. So instead of e let's
say I want Peola and now when I print it
let's say what happens. So as you can see, I have replaced
the value over there, but since it was inserted
in the beginning, like the first one was e value
is not changing over there.

So this is the main reason
why we use order dictionary because it remembers
the order in which the elements are being added
inside the dictionary. So now that we are done
with order dictionary. Let's talk about
default dictionary guys. So what basically
default dictionary does is it is a dictionary subclass which calls a factory function
to supply missing values? So in general it
does not throw any errors when a missing key value
is called in a dictionary. So you'll understand
this better guys. So let's take a look
at this example. We have a default dictionary in which we have
to specify a type as well. So let's say we have
two values on the first value we have at Eureka
and then we have python but instead we want to print
Java there which is not actually inside the dictionary because there is
no value present. That but we will not get
any key value errors and it will instead
give the output as 0 so let's take it up
to pycharm guys will try to understand over there.

So let's remove all this. Now instead of
ordered dictionary. We are going to import
default dictionary guys. So let's make
a default dictionary. And inside this let's specify
the type as well. Now. Let's say we have
the first value as python the second value. It's a anyway car. Now when I print
this T over here, I'm getting the value as it's showing me
that we have a default dictionary which has
a class into that.

We have specified over here. And then we have a dictionary
with the values 1 2 which has python
and a director respectively. Now, let's say I want to get
the value at the number three, which is not
actually present there, but I'm getting the output as 0 so I will show
you the different guys what actually happens if you do this in a normal
ordinary dictionary guys, so I will Make
one more dictionary. Let's say and I'll give
it some value at say. Python and Eddie Rekha now when I print this
which is not actually present inside the dictionary. Let's see what we
are going to get. We're going to get
the key error guys because 3 is
not actually present inside this ordinary dictionary. But if you put it
inside a default dictionary, you're not going
to get this error guys. So this is what is function
of default dictionary guys.

It does not show you
or through any key error, even if the value
is missing inside. Actually you guys so now that we are done
with default dictionary. Let's take a look
at the next one that we have which is User Dictionary
user list and use a string. So these three data structures
are actually same but different. So let's talk
about them one by one. So talking about User Dictionary
this class acts as a wrapper around dictionary objects now that need for this class came from the necessity to subclass
directly from the dictionary. It becomes easier
to work with this class as the underlying dictionary
becomes an attribute now, Talking about the user list
this class acts like a wrapper around the list objects and it is useful Base Class
for other list like classes which can inherit from them and override
the existing methods or even add a few more
new ones as well.

And the need for this class came
from the necessity to subclass directly from list. It becomes easier
to work with this class as the underlying list
becomes an attribute as well. Now talking about
user string guys. It is also a wraparound string
objects for easier strings. Glassing now the need for this class has been
partially supplanted by the ability to subclass
directly from string. However, this class
can be easier to work with because the underlying string
is accessible as an attribute in this session today guys.

I will be covering
the following topics. First of all, I'll be explaining what exactly is an array
and then I'll be differentiating between Python lists
and arrays now, this is a very common question. Question that many
of us asked after that. I'll be showing you
how to create arrays in Python following which we will try
to access array elements and then we will try to perform
some basic operations on arrays such as finding
the length of an array adding and removing elements from it or a concatenation slicing
and looping through an array. Now, let's move on towards
the first topic our first topic for this session is what exactly is an array and array is basically a data
structure guys with automatic. What series of elements
any variable that is declared as an array can hold
more than one value at the same time all values in an array have
a particular address which is specified by
its index number here as you can see on the screen. I've declared a variable a as
an array and I've stored values from one to hundred in my array, which is a also make a note of the index values indexing
always starts from zero and not from one therefore a of zero holds
one a of One holds to a of to holds 3 and similarly
a of 99 holds hundred when the length of my array
is n the index value will be n minus 1 it is always 1 less
than the length of the array.

Now. Let's move on towards our next
topic for this session, which is the difference
between Python lists and arrays python lists and arrays have the same way
of storing data, but there is a key difference that you all have to note
erase can store only single data type values. Whereas Lists can store
any data type values. So for example, if I have an array of integer values all values
present in that array will be integers and nothing else
on the other hand. If I have a list then it
can store integers together with float and Cal's
and strings Etc. Now when you try
to perform some operations, like slicing or looping it
will be similar for both, but when you try to perform
different operations, like if you want to multiply
your array values by 2, or you want to Divide it
by 2 you can do so easily when you have an array, but if you try to do
the same with the list, it will throw an error because naturally you
cannot multiply cares and strings or divide them.

So I hope you are clear
with the difference between these two. So now let's move on
towards the next topic how to create arrays in Python unlike
other programming languages. If you want to create
a raise in Python, you will have to import
the array module now this module has all the functions that are necessary for creating and performing Various
kinds of operations on arrays to import
the array module you can use three ways first is
to import the array module by its original name, which is array. The second method is
to use an alias name. This is the most widely and commonly used method as well
in my demonstrations. I'm going to be using
this method the Third Way is using star
from array import Star what this does is
it's going to import all that is present
in your array module now, let's go To our jupyter notebook
and try to do this.

Please do it along with me guys. I'll open a new notebook and I will use the first method
to import the array module as you can see when I hit run no error
has been returned, which means this
is executed now, let's try to create
arrays using this method As you can see over here. I've created an array
using the first method. So I have used a red dot array
of integer values and have specified
some random integer values here. The first array is
the name of the module. The second array is
the array Constructor and then I've given a type code this type code specifies what type of elements
my array will hold as you can see. I've created an array. So I hope you are clear with how to create arrays
using the first method now. Let me open the notebook and try
the second method the reason to open a new notebook is because I've already
imported array module in this notebook I'll
rename this notebook because I'm going
to be using this method in further demonstrations as
well as you can see over here when I use import array as ARR ARR here is my Alias name when I use this and hit run
it does not throw any error now let me try to create arrays
using this method I'm using it as my data type you can use
any data type of your choice as you can see that an array has been created with some random
integer values in place of the module name array
I've used ARR now let's try the third method I'll open
a new notebook again As you can see over here when I'm creating arrays
using the third method.

I've just specified
The Constructor name and then the type code
and the value list. So now let's get back
to our presentation. Our next topic for this session
is accessing array elements to access array elements. You'll have to make use
of the index values each index value holds
a unique element. Like I've told you before indexing starts
from zero and not from one. So therefore a of zero
holds one a of One holds 2 and so on this is the normal driver still order which starts from the left
hand side and moves towards the right hand side. But here I want you
all to note this point as well that negative
indexing also exists. So negative indexing will start
from the right hand side and move towards the left hand
side there 400 will be at a of – 199 will be at a of minus 2 and similarly one will be
at a of – hundred now. Let's go to our Jupiter. Your notebook and try
to access some array elements.

As you can see over here. I've created a heading
to create a heading. All you have to do is go
to code select heading and prefix your text with the number of hashes based
on the heading level you want. So if I want H 1 I
will use one hash if I want H to I will use 2
and so on here, I've created a heading of H1, so I prefixed my text
with one hash now. Let me try to access
some array elements. As you can see over here when I access a of
to my output is 3 let's see where 3 is present in my array one is present
at a of 0 to at a of 1 and 3 at a of 2. So therefore when I access
a of two three has been returned our next topic of this session
is basic array operations here. I just want to tell you all
something arrays are mutable, which means they are changeable. So in case you want to add Or remove elements from it you
can do so easily now coming back to our presentation
our first operation under this section will be
finding the length of an array the second is adding
or changing elements of an array and then we will try to remove or delete elements
of an array and then guys, we will try to perform
array concatenation slicing and finally we will be looping
through an array.

Now. Let's move on towards the first
operation to find the length of an array you
will have to make use of The Len function
now this function returns an integer value which is equal
to the number of elements that are actually present
in your array. The Len function
takes one parameter, which is the name of your array as you can see
in the example of here. I've created some random array a and I've given
some random values as you can see. I have three values over here
and when I use the Len function and I specify the name
of my array the output is 3 which is equal
to the number of elements that are present in my array. And now let's move towards
our jupyter notebook and see how this works. As you can see over here when I use the Len function
and I've given the array name which is a and integer
value is returned, which is six six is the number of elements that are actually
present in my array, which is a okay.

So I hope you are
clear with this. So I'm next operation
is adding elements to an array in case you
want to add elements to an array you can do so
using the append extend or the insert function. The append function is used when you want to add an element
to the end of your array. The extend function is used when you want to add
more than one elements to the end of your array. The insert function
specifically adds a new element to a particular position
in the original array. Let's have a look at the small
example of these three as you can see on the screen.

I've created some random array a and then I've used
the append function and I've given the value
that I want to add to my array as you can see in the output
3.4 which is the value of I've specified
to the pain function. Has been added to the end
of my array which is a and then I've used
the extend function. Please make a note over here that when you use
the extend function, you will have to specify the
values between square brackets. If you don't use
the square brackets, it will throw an error. I've given three new values and all three values have been
added to the end of my array and then I've tried to use
the insert function over here. I've specified the
index number as 2 and the value to be inserted
at that position as 3.5. As you can see in the output
3.4 has been inserted at Sea of to now, let's go to our jupyter notebook
and will do the same.

I'll repent my array
which is a so that it's easy for us to refer to it. Since my array
holds integer values, I will give some new
integer value to it. As you can see I've given
eight as the value that I want to insert
in my array and eight has been added
to the end of my array now. Let me try to give
some float value to this array and see what happens. As you can see when I try to append
some float value, it gives me a type error. Therefore I can add
only those values which is specific
to the type of elements that are present in that array. Now, let me try to use
the extend function. Like I told y'all when you're using
the extended function, you will have to make use
of the square brackets.

As you can see
in the output all the values that I've specified
within the extent function have been added to the end
of my array now, let me use the insert function. I've used the insert function and the first parameter I've
specified is the index value and the second is
the element to be inserted at this index position. So at index value a
of to 6 will be inserted as you can see in the output
six has been inserted at a of to so I hope you are clear with
how to add elements to an array. Now. Let's move on towards
the next operation. Our next operation is removing
elements of an array in case you want to remove
elements from an array.

Can make use of the pop
or the remove function the pop function removes
the element and returns it whereas the remove function
will remove it but it will not return
it the pop function can either take no parameters
or one parameter the parameter. It takes is the index value
of the element to be removed. If you do not
specify any parameter, it will remove the last element from the array the remove
function takes one parameter, which is the element
to be removed itself. Now, let's have a look
at a small example of this as you can see on the screen. I've created some random array a and then I've used
the pop function without specifying any parameter as you can see in the output when I do not
specify any parameter the last value present
in my array has been popped and returned as
well second time. I've used the pop function
and I've given some index value.

Now this pop function
will remove the element that is present at
this index position as you can. See, it has removed 3.1
and returned it as well. After that. I've used the remove function. Like I've told you before the remove function
takes one parameter, which is the element
to be removed and you can see in the output that the remove function has not
returned any value after that. I've printed my array
and you can see all the values that are removed using
these two functions are no more present
in the array a now. Let's go to our jupyter notebook
and do the same. Let me reprint my array, which is a first I
will use the pop function without specifying
any parameter to it. As you can see over here when I
do not give any parameter. It removes the last element
that is present in my array now, let me give some
index value to it. I'll repent my array a because I've removed
an element from it now.

Let me give some index value
to the pop function. As you can see when I use a DOT pop
of to it removes the element which is present at a of 2 which is 6 and it
returns it as well. Let me try to use
some negative index value for the pop function. It'll pop of minus one removes the last element
that is present in my array, which is 5 now. I'll use the remove function. Let me reprint my array guys, as you can see all the elements that have been removed
using the pop function are no more present in my array
a like I've told you before when using the remove function, you will have to
specify the element that is to be removed here. Let me remove it because there are two
occurrences of 8 and let's see what the remove function does
when I hit run remove function does not return anything now, let me print my array and see
what this present as you can see.

The first occurrence
of eight has been removed, but the remove function
did not return the value. So I hope you are clear
with the remove and the pop. Students now let's get back
to our presentation and perform the next operation. Our next operation is array concatenation
concatenation means joining. So in case you want
to join different arrays, you can make use
of the plus symbol as you can see on the screen. I've created some
random array A and B, and then I've created
some random array C, which is empty also make a note that all three arrays have
the same type code and then I have concatenated a
and b into my empty array which is see. As you can see in the output
all the elements present in A and B have been concatenated
into my array C. Now. Let's go to
our jupyter notebook and perform array concatenation. I'm using it as my data type you can use
any data type of your choice. To create an empty array. All you have to do is
specify the type code and leave the value
list empty here.

I've created an empty array D and have concatenated B
and C into my array which is D. Now. Let me hit run when I hit run
all elements present in B and C have been concatenated
into my new array, which is D. So I hope you appear
with or a concatenations. Let me just show
you what happens if I try to concatenate arrays
of different data types. I'll just change one
of my Previously created a raise type code
and I'll give it as float. Let's see what happens
when I change the type code and I try to concatenate
these two arrays. You can see that I've encountered an error
and it says type error which means it
cannot concatenate two arrays of different data types. So just be careful when
you're concatenating arrays. You cannot concatenate arrays which hold different
data type elements. Okay. Now let's move on
towards our presentation and see what is the next operation. Our next operation is slicing
an array slicing actually means fetching some particular values
from your array to do so, you can make use
of the colon symbol as you can see on the screen.

I've created some random array a and I've sliced it
from 0 to 3 0 specifies from We're fetching has to start
and three specifies where it has to stop so it will start from zero. It will go on till 3:00, but it will not
include the value which is present at 3:00. As you can see in the output. I have a of 0 a
of one and a of 2 that is present in my output. Now, let's go
to our jupyter notebook and we will try
to slice our arrays.

I'll reprint Maya radio here
and then I will try to slice it. As you can see, I've sliced my array
from 0 to 5. So it will start
from index number 0 it will go to 5 but it will not include
the value which is present at index number five. You can also see the same
in the output over here. Let me try to use
some negative index value. My output when I use 0 colon – to contains all the values
between 0 and minus two, but it will not
include the value which is present at minus 2. Okay. So I hope you have
here with this topic. Just give me
a quick confirmation before I move on. Okay, I know it says
yes Shashank has a question. He asks, what does colon colon minus
1 Min Shawshank unlike what many of us think colon colon minus
1 does not reverse my array, but it prints a reversed
copy of my array. So let's try to do
this over here. as you can see all the elements present in Array D
have been reversed now, let's print our array which is d The original array D
is the same but colon colon minus 1 has reprinted
a reversed copy of my array, which is D.

This method is
actually not preferred because it exhausts the memory. So I hope I've cleared
your doubts Shawshank. Just give me
a quick confirmation. Okay. Shawshank says, yes. Now let's get back
to our presentation and perform the last operation
of this session which is looping through an array. You all might be familiar
with these two Loops, which is the four and the while
Loops the for Loop iterates over the items of an array
specified number of times. Whereas the while loop iterates until some condition is met
or some condition is true when you're using the while loop
you will have to keep three things in mind one
is initializing your iterator. In is to specify a condition third is
to increment your iterator. Remember that if you
do not increment your iterator your while loop
will go on forever.

Let's see a small
example of this as you can see on the screen. I've created some random array and then I've used the for Loop
to Loop through my array. I've used for X in a print X
which means go to every element that is present
in a and print it. Let's try to do the same
on our jupyter notebook. Let me reprint my array D. Now. Let me use the for Loop
to Loop through this array. For X in a print X which means go to every element
in D and print it as you can see
all elements present in D have been returned one
after the other now. Let me try to slice this array
and print specific elements. As you can see over here.

I've sliced my array from index number 0 to minus
3 and I've printed only those specific values
using the for Loop. Now, let's go
to our presentation and have a look
at the while loop. Like I've told you before when you're using the while loop
you will have to do three things one is initializing. Your iterator second is
to specify the condition and third is to
increment your iterator. Let's try to perform
looping on our jupyter. Notebooks. Please do it along with me. Let me reprint my array d. Here I'm using
the iterator as temp. You can use any name
of your choice. As you can see over here, I've initialized my iterator to 0 and then I've
specified a condition where an I have told
whenever the value of my temporary variable is less than D of to then
print that value and then I have iterated
the value of temp. I can also use
Temple us equal to 1 which is same as temp
equal to 10 plus 1 now.

Let's try to use the while loop
using the Len function here. I will use my array
a so let me reprint it. here as you can see over here
when I use the Len function, my temporary variable will go
to all elements present in my array a and print
them one after the other. So I hope you are clear
with looping data requires a number of ways
in which it can be stored and accessed and one of its most important
implementations includes hash tables and hashmaps. So before we begin just
make sure you subscribe to our Channel and
hit the Bell icon. To stay updated with all the
latest Erica videos coming back towards the session we shall
first begin by understanding what exactly are hash tables
are hashmaps in Python. And for that I'll
be showing you guys how to create dictionaries
nested dictionaries and perform various operations on hash tables such as
accessing updating and deleting items from them. Finally.

I'll be showing you guys how to convert
a python dictionary into a panda's data frame. So without any further delays,
let's get started. So what exactly is
a hash table or a hashmap in python in the field
of computer science a hash table or a hash map is a type of data structure that map's
keys to its value pairs. It implements the abstract
or a data type. So this basically
makes use of a function that computes an index value that in turn holds the elements to be searched
inserted removed Etc.

This makes it easy
and fast to access data in general hash table
store key value Pairs and the key is generated
using a hash function. hash tables are hashmaps
and python are implemented through the built-in
dictionary data type the keys of a dictionary
in Python are generated by a hashing function the elements
of a dictionary are not ordered and they can be changed so for example a dictionary can be
a mapping of employee names and their employee IDs or the names of students along
with their student IDs okay so moving ahead
let's go on and see how to create dictionaries
in Python dictionaries in Python can be created
in two ways one is by using the curly braces and the second is
to use the dict function so now I'll jump
onto my jupyter notebook and over here I'll
be showing you guys how to create dictionaries
in both these methods so the first method is by using
the curly braces for that I'm just going to give
some name to my dictionary I'll say my dictionary And I'll just give some random
key value pairs to this.

So I'll just give
a name said Dave. And I'll specify the value
of this as 0 0 1 so just consider this to be
an employee mapping with the ID numbers. So I'll give
another key over here. I'll say Deva. And I'll specify
the ID to be 002. I'll specify another one say Joe and I'll give the value
as not not three. Okay. So after this,
I'll print out my dictionary. and also the type
of my dictionary and then I'll hit shift enter. So as you can see over here, my dictionary has been
printed out and the type of it is dictionary itself. Okay. So now to show you guys how to make use
of the dict function. All you can do is just
specify some name. I'll say new dictionary. And make use
of the dict function. I'm not giving
any parameters at first. I'll just print out new ticked. And the type of it as well.

Okay, so as you
can see over here and empty dictionary is created since no key value pairs
are supplied as a parameter to the dict function in case
you want to add the values. All you have to do
is specify parameters into that function. So what I'm going to do is
copy this from here, we'll just paste it
and within this function, I'll specify these values
as a parameter to this so over here, I'll just use
the key value as Dave and I will say this is equal
to naught naught 1 and then Ava Which is equal
to not not to now, I'll just print out new decked. And I'll run this so
as you can see over here, I've specified the key
value pairs as parameter to this function and therefore my dictionary
has been created with those parameters. So I hope you are
clear with this.

So now moving on
towards our next topic which is nested dictionaries. Nested dictionaries are
basically dictionaries that live within other dictionaries. So for example, consider a project within which
there will be a number of teams such as the development team the
marketing team sales team Etc. These are basically
other dictionaries that are contained
within the project dictionary. This project dictionary itself can be a part
of the organization that has a number of projects. So I hope that gives
you a clear idea about what exactly is
a nested dictionary. So now I'll jump onto my jupyter
notebook to show you guys how to create them. So all I'm going to do over
here is create a dictionary which contains the employee details a single team
can have a number of employees and these employees have
different salaries IDs and Nations I'll just
create a variable over here.

I'll just say EMP details. and then I'll use
the curly braces within which I'll specify
the main element to be employed and this is going to contain
various other dictionaries so here the first employee
name will be Dave and since each employee
will have other details such as ID salary designations Etc it is going
to be another dictionary with in this dictionary so I'll just open
another dictionary and over here I'll specify ID to be 0 0 1 the next detail that I'm going to specify
for this employee is the salary so I'll just specify
the key as salary and I'll give some random
value to this say 2000 and finally I'll specify
the designation Okay, so this was all the details for Dave now, I'll create
another employee name.

So I'll move out
of this dictionary and here I'll specify Ava. So just like Dave Ava
is also going to have ID salaries and designations and for that I'll create
another dictionary within this and I'll specify
the same key value pairs. The ID is going to be 0 0 2 and salary I'll give
some random value say 1,000. the designation will
be associate Okay. So after this I just
print out this dictionary. So as you can see over here, I've created a
nested dictionary. So I hope you guys
are clear with this. So now let's move on
towards our next topic which is performing
operations on hash tables. There are a number of operations
that can be performed on hash tables in Python using
dictionaries in this session. I'll be showing you
how to access update and delete elements
from dictionaries or hash tables in Python. So accessing values the values
of a dictionary can be accessed in many ways such as
using key value pairs.

Functions are implementing the for Loop now to show
all this to you. I'll jump onto
my jupyter notebook. I'll just give a heading over
here say accessing values or rather healthy items. So the first method that I'm going to show you
is using the key values. So for that I'll just
use the dictionary that I've created earlier which is my decked and I'm going to say
my underscore dict and the parameter that I'm going
to specify is Dave and then I'll hit run. So as you can see over
here the key Dave contains the value as 0 0 1 python
also provides a number of functions using which you can access
the key value pairs that are present
within dictionaries. Some of these functions
are the keys function. The values function
or the get function. So what I'm going to do
over here is first print out my dictionary. Now I'm doing this only
because it's going to be easy for us to refer to it. So after this, I'll be showing you guys
how to use the keys the values and the get functions.

So what I'm going
to do is print. My dict dot keys. And then I'll head Run Okay, so as you
can see over here when I use the keys
function all the keys that are present
in my dictionary have been returned now in case
I want to access all the values. All I have to do is change this
from keys to values and then hit Run Okay. So as you can see in contrast
to the previous function, the values function
has returned all the values that are present
within my dictionary now, there's another function
which I already told you which is get and to use
function you'll have to specify some parameter
whose value you want to retrieve so what I'm going to do is
print my dictionary dot get and I'll specify
the value as Ava so as you can see over here
the value that's present for Ava is not not too so I hope you guys are clear
with this so there's another way by which you
can access the values that are present in a dictionary
and that is using the for Loop so in case I want to retrieve
all the keys that are present in my dictionary all
I'm going to do is use for X in my district as he protects so as you can see over here my for Loop is iterating
over all the keys that are present
in my dictionary and it has returned all of them
one after the other now in case I want to fetch only the values that are present
in my dictionary all I can do is use the same for Loop and within that I can specify
my dick taught values function so as you can see all the values that are present
within my dictionary have been returned by the
for Loop now there's another function called as items that will retrieve all
the key value pairs that are present
in my dictionary so to show you guys I'll just type 4 x 4 x in my dictionary
Dot items which is the name of the function.

Sorry guys, this
supposed to be X comma y since I have to retrieve
two values at a time. That is the key and the value
and then I'll just print X comma y. So as you can see over here, I have all the keys
along with their value pairs. Okay, so I hope you
are clear with this. So now let's move on and see how we can actually
update the values of a dictionary dictionaries
are mutable data types and therefore you
can update them as and when required so in case if you want to change the ID
of some employee or if you want to add
some new key value pair to a dictionary you
can do it easily. So now to show
that to you guys, I'll get back
to my jupyter notebook. I'll give a new heading. I'll say updating. So I've already created
a dictionary of here and from that dictionary. I'll just change the value of
Dave from 0 0 1 2004 for that.

I'll just specify my dict. And within this I'll specify
the parameter as Dave. And the value I'll change
it from 0 0 1 2004. Now I want to add some new value
to my dictionary. So for that allowing going
to do is specify my dict. And I'll specify
a new parameter. Say Chris. And the value I'll specify
to this as 003. Finally, I'll just
print out my date.

So as you can see over here, the value of Dave
was initially 0 0 1 and now I updated
it from 0 0 1 2004 you can also see over here that I've added
a new key value pair and the key is Chris
and the value is not not three. So I hope you guys
are clear with this. Okay. So now let's get back
to our presentation and see how we can actually delete
items from a dictionary.

There are a number of functions
that allow you to delete items from a dictionary such as the DL
function the pop function. Pop item function pure Etc. So to implement this I'll get
back to my jupyter notebook and over here. I'll create a new heading. So the first thing that I'm going to do is
use the pop function, so I'll just copy the name
of my dictionary from here.

And I'll use the pop
function with this. So the pop function
will take one parameter and it's going to remove
that key value pair from my dictionary. So just specify Ava
And I'll hit run. So as you can see over here, the pop function has removed
and return the item from the dictionary. So there's another function
called as the pop item function which will remove
the last inserted element from my dictionary. So for that all I'm going
to do is specify my date.

Dot pop item and then I hit Run Okay. So as you all know the last item that I had added to my dictionary was Chris
having the value of not not three pop item has removed
that and returned it as well. So to use the delete function. All you have to do is
specify DL followed by the name of the dictionary and to this you'll have
to specify the key whose value you want to remove
from your dictionary. So here I'll just specify Dave
and I'll hit run finally. I'll just print
out my dictionary. So as you can see over here, all that is left
in my dictionary is just one key value pair, which is Joe having
the value of not not three.

Okay. So now let's move on
towards the last topic of this session which is converting a dictionary
into a data frame. So before showing you guys how to convert
this let's first see what exactly is a data frame a data frame is
a two-dimensional data structure that consists of columns
of various types. It is very similar
to python dictionary and you can even
convert a dictionary into a Those data frame. So now to convert this. I'll get back
to my jupyter notebook. Okay. So as you all have seen
previously I had created a nested dictionary
containing employee names and their details map
to it now to make a clear table out of that. I'll make use
of the pandas library in order to put everything
as a data frame. So what I have to do over
here is import pandas. And I'll take a new
variable say d f I'm going to import
the pandas Library as PD guys.

Sorry, it's just an alias name
so you don't have to worry about that. So I'll just use
PD touch data frame. And over here, I'll specify employ
underscore details, which was the nested dictionary
which I've created earlier. Finally, I'll just print
out the data frame. So if I would have imported
the pandas Library as pandas and not as PD in place
of PD over here, I should have written the
complete name of the library, which is pandas. Okay, so now I'll just hit run. So as you all can see a clear table has been created
for the dictionary, which I had created earlier. So here is a list
of all the operators that we have in Python. So first of all,
we have arithmetic operators, then we have assignment
operators comparison operators logical operators.

Then we have membership
operators identity operators and bitwise operators. So we will be discussing all
of these operators in detail. So let's talk
about arithmetic operators at The mattock Operators are
nothing but the operators that are used to perform
arithmetic operations between variables or two values. So these are
the Pneumatic operator symbols that we use in Python. So we have addition subtraction multiplication
division modulus exponentiation and flow division.

So, let's take it up
to jupyter notebook to understand the concept
of arithmetic operators. So let's say I have
two variables X. I'm going to give
this value as 10 and then I have
one more variable. Let's say why
I'll give it a value. Let's say 20 now
to understand the concept of our thematic operators. What I'm going to
do is First of all, I will try to perform addition
between these two variables. So I'll just write
plus over here. And when I execute
this I'm going to get the addition as my output
now to perform subtraction.

I'm going to use
the subtraction operator and it is going to give me the value
as the subtraction over here. Similarly. I can perform
multiplication then I can also perform exponentiation. So I'll use two asterisks
instead of one for exponentiation it is that easy in Python guys now
we will perform division. No, we have so it is going to give me
the value of the division. Now when I do the flow division, I'm going to get the value
over here as well. One more operator is left
that is the modulus. So I will try to perform
modulus as well. So it is going
to give me the value that is the remainder. So this was all
about arithmetic operators guys. So these are all the symbols that we can use
for various purposes like addition subtraction
multiplication division Etc. I hope you are clear
with the concept of arithmetic operators.

Now let's try to understand
the next operator that we have which is assignment operator. So you can imagine what
an assignment operator is by the name itself
that is assignment. So we use the assignment
operators to assign values to a variable or any value
that we have in Python. Right? So we have assignment operators
like is equal to then we have plus is equal to so
all these symbols we have let's try to understand
what all these are used for. For example, let's say
we have a variable X which has a value hundred. Now when I write
this X Plus is equal to 10 it is going
to mean the same as X is equal to X plus 10. Similarly. We can write x minus
is equal to multiplication is equal to division is equal
to R exponentiation is equal to now, let's try to
understand these operators or the assignment operators
in jupyter Notebook. So first of all, we have is equal to as
our first assignment operator. So I will have 1 let's say
I have X so I have not assigned any value to this.

Let's say what happens, okay. Let's try one more variable. I'll write this so it is showing
me a name error, which is saying name
a is not defined because I have not assigned
a value to it. So in Python until you assign a value
to a variable it is not going to be declared in Python. So now when I give
the value to this variable, let's say I'll write
5 over here. It is not showing any error, which means I have assigned
a value to this variable. Now, let's try to understand
other assignment operators. Let's see. So what does plus is equal
to Min in Python? Write this what should be
the output guys. So let's try to understand this. So when I print a I get the value as 10 so why
I am getting this value because I have assigned
the value 5 over here. Then I write one more
assignment operator that is plus is equal to 5. So what is going to happen
over here is it is going to be same as
a is equal to a plus 5, so we have 5 over here and we have added five
more to this statement, which means we are getting
the result as 10 over here.

Now, let's try to understand. And other assignment
operators as well. So let's say
exponentiation is equal to 5. So, let's see what
the output will be. So when I print this
I'm getting the exponentiation to the value of five since a is equal to 10 and we
are doing the exponentiation until five digits. So we are getting the output
as a hundred thousand. So this was all
about assignment operator. Similarly we can do
the division is equal to then we have
minus is equal to so these are all
the assignment operator. That we have in bitin. Now, let's talk about
the next operator that we have which is comparison operator. So comparison operators are
nothing but the operators that we are using
to compare two values or objects, right? So we have comparison operators like equal not equal
greater than less than greater than or equal to and then we have less
than or equal to as well.

So let's try to take
an example over here. So when I use
the equal operator, I am going to write
the statement as just I have written over here x is equal to Why so when I'm using
the comparison operator, I'm actually using
double equal to so this is the basic difference
between assignment operator and comparison operator. So let's take it up to
jupyter notebook to understand these comparison operators guys. So let's say
I have two variables. Value is equal to 10
and number is equal to 20. So to understand
the comparison operators, let me take one more variable. I'll say this will be
our Boolean variable. So what I'm going to do
is I will write Val is equal to number one
for I am checking is or comparing these two values. So what exactly I'm doing
is comparing these two variables or values that we have.

That is Val and number one. So when I print
this compare variable what I am going to get
is either true or false, so it is going to be false because value is not equal
to number so I can do this. Miller thing I can check whether it is greater
than or I can check if it is less than so
when I write 10 over here so I can similarly check if it is greater than
or equal to I can check if it is less than or equal to. So these are
the comparison operators that we have in Python, which we can use to compare
two values or two objects. Now, let's try to understand
the next operator that we have which is The Logical operators. So logical operators are used to
combine conditional statements. So what are
the Conditional statements that we have in Python. So let's briefly talk about
conditional statement guys. So mainly we have three conditional
statements in Python.

We have an if statement
then we have an else if statement and we
have an else statement. So I'll give you an example for better understanding so
for these two variables only. Alright if well is equal
to number one print equal. else if well is greater than number one print
greater else print smaller so what happened here is guys first
of all the execution will go to F statement it
will check this condition if this statement is true it
is going to print this value if this is false it is going
to move to the next statement that is the else if statement that we have over here it
is going to check this condition if it is true it is going to print
this statement or if this condition is false
it is going to jump to the next statement that is the else statement and I
will give one more condition so if all of these
conditions Is are false.

It is going to jump
to this statement and it is going to print
not there over here. If all of these conditions
are false, it is going to jump to the next statement that we are going
to have in the program, but I have not written
any other statements. So it is going to end
the execution over here own. So this is a basic example using
the conditional statements now that we are done discussing
conditional statements. Let's talk about
logical operators. So I have told you logical operators are used to
combine conditional statements. So what exactly are
The Logical operators, so we have a logical
and we have logical or or we have a logical not With
by looking at the example. Let's say we have
two conditions over here. We have X is greater than 5 and then we have
X is greater than 10. So let's try to understand
these logical operators in jupyter Notebook.

Now, let's say
I have two statements. Alright X is equal to 10 and what I'm going to do
is I'm going to check if x is greater than 10. All right, and which is
my logical and operator and I'll write X is greater than 5 so what is going to happen if I
use the logical and operator if both of these statements
are true it is going to give the result as true. But if one of these statements is false it is going
to give me the value or the output as false. So, let's see what happens
if I execute this statement, I'm getting false because one
of these statements is false.

Now when I write instead of 10, if I write 8 over here,
let's see what happens since both of these
statements are true. It is going to give me
the output as true now instead of and Creator if I use the logical
or operator, let's see what is going to happen. It is showing me that it is true because when we
are using the logical or operator only one of these statements has to be
true the output will be true. But what happens if both
of these statements are false, it is showing me the value
that is false. But let's see what happens. If both of these
statements are true. I'm getting true as well. So one of the statements
has to be true when we are using the
or operator not talking about logical not operator, but I'm going to do is I'll
write not in the beginning now. I specify the condition. Let's say x is greater than 10
and X is greater than 5 this is the same statement that we have used
before and for this we have got the output as false.

So, let's see when we use
the logical not operator. What is going to be the output. I'm getting true
as the output here because this statement is negated over here
using the not operator and we are getting the Value that we should be getting
for this statement. So this is the purpose which fulfills by using
the not operator or The Logical not operator
that we have in Python. So now that we are done
with logical operators as well. Let's try to understand
what our identity operators so identity operators
are used to compare objects.

Now, you must be wondering
what our objects here. So everything in Python
is actually an object so we can use the data types
as objects as well. So let's try to understand. What are the identity operator? In Python, so we have is and we have is not so these
are the identity operators. So what is does is it returns? True? If both the variables
are same object? For example, let's try to do
this in jupyter Notebook.

So what I'll do is I'll take let's say A list I
will give it up some values. Let's say 10 20 and 30. I'll take one more list. Give it the same values. Let's say 10 20
and 30 and I'll write X is equal to list one. So when I use
the identity operators, let's say if I
write X is lest one. Let's see. What is the output
that I'm going to get. I'm getting true because X is actually
the same object as list 1 Now let's try to write lists one is list to even though when we have used the same
values in list one and list two. Let's see what
the output will be. It is false because these are
the not the same objects, right? Similarly. I can use list
one is not list too.

So here I'm going
to get the output as true because list one is
not exactly list to even though we have the same values. It is not going to be
the same object. So this is the concept about the DD operators now
let's talk about the next one that we have is
membership operators in Python. So membership operators
are used to check if a sequence is present in an object or not now
to understand the difference between an identity
and a membership operator. Okay. Let's first understand. What are the operators in
membership operator we have in and then we have not in so it is going to return true. If a sequence with the specified
value is present in the object and it will return true
if the sequence is not present.

So let's do do this
in jupyter Notebook. We have already
specified these objects. So let's try to do if x in list 1 let's
see what happens. It is going to show me
that it is false because we have no values in X. So when I do the same thing
with list one in list two now, you see we have
the same values over here. Let's see what the output
will be it is false again. Okay, let me do one thing.

Now to check a particular value
or a particular sequence. What I am going to write
is I'll check if 10 in list 1 so it is going to check if this is going to be present
over here or not. It is showing me
that it is true. So what if I write
like this 10 20 30 in list 2 it is false. So this is the basic
difference between is that is then identity operator
and membership operators. So when I alright, let's say It is going to check
if this is present in the sequence or not. It is showing false
because it is not there. But what if I add
this value over here, let's say Now when I
execute the same statement, I'm getting true because this sequence
is actually present in the object now
to understand the difference between he's equal
to n the identity operator. Let's see what
is going to happen. What if I write lists
one is equal to list to it is showing false. I have made a change over here. So I'll do this once again, so when I print
this it is showing that it is true, but instead of is equal to if I write is over here it
is going to show me false because the Are two
different objects.

So this is the basic
concept of identity and membership operators guys. Now, let's understand
bitwise operators. So bitwise operators are used
to compare binary values or binary numbers. So this is a rather
difficult concept guys. So I will be telling you about
what are binary numbers first and then we will be moving on
to the bitwise operators that we have in Python. So these are the bitwise
operators like bitwise and bitwise or so, these are the symbols used
for these Operators guys, so this is actually what happens when you
are using these operators. So let's try to understand
bitwise and operator first in jupyter Notebook.

So what I'm going to do is
I'll just try 10 and 12. So what is going
to happen over here? Let's say it is showing
me the output as eight but it is not clear why we
are getting this output. Right? So let's understand what 10 is
in binary numbers. So when I write 10
in binary numbers, it is going to be 1 0 1 0 and similarly for 12
Is going to be 1100 now when I use the logical and
operator but is going to do is if both the bits are
1 it is going to be 1 so in this case only
first bit is 1 over here. So the output will be 1 0 0 0
and if we convert this to a decimal it is going
to be the number 8.

So this is the concept
between the binary numbers guys. Similarly. I can use 10 or 12. So what is happening here
is I have these values. Let's say 1 0 1 0 for 10 and 1100 412 now looking
at first bits here. That is 0 0 it
is going to be one. So all of these bits in the output will be 1 1 1 1
which is exactly equal to 14. So this is the concept
of using the bitwise operators where we are using
the values as binary numbers. We are comparing
the binary numbers now, let's talk about left shift
and right shift guys. So this is what I write
for doing the right shift. So 10 in binary
numbers is 1 0 Zero, so when I write
shift these two beds, I'm going to be left with 1 0 and when I convert
this to Binary, I'm going to get the value as 2. So this is the concept
of right shift guys. Now, let's try to
understand left shift.

So when I write this I'm going
to get the value as 40 now. Let's try to understand
how I am getting this value. So 10 if I write it in binary
is going to be 1 0 1 0. So when I do the left shift, what is going to happen is it
is going to shift to values and I'm going to Get
the value as 1 0 1 0 0 0. So what is happening here? If I convert this binary number to decimal I'm going
to get the value as 40. So this is why I am getting
the value for T over here.

So this is the concept
of bitwise operators guys. I hope you are clear
with the concept of bitwise operators. It is a bit complicated because we are using
the binary numbers even though I am telling you
these binary numbers, you need not mention them while using the operators
for example for these bit. Operators all these
are written over here. Let's say if you
are using the bitwise and operator it
will set each bit to 1 if both bits are 1 as I've shown you
and then before bitwise or operator it
is going to be one if one of the bits as
one so similarly for x or it will set each bit to one. If only one of the bits is 1 and then we have
bitwise not operator which is going to
invert all the bits.

Let's say if we have all bits that is one it is going
to convert all those bits to 0. And then I have told
you about left shift and right shift as well. So this is about operators
in Python guys. Today's session will be focusing
on various Loops that are available in Python. So without any further Ado, let us move forward and have
a look at the agenda for today. So first we'll see
why to use Loops.

What is the reason
of introducing Loops in the programming world? Then we'll see
what exactly are loops and then we'll focus
on various types of Loops that are In Python namely while for and nested. I will be explaining you
all these three loops with examples after that. I'll give you a brief summary
of what are the things that we have discussed
in today's session. So let us move forward and see
why we need Loops. Now, let us understand
this with an example that is there in front
of your screen suppose. You are a software developer and you are required
to create a software module for payroll processing of all
the employees in your office.

Now what all things
you need you need. The salary of those employees
the bonus then the total amount that they will get
after the end of the month. Right? So all these things for each employee you
need to print so for each of the employees you need
to print all these three details now there are two ways
of executing this task. So let us see,
what are those two ways. So the one way is you
can actually write a logic to calculate the total salary
of each of the employees that includes all the fields
like salary bonus in total and you are going to write
that logic for all the employees that are there in our office there might be
hundreds of employees that are there in your office
you need to write the closet or you need to write the code
for all of those employees so this process is actually
pretty hectic you need to repeat the same logic
for total amount of employees are there in the office I'm just
giving you an example of three employees but what if you're have like
hundreds of employees so at that time
this particular process will not work this
will not only increase the size of the code it will
make it more complex and less efficient now another way of approaching
this task would be you write the logic to calculate
the salary you keep on iterating that logic for the total
number of employees that are there so
when this Loop runs once it will print the salary
of first employee when the loop runs for the second time it
will print the salary of the second employed similarly
it will keep on repeating so if you have a hundred
employees it will repeat four hundred times now
what advantage we get here the major advantage that we get here is we don't need to write
the logic for each employee in order to calculate
the salary In right one logic and keep on repeating it
for all the employees.

So this way the size
of the code get reduced. The length of the code
is reduced at the same time. It reduces the complexity makes
it more efficient and even increases
the speed of execution. So this is just one example in order to show you
why we need Loops. So there are hundreds
of thousands of examples that you can think
of why we need Loops, right? So this is just
one simple example that I've shown you
in order to make you understand why we need Loops. So let us Move forward and see
what exactly are Loops. Let me explain you this
with the help of the flow chart that is there in front
of your screen.

Now what our loops loops
basically allows us to execute a statement or a group
of statement multiple times. Let me explain you this
with the help of an example that is present
in front of your screen. Now over here what happens
the control comes here and check the condition. So if this condition is true, it will go on and execute
the conditional code that is here. This is nothing but the statements
that are present inside. The loop so it
will execute that.

And again, it will go back
and check the condition. So if the condition is
still true then again, it will execute
the conditional code of the statements
president side the loop and it will keep on repeating until this condition
becomes false and the moment is condition becomes false
the control will move out of the loop and it'll execute the statements
are a present after that Loop.

Now one thing to
notice here guys is that they can be two kinds
of Loops one is finite. This is actually the flow chart
for the finite loops and another can be E infinite now
in infinite Loops what happened? The condition will
never be false. So at that time the control
will never come out of the loop. So it will keep on repeating
and it will never stop that is what infinite Loops are. So basically the condition
will never be false and do that. The loop will be executed
infinite number of times.

Now, there is one more way
in order to categorize Loops that is called post-test
and pretest in postage Loops what happened the controls
will first enter the loop and then in End it will actually
check the condition. But in pretest Loops the control
will enter the loop only when the condition is true. So the condition is checked
in the beginning of the loop and pretest Loops, but in post-test Loop
the condition is checked at the end of the loop
now in Python. There are no
postage Loops present. There are only pretest Loops. So we'll focus on pretest Loops
in today's session. So we'll move forward and we'll
see various types of Loops that are present in Python. So python basically supports
three kinds of Loops one is by 4 and nested will look
at all these Loops one by one and I'll explain you
with examples as well. So first we'll have
a look at while loop. So while loop is basically used when you don't know how many
I trations are required.

So let me explain you this
with the help of the flow chart that is there in front
of your screen now over here what happens the control
will move inside the loop only when this while
condition is true and when it is true Execute
the body of the loop. And then again,
it will go back and see whether the condition is
still true or not.

If it is still true then again, it will execute the body of
the loop and we'll keep on doing that until the condition becomes false and the moment
the condition becomes false. It will come out of the loop
and executes the statements that are present after the loop. Now. This is a Syntax for
while loop first need to write while then you write
the expression or the condition.

Then you give a colon and the statements or the body
of the loop now why we use while loop Basically, I've told you earlier as
well while loop is used when you don't know how many
I durations are required. So you don't know how many times you need
to execute the statements that are present
inside your Loop. So that is the reason why we use
while Loops now, let me show you that with the help
of an example. I'll open my pycharm and I'll give you a very
basic example of using while loop and after that
I'm going to increase the complexity of the code. So first we'll see a very
small introductory example of while loop in which I'm going to print
the integer values between 0 to That won't include nine. So it will print
0 1 2 3 till 9:00, but it won't include nine. So let me open my pycharm
and show you how to do that. Now. This is my pycharm guys.

So we're here as I have told
you earlier as well. I'm going to print the integer
values between 0 to 9, but that won't include nine. So for that what I need to do is I need
to First Define a variable. Let me name it as count and I'm going to
initialize value to it. That is 0 now after that. I'm going to use the while loop
and I'll write while And then I'm going
to give a condition which says that when count
becomes greater than nine. It should come out of the loop. Alright, so now what I'm going to do is
I'm going to just type in print Let It Be number
colon comma print count, right? Now, I'm going to increment
the value of count count equal to count plus 1.

Yep. Now when I come
out of the loop, I want to print say goodbye. Yeah looks fine. Now. Let me tell you
what I have done here. I have defined a variable and I have initialize
the value zero to it. After that. I have used a while loop in which I have given
a condition that says that count should
always be less than nine because I want to print values
between 0 till lines which won't include nine. Let me tell you
that so my condition says that the loop should be executed only when the count value
is less than 9 the moment. It becomes greater than 9 than the control should come
out of the loop.

That is just
a sent General syntax. I have given a colon and then I
have written a print statement that will print the count value
and after that I have increased the value of my count
by 1 and finally when the control comes
out of the loop. I want to print goodbye. So let us see
whether it works or not. I'm going to run it and as you can see
that it works. So we have 0 1 2 3 4
5 6 7 & 8 and finally when the control went
out of the loop it has printed. Goodbye. This is just a very
A small example guys now, let me go back to my slides.

Now the example that we just saw was
a very simple example, so I'll increase
the complexity a bit and I'll give you
one more example. So let us move forward
with that so over here, what I'm trying to do is
I'm trying to code a little guessing game. All right. So what happens
in this guessing game, so there will be a random number that will be generated
between say zero to 20 and you need to Guess
that number so the but that you have guessed
is less than that random number then it will print
number is too small if you have guessed the number that is greater
than the random number then it will print
that number is too large and the moment you
get the right answer you'll exit the while loop and you have won
the game basically, so just a pretty simple example, but this is a perfect example
in order to show you why we use while loop because
if you notice here, I don't know how many
I trations are required in order to guess the correct
answer so at that time while Loop is a perfect solution
to this problem.

So without wasting any time I'll actually open
my pycharm and show you how to execute this. So this is the code here guys. Let me explain you
each and every line that is present here. Now what happens first? I need to import a module that is called random
in order to generate a random number now over here.

I've defined a variable n and I've given a value
to it that is 20 because I want the random number that is to be generated should
be between the range 0 to 20. Now I've taken one more variable
and I've named it as to be kissed and over here. It should be an integer
types of written NT and this logic will generate the
random number that I'm talking about and this will be generated
between the range 0 to 20. So how can we generate
will be generated with the help of random module
that we have imported.

So it will be n
random dot random plus 1 this will actually
generate a random number between 0 to 20. So after that what happens I have defined
one more variable guess and I have assigned a value to it or initialize
the value to it zero. All right. So now comes the while loop now in while loop I have given
a condition which says that the number
that I have guessed if it is not equal to the random number
then enter the loop now, once you enter the loop you need to input
the new number the number that you want to guess again now if that guest number
or the number that you are guessing
It's greater than 0 then again.

There will be one more
if condition which says that the number that you have guessed
is greater than the number that has been generated
or the random number that has been generated. Then print number is too large. And if the number that you have guessed
is actually smaller than the random number generated
then print number is too small. Now there's one more condition
that is else, which means that when the number that you have guessed is less
than or equal to 0 then that means you are giving up so it will break it
will come out of the loop and it will print sorry that you are giving up that's
when your game gets over and you have lost it finally if you have guessed
the correct number then it will print congratulations. You have made it. So let us go ahead and execute
this and see what happens. All right, so it asks
me for a new number.

So it has to be between 0 to 20. So, yep, I'll type
10 and let's see what happens. So it says number is too small that means it is
between 10 to 20. How about 13? All right, so I have guessed
the correct number and it says congratulations
you have made it now over here as you can see that it took only two I trations
for me in order to guess the correct number, but what if it would have
taken more iterations? I mean, I'm pretty unclear how many iterations
it will take for me. So that is the reason
why we use while loop because we don't know how many I trations
are required now we can run this program again and I
can show it to you once more.

Us a new number,
so I'll just type in say 14. It says number is too large. So I'll type in 11 again. The number is too large. That means it is
between 0 to 11. So how about eight guys
number is too small. So now now as you can see that already three
iterations have occurred and for the for titration
definitely the random number will be somewhere
between 8:00 and 11:00. So, how about 10? n So congratulations you have
made it and the control came out of the while loop and it has printed
congratulations you made it. So we'll move forward and see
for Loops in Python. So for Loop is basically
used when you know, the number of I trations
that are required and like while loop where you are. Not sure about the
number of iterations that are required in for Loop. You know, how many times the statement
that I present inside the loops need to be executed.

So for Loop provides
you with a syntax that'll include three Fields
basically or you can say three informations. So first will be
the Boolean condition then comes the initial value
of the counting variable and then the incrementation
of the counting variable. So as you can see it
from the syntax is well first you write for name
of the variable in the range. Then you specify the range
in which that variable should be or and then you
specify the range that means from which point at which point it
should be executed. So, you know, the number of iterations
required then only you use for Loop now over here as you can see from
the flow diagram itself, the control comes to this and it will see the item
from the sequence. It will execute
the statement go back again, and then from Um
the range it will pick up the next item again. It'll execute this statement
again go back and then from the range will pick
up the third item and it will keep on executing until the range becomes over or that is the last item
from the sequence. So when there are no items
in the sequence, it will go on and execute
the statements that are present after the for Loop.

So this is how for
Loop Works guys. Now, let me just give you
a very small example of how for Loop works. I'll open my pycharm again and I'll start with
a very small example, and then I'm To increase
the complexity of our code. Like I've done that in
while loop now over here. What I'm going to do is I
am going to first Define a list and I'm going to
name it as fruits. So what all fruits
you like guys, I'll first type in mango
then I like grapes. And finally, I'm going
to write and say apple. Yep. So this is my list which contains the three
fruits mango grapes and apple now I am going to
define a for Loop and over here.

What I will write I'll Define
a variable safe route for fruit in fruits. Give a colon. print current fruit
and type in fruit now when you come out
of the loop just print. Again, goodbye. So I have declared
a list and the name of that list is fruits. Now that fruits list
contains elements, which are mango grapes and apple now after that
I have defined a for Loop which says that for a variable
named fruit in fruits. So this will give
me the range fruits will give me the range
as you know, that in the fruits list. There are only three fruits
so I know it alight rate only Thrice first
for mango then for grapes, In per Apple. So this is the difference
between the violent for Loop and for loop.

I know that will take
only three iterations after that print
the current fruit. That's all and when the control moves
out of the loop print. Goodbye. It's pretty easy guys. So go on execute
this and see what happens. So you have the current fruit
first is mangoes incomes grapes, then comes apple and then
finally print goodbye. So what I'm going to do
is I'm going to increase the complexity now as I've done that in
while loop as well. So I'll show you
an example first. Let me go back to my slides. So what I'm going to do
in this example, I'm going to
calculate the factorial. Now one thing to notice here
guys again in factorial. Also, I know how many
I trations are required because if you see if I'm calculating
the factorial of 5, and I know that I need
multiplication five times first. I need to multiply 5 with 4
then 4 with 3 then 3 with 2 and then 2 with 1. So this way I require
only four iterations. So I know the number
of iterations required so it's a very good example
in order to show you where we should use.

A while loop and where we
should use for Loop. So let me go back to my pycharm
and execute this practically. So this is the code in order to
find the factorial of a number so over here what happens first? I need to input the number that I want to calculate
the factorial of after that. I've defined a
variable factorial and have initialize
the value to it, which is 1 now. I have defined a condition if the number
that I have entered is less than 0 then print
the number must be positive because I can't
calculate the factorial. Negative numbers, right? And again, I have given
one more condition which says that if number is equal to equal
to 0 then factorial is equal to 1 and then else
condition says that when number is greater than zero then I've used the
for Loop which says that for I have defined
a variable I in range 1 to num +1 when I write num +1 the range will be
between 1 to num +1, but it won't include num +1 so it will only be
including one till Numb.

Alright, so after that would have written factorial
is equal to factorial n 2. I so factorial was one earlier than it will multiply by I I
will also be 1 in the beginning and then again, it will go back and it
will become 2 similarly. It will keep on increasing
until it becomes numb. So till that time we'll keep
on executing the loop and the moment it
becomes equal to num.

It will come out of the loop and it will print
the factorial value. So let me go ahead
and execute this and show you if it works or not. So I need to enter the number. So let's say I want
to calculate the factorial of 3, which is 6 so if I want
to enter one more number, so what I can do is I
can start it once more. So what I will type I can type
again for So it prints 24 which is absolutely correct. So we'll move forward
and we'll see what are nested Loops in Python. So python basically allows
us to use a loop inside and another loop, for example, you can use a
for Loop inside a for Loop or you can use a while loop
inside a while loop and at the same time you
can use a while loop inside a for loop as well and a for Loop
inside a while loop as well. So that is basically
what is called nested Loops now, we'll have a look at the example
of nested Loops as well. Don't worry. So let us move.

What an see one example
of nested Loops now over here. What I'm going to do is I
am going to write a code in order to simulate a bank ATM. All right. So for that I am
going to use nested while loop and
what will happen first. You need to enter
the four-digit pin and then you can perform
the following functions. You can check the balance. You can make a withdrawal
you can deposit some money and you can even if you don't want to do anything
you can tell the machine to return your car as well. So let me show you
how it is done. I'll open my pycharm once more. So this is the code that I've written in order
to simulate a bank ATM. I'll explain you each and every lines
don't worry about that. So first line is nothing
but a print statement that says welcome
to iron bank of braavos ATM. All right, and then I have defined a variable restart
and I've assigned a value to it. That is why similarly chances
are assigned a value that is 3 and this
is the balance that I'm going to initialize
the array 67.1 phone notice you over here.

You won't get more
than three chances in order to write
the correct password. Now comes the while loop which says that when chances
are greater than or equal to 0 at that time. What will do you need
to enter the pin? So you need to input
the four-digit pin that you have and
if that pin is 1234, then it will print that you have entered
the correct pin now comes one more while loop which says that while restart should not be
in this particular topple. That is the value of restart
should not be n capital n o small n o or capital N, so it should not lie
within this particular sequence that is n capital N Ono and N, but we know
that the restart value is y so, it will enter
the while loop now over here what will happen it
will give you four options.

First option is in order
to check your balance for that. You need to press
one to make a withdrawal. You need to press to in order to paint some cash
or you need to deposit. Is it something you
need to press three or you want your card back? You need to press for so
these are the four options that will be given to you. So when you choose
option 1 it will print the account balance so over here
as you can see that your account balance
is and the balance that is there in your account. After that. It will ask you for restart. So you need to input that value so that will say would
you like to go back and if you restart value lies
in this particular Tuple, then it will break and it will print
a Thank you statement. But if you want to continue or you want to go back then you
can press anything else apart from small n n o
or this no or capital N. So if you press
any other button apart from these it'll actually go
back and in the while statement as you can see it says
that it is not present here.

So it'll give you all
these four options once more now after that what if you choose the another option in which you need
to make a withdrawal. So for that what will happen you
need to enter the amount that you would write to draw
which can be a float number. It cannot be an integer number. So that's why we use float here. So you need to enter that value. And once you enter that value, it will check whether it is
in this particular list or not. That is 10 20,
40 60 80 100 Now by default. It will give a restart. Why because you need to enter
the amount once more. So again, it will go back and I
will give you all four options so you can choose
that withdrawal option again, and you can choose a number which is present
in this particular list now when you choose withdrawal
equal to equal to One at that time it will again ask you please enter
the desired amount.

So this is for option two. Now when we talk about option 3, it is pretty much similar
to the couple of options that we have discussed before there is pretty much
similar to that over here again, whatever the amount is that you want to pay
in the how much of amount that you would like to pay
and balance plus the amount that you are depositing. So it will print the balance that will be equal
to balance plus the amount that you are depositing again.

It will ask you for restart if you press Anything apart
from this particular Tuple, then it will go back
to the while statement and it will give you all
these four options similarly for option for as well. Now what happens when you
enter the incorrect pin, so there's one more
condition in the end, which says that if the pin that you have entered is
not equal to 1 2 3 4 then it will print
that incorrect password and it will decrease
the chances by one. So earlier you
had three chances. If you press the incorrect pin
once it'll decrease your chance, and it will make it as to If you write the incorrect
password then again, it will make it as trans requires two chances
minus 1 which will become 1 and if the third time also
you do the same thing, then the chances will become
zero and the moment it becomes 0 then it will print no more tries break
will come out of the loop.

That's all guys. So let us go ahead and execute
this and see what happens. So, please enter
your four-digit pin. So I'll just write 1 2 3 4
and give me four options, which is one for balance
to for withdrawal. I paint for to return a card. So if I want to check
my balance and put in 1 so it has printed my balance
which is 60 by 7 point 1 4 and then the restart value
that I was talking about. It is asking for that. Let me just make it big for you. Yeah, would you like to go back? So if I press n here it
will come out of the loop and will break and if I press anything
apart from small n capital n o small n o or capital N it will actually
go back and ask gave me all the four options
that were there. So if I press y it will again
give All the four options that are there you
can see that press 1.

So again, if I want
to make a withdrawal, I will press to how much amount that I would like to withdraw
say I want to withdraw 10. So my balance has reduced
from 67.1 for 250 7.14. So would you like to go back? So I'll again press Y and it will give me
all four options. If I want to paint something that is I want to deposit
something and press three how much amount
that I would like to deposit. I'll say 10, so my balance became
again 67.1 One for again. It is asked me would
you like to go back? No, I don't want to go back
so I can type in N so, yep. So it says thank you and again asking me
for 4-Digit pin. So let me show you what happens. If I die the incorrect pin say if I write one one
one incorrect pin, if I write that pin again
again incorrect again incorrect.

So we have no more tries. It'll come out since I've exceeded the chances
that I was given. So I was given three chances
I couldn't write the I've been in those three chances. So at will come out of the loop
and it will stop so this is an example of nested while now, let me go back
to my presentation and I'll show you an example
of for loop as well.

So this is an example
of nested for Loop. So over here, what I'm going to do is
I'm going to write a code in order to print
the Pythagorean number between a particular range. So what happens is suppose if I
want to enter the number 20, that means I want
the Pythagorean numbers between 1 to 20. So Pythagorean numbers are
nothing but the integers which satisfy a square plus b square is
equal to C Square.

So at that time it will print
all the Pythagorean numbers that are possible between
one to twenty three four five. You can see the three Square
for square is equal to V Square 9 plus 16
is equal to 25 similarly. It goes for 5 2013 6 8 10 8 1579 1215 similarly
for 12 16 and 20. Don't worry guys. I'll go back to my pycharm
and I'll explain you how you can do that. So this is the example of
a nested for supposed over here. I need to import certain modules in order to use
the square root function. So from math module, I am going to import
the square root function after that last me
for the number in the example if you can remember
in the slides where I've written 20, so that's printed
the Pythagorean numbers between 1 to 20 that same
number It'll ask me and it will print
the Pythagorean numbers between 1 to n.

So whatever the number n that I'm going to put in
or given input. After that, lll run a
for Loop and it will say that for a which is a variable
in range 1 to n plus 1 that means 1 to n that means 1 to n plus 1 but don't include n
plus 1 after that. There's one more variable B, which is in the range a comma n
that will not include n it will only include till n minus 1 so the square root C Square. I've defined one more
variable C square is equal to a exponential to What a ^ 2 similarly B
raised to the power of 2. All right, and then what I'm going to do is
I'm going to calculate the square root.

And then what I'm going to do is I'm going to Define
one more variable C and it will be an integer that will be the square
root of C Square. So if that c square is
minus C square is equal to equal to 0 then print ABC. It's pretty simple logic guys. Okay, I'll explain
it once morning. So this is an example
of nested fought so over here.

What I'm going to do is
I'm going to first import the square root function
from the math module. I have to that I am going
to input a number. So if you can remember
in the slides have given it as 20 so it will print
the Pythagorean numbers between 1 to 20 over here. Also, I will print
the Pythagorean numbers between 1 to n. So whatever the value
of Nu input that will be depending upon it. So the Pythagorean numbers will
be depending upon the values that you input. So it will be printing the Pythagorean numbers present
between After that, I'll run a for Loop, which says that for a should be
in the range 1 to n plus 1 that will not include
n plus 1 guys. It'll only include n so 1 till n plus 1
but don't include n plus 1 After that, I've defined
one more for Loop which says that for be in range a comma n it won't include n
it will be tell only n minus 1.

I've defined one
more variable here, which is equal to C underscore
square that is equal to a square plus b square. Now after that have defined
one more variable C and this will be actually
the integer of the square root of the C underscore Square. All right, so whatever value
that you will get here. Square root of that value will
be converted to an integer value and will be assigned
to see now one. If condition I will be
using here which says that if C underscore Square minus C square is equal
to equal to 0 then print ABC that means that will be
a Pythagorean number. So this is a pretty
simple logic guys. Alright, so I hope you
have understood the coda explain to you here now. Let us go ahead and execute
this and see what happens.

Yeah. So the first number that I'm going to type
in say five iron will give me all the Pythagorean numbers
present between 1 to 5. So we have only
one Pythagorean number that is 3 4 5 in that range now. Let's execute this once more
and I'll type in 10 here. So we have to Pythagoras number. There are three four five
and six eight ten similarly. If I execute it, once more and a type
in a big numbers say 25. Yeah, we have these many. Bye to Grandpa numbers between 1 to 20 fights
will again go back to our slides and we'll have a look
at one more example.

Now in this example, I'll actually be using a
for Loop inside a while loop. So what is this example, I want the bulk reservation
of train tickets. So I have like group of people
who are traveling somewhere and I want to give their details
such as name age and sex I want that to happen in bulk. I don't want to give
it one by one. I just want it
to happen in bulk. So for that what I am going
to use is I'm going to use a for Loop inside a while as I told you earlier is where you can even use
a while loop inside a for Loop. But for now, I'll use a for Loop inside a
while loop and see what happens. So let me go back to my pycharm. So this is the code in which
I will be using a for Loop inside a while loop
the first I have defined a variable traveling so
in which you need to input whether yes or no, so if you are traveling
you'll say yes, obviously and then we'll have
a while loop which says that while the condition is
traveling equal to equal to yes.

That means if you're
willing to travel enter the number of people who are traveling so you need to
enter the number of passengers that are traveling and that will be assigned
to a variable num now they'll be a
for Loop which says that for Num
in range 1 to num +1 but it won't include num +1 enter the name
and age and finally whether the person is male or a female and then
print all those values now one more thing here
is again it will ask you whether you have missed someone
or not so you need to input that whoops forgot someone so
at that time you can write in yes if you
have forgotten someone that again it'll execute
the loop again It'll ask you the number of people traveling
in all these details if you ripen anything
apart from yes that means you have
not forgotten anyone and it will come out of the loop so it is a very small example but a very good example
to understand how for Loop can be used
inside the while loop so let me go ahead
and execute this whether you're traveling I
would say yes I am traveling number People traveling I would say three name is
sort of Ages 78 male.

Alright. So again, it is ask me
for one more name. So I will say Neil. Age is 90. male or female Male, yep, so one more name
I need to type in say I would type in Java tea. AJ is 98 Male
female female and Yap. It will print all
those details for me. So now it is asking
have you forgotten someone so if I type in and say yes, then it will again Ask me
the number of people traveling that means it is again
executing the while loop. So if I would say the number
of people traveling is one and I would type
in the name of the person that was traveling so I would just say
Siddharth whose age is 77 and he's a male.

Yep, again, it has asked me. So if I type in anything
apart from yes say if I type n so, yep,
it'll come out of the loop. And this is how you can actually use a
for Loop inside a while loop. So let me just open my slides. And yeah, so this was
an example of a for Loop inside a while loop. So let us move forward and I'll give you
a brief summary of what all things we
have discussed till now. First we saw why we need Loops. We actually use the example
of software module for payroll processing in which
I showed you two methods. The one is manual and the another one
in which you are using Loops after I told you
what exactly are loops and we saw various types
of Loops in Python namely while for and nested then we focus on each of these Loops we started with
while loop and I explain to you where to use by loop I gave you two examples of while loop similarly
for for loop I explain what is that least
four Loop how it works.

It's Tags and two examples
again perform a loop when you talk about
nested Loops again. I've explained you the syntax how to use it and I've given you
three examples for nested Loop is well, let's take a look
at the agenda for this session. First of all, I will start with
star pattern programs and the patterns include
pyramid half pyramid are glass dementia patterns
Etc moving further. I will discuss pattern
program with numbers. So instead of asterisk will
be Using the numerical values in the patterns and finally I will explain a few
pattern programs with characters or alphabets in them.

I hope you are clear
with the agenda. Also, don't forget
to subscribe to a director for more exciting tutorials and press the Bell icon to get
the latest updates from Eddie. Wake up. Now without wasting
any more time. Let's take a look
at the star pattern programs that I will explain
in this session. So I'm going to start with star pattern programs
in which I'm going to show you how you can play
with the concept and make other patterns
like half pyramid triangle. Glass bad didn't diamond pattern and inverted pyramid
patterns as well. So let's take it up
to jupyter notebook and I'll show you how you
can make Star pattern programs and we are going to start with the simple
pyramid program first. So now we are
in the jupyter notebook guys. I'm going to start
with the simple pyramid program. So I'll write pyramid over here. And in this I'm going
to take one function and I will name it as
pattern inside this I'm going to pass n because this is going
to be our number of lines which I want in the pattern
and for blank Cases, I'm going to take one variable.

That is K. I'll show you what it does and we're going to use a lot
of for Loops inside this so if you're not familiar
with loops in Python, I suggest you to check
out other tutorials on a deal breaker
for Loops in Python so that you will be able
to understand this better. And I'm going to take one
for Loop here for I in. This is going to be the loop
for our outer rows. So I'm going to take
this as range 0 to n and I'm going to take
one more Loop, which is for J in range. And this is going to be
our Loop four columns. And I'm going to take
this as K over here. Now. I'm going to print
some blank spaces over here. So for this I'm going
to write this and is equal to and after this I have
to decrement the value of K, and I'm going to take Take
one more for Loop inside this I'm going to specify
the range 0 to I plus 1.

Because you're going to move
in the forward Direction while printing the pattern
that we have. So inside this I'm going
to print the Aztecs pattern which is the star pattern also. And end is equal to this now
one more important point you have to print backslash or backslash n in order
to get the pattern right? I'll show you what happens. If you don't do that now, we're done with the pattern
function over here. I'll just call pattern and inside the red specify 5
and when I run this, I'm getting a pattern
which is a pyramid.

Pardon. So instead of backslash n
if I write backslash R, the pattern will look
something like this and if I just comment
this statement lists, Get the output that varies. So we're getting the output
somewhat like this. If you want to get your pattern, right you're going to have
to write it like this. And this is how you
can make a simple pyramid pattern program in Python. So you can see this. This is the variable
that I was talking about to specify the spaces. So what if I write it as let's say n minus 2
the output will move to the left side and if I write it as n Look at this. So this is what happens when you play with
the space over here. So I'll just write it
as 2 into n minus 2, so we are getting the pattern
somewhat like this. So instead of 5
if I write 10 over here. I'll be getting a much
more bigger pattern with a pyramid shape. And this is how we can write
a simple pyramid pattern. So let's take a look
at the next program that we have which is
the inverse pyramid.

So by now, I think you have got the idea
of how we are doing this so for printing
the inverse pyramid, you're going to go
from Back to the starting. So we'll start with this one
first and we'll go in the backward Direction. So that will get one in the end. So we will get
the inverse pyramid then so let's take a look at
how we're going to do that.

I'll just take a function
like I have done before and inside this I'm going
to specify the space as well, which is 2 into n minus 2. And I'm going
to take a for Loop. So for I in range this is
where the magic happens guys. You have to specify an over here because we're going
the backward Direction and minus one and we'll take
the step as minus one as well. And if you're not familiar
with the range functions, please do check out the other tutorials on a diwaker
for better understanding guys. We have a full video
on Range function as well and I'll take another
for Loop for columns as well. So in this I am going to go
with the back our direction as well step is going
to be minus one. And now I have to print
and is equal to this now. I have to specify our increment
in the K variable because we're going
the backward Direction.

I'm going to take one
more for Loop and for J in rain this time, you're going to go
with the normal flow, which is I plus 1 And in this I'm going
to print my asterisk. And after this I have
to just print the backslash R so that my output
will not be distorted and it will print
of perfect pattern. So when I call
my function pattern over here and let's
just say I write it as 10. Okay. I have an invalid
syntax over here. Sorry guys, we're getting
an inverse pattern right here. So in this you can see
the output is towards right? So what I'll do is
I'll just remove this and you will see the output is
just like the other one the pyramid and we are getting
the Most pyramid right now.

So the approach that I followed was I
was starting from the end which I got over here and I got back to the backward
Direction and in the end I'm getting the one stop. So this is how you write
a simple program for inverse pyramid. Let's take a look
at the next pattern that we have
which is all right, start patent program. So we are going to follow
the same approach right here. Let me just write
right start button. So in this I am going
to follow the same protocol. I will specify
a function pattern inside the cell specify n and now what I'll do is
I'll just write for I in range. 0 to n for J in range 0 + I + 1 that we have written
before as well. Now, what I'll do is I
will print my asterisk can any of you guess
right now which I had and I'm going to make
because I'm not sure if everybody is familiar with
the pattern right start pattern.

It's going to be looking
like a triangle but mention in the comments if you had guessed right and specify one more
outer rows function because we're going
to get failure. Unique pattern in there. So we need to Outer Loops for Rose and two outer Loops
for columns as well. So I in range. I'm going to specify the range
as n 0 and minus 1 the step is going to be minus one. And inside this I'm going
to specify for J in the range 0 and we're going to follow
the same approach. That is I plus 1 after this. I'm going to
print asterisk again. And is equal to this. Trent backslash R. Don't forget the
backslash R guys. So if you have any problems
in your pattern just look at the print statement where you
have specified backslash R.

Now when I call
my function pattern over here, I'll specify tan again. Okay, I'm getting the pattern
somewhat like this. OK we are not getting the output
as I had expected. So I'll just do one thing
instead of 0 over here. I'll specify minus 1 so
when I run it again, I'm getting the perfect
right start baton. So this is how you write
a program for a ride. Start pattern in Python
and let's take a look at the next program that we have
which is a left start pattern. So for this I'm going to take
pattern again specify an and after this I am going
to take one variable for spaces because we are going
towards the left side.

So what I'll do is
I'll just write K is equal to 2 into n minus 2. And again, I will take
a loop for outer rows and sizes will specify
the range as 0 and N minus 1. For the columns. I will take for J in range 0 to
K. Trent end is equal to this because we want
some blank spaces over there and I will determine the value
of K by K minus 2. You can modify
these values for K and all these range functions as
well according to your pattern whichever pattern you're making
do experiment with these values so that you will understand
how it's working.

So I'll take one more for Loop
for columns again. So J in range this time. The range is going to be 0 and I plus 1 and can any
of you guess right. Now. I'm going to print
the asterisks over here, which is going to be
in my pattern again. This is going to be
n is equal to this and oh, Here,
I need to print backslash R.

So that my output
will not look distorted. And again, I have to get
the value of K. Right. So I'll write K is equal to K minus one. Now I have to take one more. I would to look for outer rows. So for I in range just like we
did in the other program. Okay, I'll show you why we are
taking two different outer rows. So I'm printing a half
pyramid until here and after this I'm going in the
backward Direction like this. So instead of doing
this I am going to print some blank spaces as well. So I'll be printing
back spaces until here and then my actual
program will start. So this is why I'm taking
two Loops over here. So just specify N minus 1 minus 1 and minus 1
for the step as well. And after this I'm going to take
one more Loop for columns.

And inside this I
will specify a minus one and step as minus one as well. I'm going to print
and is equal to spaces. The commitment value
or increment the value because we are going to go
in the backward Direction in this Loop and again for J in range 0 I plus 1 and after this
I'm going to print asterisk. And is equal to this
and print backslash are. I mean I call
my pattern again say 10. Okay, I have invalid Syntax
for J in range. Okay, I think I have made
a mistake over here. So I'll just check
my coat again. Okay, I'll make
this as minus one and move it a little further. So I'm getting
my pattern right there, which is a left start pattern. So this is how you can write a program for
left start pattern in Python. And now let's take a look
at the next program that we have which is
our last pattern program.

So for our class pattern
I'm going to print. pyramid pattern and on top
of that I'm going to print or inverse permit so that it will look
like an hourglass so let's take a look at
how I'm going to write that so I will take one pattern
function again specify n and I'll just go
with the variables for spaces and then for auto Rose
I have a loop in which I am taking the range
as n minus 1 and step is minus one as well okay
I made a syntax error and now four columns
for J in range I'm going to take the range
as K 0 and minus 1 okay we'll do one thing
guys I know for sure that we need an inverse pyramid so I'll just take
this code copy this and over here I'll just
print this code so when I call pattern now say five I'm getting an inverse
pyramid so now I'm going to take the code
for Pyramid pattern over here and I'm going to paste this
after this this goes here so this is my art class
pattern guys I'll give you how a little distorted our glass so in our inverse pyramid
beginning the six rows and in this very minute we
are getting only five rows so what I'm going to do is
I'll just specify this as 0 and N minus 1 let's see
what happens so I'm going to take it as n plus 1 so now we're getting
a perfect hourglass pattern and this is how you
can write our glass pattern in Python guys all you
have to do is Understand how it works.

And after that you can just
play with the numbers and the spaces and you
can make any pattern that you want. So now that we are done
with our last pattern. Let's take a look
at a half pyramid pattern that we have in Python. So it's very easy guys. I'll just take one pattern
function specify an over here. And in this I am going
to just write for I in range whatever number
that you want. So I'll just write 0 n and for J in range The range is going
to be 0 and I plus 1 and I'm just going to print
my number over here. and inside this my asterisk
and is equal to this and again, I have to specify
a backslash or Now when I call my pattern function
Spanish attend give you have a syntax error again, I'm sorry guys, and this is
my half pyramid pattern or we can call it a right
triangle pattern as well.

So this is how you can make
a half pyramid pattern in Python guys. So let me show you how you can make
a left pyramid pattern so that you have to just
add a simple code in which you have to specify the spaces like we have done
in the other programs also, so I'll just copy
the whole code. They stood over here
and four spaces. Okay, I'll have to take
a variable k 4 spaces and inside this I'm just
going to specify 2 N minus 2 and after this I will have
to take one more outros do and inside this. I'm going to take the range as it's going to go
in the direction 0 to n and for J in range now, this is where K comes into picture and I'm just going
to print the spaces that I want.

I think we're done. I have to determine
the value of K as well. So when I call my pattern now. Just say Phi if you're getting
a different value here. I think I made a mistake guys. Let me check the code again. Okay, I think I've got
the error guys. So let me just comment
this line and see if our output changes at all. It doesn't. And this one as well, so now we're getting
the left half plane with pattern guys.

So I had made him silly mistake. So I was taking two Loops
for outer rows instead. I just have to take one. So let me just make
it as then so that it will be better looking. So this is how you can make
a left half pyramid pattern in Python guys. Now, let's take a look
at the next program, which is a
downward half pyramid. So we're going to go
from this line to that line in a reverse order. So that will get
a downward half pyramid. So we follow the same thing. We will take a function
specify any over here. And now what I'll do
is I'll write for I in range range is going
to be downward Direction. So it's going to be minus 1 and minus 1 again
and for J in range.

This is going to be the same I plus 1 Since you're not getting
any left pattern, we just going to print
the Aztecs over here. And is equal to this. Bring back slash are now
when I call my pattern function. Let's see what I don't know. I'm getting over here. I'm getting a downward half
permit pattern like this. And if you want to make it
a left downward pyramid pattern, you just have to follow
this approach in which you have to specify
a range and get this variable K and decrement the value
and you will get the same output as you're getting over here. Now, let's take a look at the
next topic or the next program, which is diamond pattern. Diamond pattern in
Python for this. I'm just going to
take pattern again. And after this I'll specify
the spaces to into n minus 2 again for I in range I'm going
to take the range as 0 to n.

And again, I'm going
to take the columns which is going to be
in the range 0 to K. I'm going to print the spaces. And after this decrement
the value of K. Now again, I will take one more
blue four columns, which is going to be
in the range 0 and I plus 1 and I'm going to print
asterisk again for my pattern. And is equal to this and after this I'm just going
to print the backslash are now. Let me just call
my pattern function and see what happens over here. I'm getting the pattern like this to make it
a diamond-shaped pattern. I'll have to make inverse permit
on the downward Direction so that it will look like diamond. So I'll take one more
for Loop for that.

I have to specify
the K value again. So for this I'm going
to take n minus 2 because if I take 2 and minus 2 it will look
a little started. I'll show you that as well. So I'll take the for Loop
for I in range now. We doing the diamond
downward Direction, so it will be n
minus 1 and step. Nu minus 1 as well and for J in range it's going
to be K 0 and step is going to be minus one now
in this I am going to print and is equal to this bring
the backslash r for J in range is going to be 0 and I plus 1 again I will print
my asterisk value over here and is equal to this print
backslash are so now that we're done with
the functional just print this.

Okay. We are getting
a very distorted image. I'll take a look at what we
are doing wrong over here. Okay, we have this one. So for this I have to specify
K is equal to K plus 1 and as you can see we are getting
the diamond-shaped pattern over here and let me show you if I take the value of K as 2
into n minus 1 or n minus 2 the pattern looks somewhat
like this to make it better. I have to make it as
2N + -2 should be gone. I'll have to make a few changes
over here to make it a line to the downward pattern. So what I'll do is
I'll just remove two over here and it will look like a diamond-shaped
pattern right now. So now that we're done
with this one.

Also, I will show you
a diamond star pattern. So there is a different approach
to this a diamond pattern that I'm going to
show you right now. So first, I'll write the code
and then I'll explain how I have made this. So for I in range going to specify the range has
five and for J in range, it's going to be five as well.

Now. What I'll do is
if I plus j or or i – J is equal to 2 or I
plus J is equal to 6 or Jay. – I is equal to 2 so
this is my condition is I have put it all in the if statement I am going
to print my asterisk and and is equal
to this else print and is equal to this I think
I made a mistake over here let me just take a look
at the code again so when I print this I'm going
to get the value as this so this is a star
diamond star button so what I've done here is you have
to look at the picture over here so if you take a look at the rows and columns
is going to be 0 1 2 and 3 and you have to you know
identify the pattern in which you can make a statement like this so for all
these values I'm printing this one so wherever we have a as tricks over here it's going to satisfy
This statement over here only then it's going
to print this value. So this is how you can make
a diamond star pattern in Python guys.

So now that we're done
with the star pattern programs. Let's take a look
at the number pad in program. So instead of asterisk, we will have a numerical value
in the patterns and we will start with
some simple numbers program. I'm just going
to take one function that is pattern. And again, I'll just write for I in range the range
is going to be 0 to n and after this I
will have a variable but before that I have
to specify it over here. So let's say x is equal to 0 and inside this I'm going
to increment this x by 1 now comes my program guys. So four columns for J in range. I'm going to get the value. Was zero and I plus 1 just like before and
inside this instead of a stress. I'm going to print X.
And is equal to this.

Or because we don't have
spaces over here. I'll just write space now. I'll have to specify
backslash R statement. And take okay. We'll just call
our function over here. So we're getting patents
for more like this. I'll just make it
as let's say seven. So we're getting
the pattern with numbers which is 1 then there is 2 2 then this 3 4 5 6
and on till 7:00. This is a very simple
pattern for numbers. Let's take a look at a Pascal's
triangle pattern guys. So I'm sure most of you are familiar
with Pascal's triangle. So I'll just write the code
for Pascal's triangle and inside the specify n again. I'll have to take for
I in range 0 to n. For J in range 0 I plus 1 and inside this I'm going
to print my function. Which is I and J comma this and end is equal to this. And after this I'll just print now I have to take
one more function guys.

So my function is function
and inside this I have n and K. So my result is equal
to 1 this is the logic for Pascal's triangle guys. So I have made the function
for my pattern now. I'm just writing the code. For Pascal's triangle logic. So if K is greater than n minus
k k is equal to n minus k 4i in range 0 to K Result
is equal to result into n minus. I and so does equal
to zero flow division. I plus 1 it's John result now when I call my pattern function specify not 10 let's say 7 so
this is my Pascal's triangle guy so basically what happens
in a Pascal's triangle if you take a look
at this one so some of these two numbers
is going to be over here and similarly for later purposes
some of these two numbers is going to be here
and these two numbers here so this is how the Pascal's
triangle will go on and for let's say 10 it
will look something like this and what's your 20 look
something like this so this is how you can make
a Pascal's triangle pattern in Python guys so very
simple pattern I've given you the logic also to get
the third summation over here in this position so this is how you can make a pattern
for Pascal's triangle in Python let's take a look at a half pyramid pattern
with numbers guy so I just showed you a half pyramid pattern
guys it's right here so I'll just copy this code
again paste it over here so getting When I call
my pattern function, let's say 10.

I'm getting a half pyramid. So what I'll do is I'll just
write X is equal to let's say 0 and after this I'll just
mention X is equal to X Plus 1 and instead of asterisk. I'll print X space over here and we're getting the values
as 1 2 2 3 3 3 4 4 4 like that but instead of that we
can also make a diamond pattern with numbers as well. So we'll just copy
the code again. With this one. Okay. I'll just show you
over here only. So instead of asterisk. I'm going to print X
and I'll specify X over here x is equal to 0
and here x is equal to X Plus 1 same here.

I'll have 2X is equal to 0. X is equal to X Plus 1 Okay, we made a mistake guys. and we have to change X
over here as well give it a space you not do this for 10 let's say do it
for 7 and this is how you get a diamond pattern
with numbers guys so you just have to change the
values inside all these patterns that I've shown you and you
can play around with numbers and make different patterns
as well now let me show you one more program with numbers
so I'm going to show you how you can make
or descending order patterns so it's very easy guys and just make one function
with same approach and for I in Range, I'm going to take
the range as n 0 and minus 1 and again
for J in range 1 and I'm going to take
1 I plus 1 again. I'm going to print Jay.

And end it with space. print backslash or Call
my pattern function specify 5 over here
and you can look at this. We're getting the
descending order pattern. So first of all,
we have five numbers. Then we have four then
we have three two, and one similarly we can do is for 10 as well for
any amount of numbers. You can make it this as
a descending order pattern, which is also a downward
half pyramid pattern as well. So now that we're done
with this one. Let's take a look at and binary number pattern program guys
out of all these numbers.

We are just going
to use 0 and 1. So what I'll do
is I'll take one. action pattern and inside this
I'll take the range as for I in range 0 to n. Okay, I forgot to take
that variable K is equal to 2 into n minus
2 after this for Jay. In range it's going
to be 0 to K. And after this I'll print
this blank spaces. Is equal to this K
is equal to K minus 1. 4J in range 0 + I + 1 I'm going to print one and zero. So instead of a stress,
I've just written one and zero, so it's going to print out
a binary number program. So basically what happens
over here is we just getting the output as 0 and 1. So you can use
any characters instead of 0 and 1 you can use two and three and you can use just 2 or 4
or 5 or any other number that you want and we're getting
the value somewhat like this. So this is a pyramid pattern. We just binary number
that is 0-1 and this is how you can make
number patterns in Python.

And now that we are done
with number pattern programs. Let's take a look
at character pattern programs instead of numerical values. We will have a character value
inside the program and there is a little
more changed you can all just to mention it. Some variable or just like
that you have to make sure that you're changing
it to integer value the character number. So first of all, let me show you the pattern
for right alphabetical triangle. So what I'll do is
I'll take function name in that pattern taken over here. So I'll take
the variable X as 65 now because 65 is the as Sky value
for a so for I in range 0 to n And I'm going to take
one more variable CH and I'm going to change this x into the character variable
now X is equal to X Plus 1.

It's easy for me now
for and J in range 0 I plus 1 I can just print ch. Call pattern program. Okay, let's just name it as 10. We have an invalid
syntax over here. So this is
how I'm getting my pattern, so it's starting from a
and going until J. Because I have specified
then over here. Let's say I wanted as 25. So we're going until why
and if I do it like 26, we're getting the whole
alphabetical pattern with a to z in a triangle pattern. So this is a very
simple example guys, so I'm going to show you a character pyramid
program as well.

So I'll take this same approach
specify a function pattern and over here. And inside this
I'll take the value of 2 N minus 1 or n minus 2 for I in range 0 to n we
have forgot to take the eggs now we're here for J in range 0 to K print the blank
space decrement the value for K and for J in range
0 + I + 1 Now comes the CH or character variable in which I'm going to change
the X into character.

And now I'm going to print CH and is equal to this
and X Plus is equal to 1 because we have not done
that after this. I'll just print
my backslash R again. Now when I call
my pattern function, let's see what I'm getting. So we're getting
somewhat like this. Okay, so instead of 10,
let's just take seven. So we're getting a b c d e f
and this is how we are going.

The values over here, so I have changed
a little over here. So I was incrementing the value
of x on the outer rows, but now I have incremented the
value in the columns as well. So we're getting
a BC bef like that. Otherwise, we will be getting
like a BB CC c b and so on so this is a simple change
that I've done in this program so that you will
be understanding better. So let's take a look
at the next pattern that we have which is
a case shape character program. So I'm going to print the
pattern in the shape of okay. Using the asterisk again. So I've shown you
that diamond star pattern in which I have
taken if statement. So if that
statement is satisfied, it's going to print
or k shape pattern which is going to look
like okay shape with Aztecs in them. So I'll just write
the code for this.

So for I in range, let's see 7 and 4 J
in range 7 again. So this is where the court
begins and I'm going to specify if J is equal to 0 or i – J is equal to 3 or I
plus J is equal to 3 again. I'm going to print. Asterisk, Orange
Grove asterisks. I'm just going
to print a over here and and is equal to this else.

I'm going to print. And is equal to this. and now print so we're getting
the value of Summer like this. So this character actually looks
like case shaped character. So instead of a I'll just
write as just again so that you'll be
understanding better. So this looks like a cake shaped
character program using Python. And this is how you can make a cake shaped
character program in Python. So let's take a look
at one more pattern here, which is a
triangle pattern program. So I'll just specify a function
again specify an over here take K is equal to 2 into n minus. Two again X is equal
to 65 for I in range 0 to 1. And CH is equal to character
X. X plus zero is equal to one. Now for J in range 0 to K.

I am going to print
blank spaces and for J in range 0 to I plus 1 I
am going to print CH and N is equal to this
print backslash or And when I call
my pattern function, I'm getting the value like this. So this is how I make
a simple triangle pattern. So let's take a look
at the last pattern that I have in the session which is a diamond-shaped
pattern with characters. So we just copy this code again
in this is my diamond pattern. So I'll just copy
this whole code. And over here, I'll just paste this
when I run this. I'm getting the pattern
somewhat like this. So instead of numbers. I want characters. So what I'll do is I
already have X over here. So I will mention X
as 65 and over here. I'll take CH is equal
to character X and instead of X will write CH. Let's see how
the pattern unfolds.

So we're going to follow the same approach
over here as well. So X is going to be 65 and we have ch is equal
to character X and instead of X will write CH now
in my print my pattern so I'm going to take
this to another level. So I'll just write 15. So this is my diamond shaped
pattern using characters guys. Let me quickly walk you
through the agenda for the session. We'll Begin by quickly
understanding why we need file handling later. We'll move on to understanding
the types of files and guys. This is very interesting next. I'll walk you through all
of the concepts of how files are handle using
python will be making use of the code first
approach to ensure that we understand code at every point of time will end
this session by checking out how Eddie Rekha is helping
Learners across the globe so we can make sure you can
get started as soon as possible.

And make your learning fun. So let's begin by quickly
walking you guys through why we require file handling. Well guys think
about this situation. You have a server running and you need to give
access to someone who needs to access
it remotely right or basically you need
to walk with these files in general and say you need
you need to have some import into your program where you're actually
configure an input for it. Well, if I had to
answer this personally, how would I go about it? I would be using files for a lot of my deep learning models
to import my data sets into the program
at all the time. So basically by doing
this I'll be making use of files a lot. So coming back
to the basics again. How can we in put something into python the standard input
the usual keyboard input right so you can key
in anything you want. Well, there's another
case as well.

Maybe even command
line arguments to input some parameters into
the code, correct? But what if you had to read lots
and lots of data, which is not practical
to type in at every point of time or even that it doesn't make sense at
all to type it all the time. The easiest way out of this
here is to actually store whatever input
you want in one place and keep using it as
long as your requirement is met so what's the answer
the answers files guys.

So guys this concept
is actually very easy. I'm sure everyone who's joined will take away
some really interesting stuff about python that you
can practically use. Working with fights basically opens another
door among thousands and each door with python
opens up to n number of opportunities again. So now that we're good with this and we started off
on a really high roll. Let's keep it going next. We'll be taking a look
at some of the types of files available in Python. So we have images we have audio we have video we have
text we have script and so much more right there is a key difference here. I want you guys
to note check this out. Windows supports all
of these files that I told and more well watch
Ali unlimited to be honest.

But again, I won't get
ahead of myself here because there are
limitations here as well. Now check out python. There are two types
of files binary and text. So whatever is not text
is binary as simple as that. So either a file
gets to be a binary which contains obviously zeros and ones or it can have
A literal text well takes as in strings or anything while it for that matter. Picks fights are structured
as a sequence of lines where each line includes
a sequence of characters. And this is what we call
as code or syntax. Right and every line is terminated with
a special character what we call as the EOL. What is the EOL guys? It's the end of line character
a binary file is any type of file which is not a text file as I mentioned and because of
their nature binary files can only be buy an application that knows and understands
this file system structure. In other words, they must be applications
that can read and interpret binary, right? And now that we know what
are the types of files are so we can start
looking into more of this guy's formally speaking.

I think it can be Consolidated as the operations performed
on a file, right? So what all can we do? Check this out? It's called as
the crud operations. What is crowd well create
read update and delete Guys. These are the operations
which can be done with files. Will again there are
many Operations as well such as copying a file
changing the properties of a file or anything, but for Simplicity sake
I have planned to keep this session really easy
for all of the audience. So let us dive into python now. So let us quickly see how we can go about understanding
the file handling capabilities of python check out
this flow diagram to give you a quick picture of
what needs to be done first. We create a file and later. We open that file. We work on the file. Well walking on it
is basically reading or writing or anything for that matter
and lastly we close the file when we are done using it.

Coming to python now creation of a file can be done
manually by the user or through python for now. Let us consider that we will do it manually
by going into the location and creating a file say like a text file later
in this session. I'll show you how easy it is to make
python create the file for us. So make sure you stay
tuned till the end. So now we concentrate on how we can open a file
with python guys. It is very simple. So we have an inbuilt function
called as the open function which is used
for this exact purpose. The open function
takes in two parameters as seen here one is the filename and other is the mode
and this on your screen is the syntax
for the open function. So what do the two parameters
mean one is the file name that you want to open? It can be anything
at this point of time, right? So it has to contain the extension of
the file type as well. So this is compulsory
and important.

So make sure you keep this
in your mind and second. We have the mode we know
this means something that has to do with opening
the file, right? So check the check the screen. So basically these are various
modes available to open a file. We can open it in the read mode
the right mode the append more and even the create mode as
well pretty straightforward, but do note that the default mode is always
the read mode and guys know that you can open a file
in read mode only if it exists as well. If you try to read a file
or something that doesn't exist. Then python will greet you
with a beautiful error message and in addition
if you want to specify if the file Should be handled as a binary or text mode then along
with the mode as well. We can actually push
into categories for it.

Check this out. So we have t for text
and be for binary T is the default value
and B is for binary modes so we can have something as WT. So what does it mean
so it basically says that the file needs to be opened
in the right mode and the file that the python opening
is a text file. So we're basically making
the job of Been to be really easy in this case. So check out the example code
I have here for you guys. Even if we do not give a mode as I said the default
is the read mode. So these two tiny Snippets
I have for you are one and the same and yet make sure
something exists before reading that guy's or else
you're sure to hit that error. So check this out, right? So F equal to open and the file name is
demo file dot txt. I don't have a more here. This is exactly equal
to having the read more in the next example.

And it is as simple
and straightforward as that. So now we know how we can actually create
a file and open it. Right? So let's begin walking on it. Let us start with creating on how we can actually do
a read operation using python. So the read operation
is very easy guys. So basically just like
all the other functions and handling files in Python. We make use of the read function
for this very purpose. But then again, there are so many ways
to read a file to so let me so let me break
it down for you. All right, so we can do
many things here. We can read an entire file
or read a few characters or need a few lines or any number of characters
and lines together and so on check out
this Sample code here. So we have a variable right we call it file and then
we are opening the file. It's called text file Dot txt
and opening it in the read mode.

Later, we are actually
going to make use of the print function to read
the contents of the file and print the same
on the python console. Now similar to the previous code that I just showed
you we have something slightly different here. Can you notice
that five on your screen? What do you think
the five indicates your guys? Let me help you out. So basically tells
the python interpreter to read the first five characters
from the file and nothing else. Now check the old syntax. So here we don't have the five.

So we are basically telling
The Interpreter to read every single valid character
present in our file and print it out for us. So you got a good picture
of what is happening with the file now. Well, let's quickly take a tour
in to seeing this practically. So I'll open up my pycharm now, which I use as the IDE
to work with python where I'll show you the code
for all of these guys, you can basically make
use of any IDs That you're comfortable with
and even the console as well. It is your call. I am comfortable
working with pycharm. So I'll go ahead with that. So let me quickly open
up the IDE and we can see the basic code to read the file. So as you can check out
I'm here in my pycharm right now importing. The OS module is the first line This currently
being unused right now, but I'm going to talk about this
in the future session. So basically we
are opening a file, right so we have
a variable file. We're going to open it
and we providing the entire path to the file present.

So here the file is
demo file dot txt. This is the name of the file W
is the right mode that I already told you about. Let me quickly go
ahead and run this. That ran fine, but you cannot see anything
on the output right? That is because we just
opened it over out everything that is present in the file
and we just close it. So we not seeing absolutely
anything here check out example to importing the OS module file
equal to open again.

We are providing the same file
here we had right board and now we are having
the read mode and here we're actually printing it
using the file dot read again. I will be walking you through
file dot read in a second, but right now all you need
to Is this will print the output on the screen for us if I go ahead and actually run it nothing
is going to be printed. Why do you think this happened? This happened because we actually
use the right mode and we actually blanked out
the entire file Quick Fix is to actually open the file as you can see nothing
is present there. So, let me type in something. So we love Ed Eureka. Let me save that quickly minimize
it go back to my pycharm.

Now as soon as I run this
it is supposed to give me that exact output, which says we love
Ed Eureka perfect, right? So with absolutely
three to two lines of code, you can actually print something
on your screen how simple is this guy's Let's check
out the next case. So again, it's the same
thing opening the file using the read mode and then you're printing
file dot read of Five Guys file dot read of five. Right? So I actually
explained this to you. So let me just go
ahead and run it. We'll check the output. We got the first five
characterized UWE a blank space L&O. Let us try to make
it more a nice to look at. Let me just quickly
open up the file. Hello world. This is a perfect candidate
for our example. Yep, the quicktype. Oh save it exit back
into the code. Now if I'm going to run
this old code, right? So you're going to get
the entire output here.

Check it out. Hello world. Perfect because we
have read of blank now. We're going to
actually run this. Because we're telling
The Interpreter to read only the first five characters
of the first line for us. It is just printing hello
how simple is this guy's so now that we are actually
done with this. Let's quickly jump back to the presentation
to see what's next. Well guys next I want you guys
to check out the syntax, right? So this is what I love
about python amazing readability and you can almost guess what it means and you can be certain
of its in 90% of the time.

So we saw how to
read characters now, let us look at
how we can read lines. Well read line will actually
read each of the lines and give us a line
by line output read line of three will tell the python interpreter
to read only the 3rd lesson. And absolutely nothing else, but what if you wanted to return
every line in the file, which is properly separated
and nice to look at. Well, you can actually
use the same function only in a new form. This is called as file dot
read lines function again, let's take a quick jump
back into the core so we can see this in action. So check out example
for on your screen. I have the same file
demo file or text. I'm opening it in the read more
and I'm using read line soon as I go ahead and run this
I will have the same output as hello world.

Okay, let us step it
up a little let me just change this hello world. We love python. and we love At Eureka
so I have three lines. You're all good. Right? So I'm going
to save it close it. I'm going to come back here. I'm going to run the read line. Again, reading only
the first line cool check out example five. Now. This is where things get
interesting import again. It's all the same guys. So basically instead of the read line I
have read lines over here. So the S is extra it's going to
read all of these lines angle.

It is going to put it
in a really beautiful way for us to see check this out. Hello world is an entity we
love python is an entity We Love Ed Eureka
is another entity. That's nice to look at right
so instead of just getting a gibberish output of everything
in the line separating. It actually makes
a lot of sense. So now that we're done
with this another quick hop back to our presentation. So guys. Next we need to check
out our tiny concept on how we can actually Loop
over a file object. Well, this is
another simple concept. So let me teach you this. We using the for Loop
for this very purpose as shown but why
would we want to do this when you want to read
or return all the lines from a file in a more
memory efficient way and in a faster manner you
need to use a loop over method.

So the advantage
of using this method is that the related code is
both really simple and easy to understand right? So, let me take
another quick jump into pycharm and check
the single snip it out. So we are back into pycharm and check out this
for Loop example I have for you. So again, we're sitting on
the same file demo file dot txt reading it in the mode. So for every line in our file
object print read lines, so it is going to print
the output for us containing all of the documents of our file as you can see we will have
Python and we love Ed, Eureka.

That's really simple. Right? And with this we
are actually done understanding how to open the files
and read them in multiple ways. Next. We need to actually take a look
at the write operation, which is again, very simple and almost similar
to the Reed method. Let's start Writing
to a file is as simple as using the right function guys
similar to the read again. So to write to an existing file
we make use of two modes one is the append
and the other is Right, which we already
checked out earlier. By up and we actually add
the contents of the right to a new existing content. And with right we just added
to the blank file now. I am sure there is a question
in your mind right now. So what if the file that I'm trying to work
on is not blank what if it contains
some previous data and we make use of w
instead of a pen.

Guys this will basically
delete everything in the file and overwrite it with
what you've just put and this is exactly
the first example case that I actually showed
you so make sure that you use the mode very
wisely in every situation right so here's a quick example before we dive
right back into code as you can see we open
a file in the right mode and we write two lines
into it and we close it it is as simple as that right
now again taking you back to pycharm and let me walk you through the code so guys we
are back into pycharm right now so check out the first example
I have for you import OS already explained opening it
in the mode of right so since we already have
some content all of that content will be overridden
with hello world and hello Again, so we're opening it.

We're using file dot right
to right to content into it and then we will close it. Let me run this again. No output because we're
not printing it to our console. How do we check if everything is walking
open the demo file? Hello world and hello
world again, right? So this is exactly
what we wanted. But then again this
looks a bit gibberish as I told you right? So we use read lines to actually
make it look nice for us.

Heading back to pycharm again. Check out the next example
I have for you. So now this is to prove that we are actually
overwriting it again, which I've already told you
and it is simple but still let me walk
you through this. So we are working
on the same file. We using the W mode
and then we are writing your to it saying oops
we have over a ton it. Run it run no output. But in the sense
the file is changed. So it says oops over it and instead of hello world
and that old message that we printed. Let me get back
to the pycharm again, and this is for creation and we'll be coming back
to this in just a second.

So let's quickly go back
to our presentation and then we're going to be
coming back to pycharm again. So we're down
to the last two concepts that we will check
out in this session. The first one among that is for us to create
a new file using python. Well guys, even
for the creation of the file, we need to make use
of the open method. We already know
that a is used for up and and W is he's for right
and now we have X which is used to create a file.

But do know that you cannot create two files
of the same name guys. So basically it means that you cannot create a file which already exists check
out the example on your screen and you will definitely
get a better picture of it right there. So you cannot have two files with the same name
test file dot txt. This is not right. So again python will give
you a beautiful error message and it won't be so beautiful
at the end of it. Let me dive back to pycharm and we can check out
the example over here. Let me change this we have
something else right? So let me type header
a card or text.

I'm going to print
new file into Ed, Eureka. Opening it. We're opening it in the X more. So we are actually creating
this file physically right mode to write something
into it and close it. So as I already know
output check out the file, whereas the file called Eddie
Rekha, let us your new file of a deal breaker. So it's perfect, right? Let me quickly head back
to the presentation and we can check out what's next and then the next
simple concept I have for you guys is showing you on
how deletion operation works with respect to files
using python guys. Deleting a file is very simple and straightforward will require
the OSD remove function just for this purpose. So yes importing. The OS module is
a compulsion here. I have been using it all along because it is just
a good programming habit. Use the OS module when you playing around
with the file system the biggest mistake I
have seen people do is that they usually go
on to delete a file, which doesn't exist
again python pushes in an error message.

And that is not good
at the end of the day, right? So it is very vital
to know for sure that the file exists to do this. We just check if the path exists
and if it does cool remove the file else print
that the file doesn't exist. So you cannot remove it. What does this say guys? This is a very simple case of
an exception handled by the user and this is a really
good programming Habit to So all good, but can we delete a folder? Yes, we definitely can a folder
with all the content inside.

It can be deleted using
the rmdir command. What does rmdir stand for it basically stands
for removing directory and the parameter here
is basically the path and by the path includes
the name of the folder which needs to be removed. And this is all of the operations you
can do with python by making use of files. Let me quickly conclude
the session for you guys. So we started by checking out
the different types of files and why we need
to use files, right? So we also saw the different
types of files again and how we can work with each
of these types of files and all of the operations involved
with this as well. Let's take a look
at the agenda for this session. So first of all, I Start with the prerequisites that are python functions
and then I will talk about python decorators
with a few examples. And finally I will discuss
a rather complex concept that is fancy decorators
with a few examples as well.

I hope you guys are clear
with the agenda. Also, don't forget to subscribe to our dear a car
for more exciting tutorials and press the Bell icon to get
the latest updates from Eddie. Wake up. So without wasting
any more time. Let's start our session. I'm sure most
of you are familiar with functions in Python. So let's recall some
of the important Concepts that are going to To
be useful while working with the decorators. So the concepts that I want to discuss
are first class objects and in a functions, so in Python literally
everything is treated as an object including
all the data types and even functions.

So the functions can be passed
around as arguments as well. So that is why it is called
a first class object coming onto the inner functions
a function can be also declared in another function which is known as
an inner function. It also resonates
Around The Decorator, so we'll get to that later. In the session, so let's take it up
to pycharm and understand how in a functions work and we will also try to return
a function from a function which is actually passing
a function as an argument.

So let's take it up
to pycharm guys. So now that we are
in the pycharm. Let me go to
the presentation mode so that the clarity
will be better. So first of all, let me talk
about the first class object. So I'll just take
a function named it as let's say function
one and inside this I am going to pass a variable name. So now I just want
to return let's say hello. So for this I'm going to use
the string interpolation. If you're not sure about that. Please do check out the tutorial
on strings on Ed Eureka so that you will be familiar
with what I'm doing here. That is the
string interpolation.

You'll see what it does. Now. Let me Define one more function. Let's say Define
function number two. And inside this I'm going
to pass the same argument. That is name. And now I'm going to return using
the string interpolation again. Softer this I actually
want to ask how you doing. I have to give two lines
over here they should do and now I want to take
one more function guys. So I will name it as
function number three. And inside this I'm going
to pass function as an argument. So here I just want
to return function number 4 and inside this let's say
I want to write Delano. Now when I print this I'm going
to print function number three and inside this
I'm going to pass function that is functional
were one now again, I'm going to
pause function number.

Let's say three and inside
this I'm going to pass the function number two again. Let's see what the output is. Okay, we have
an error guys function to is missing one required
positional argument name. So we have made
a mistake over here. So when I open this now, I'm getting the output as
hello dear Ilana and dealer know how you doing. So I'm actually able to pass
the functions as arguments. So that is actually how we use
the first class object. We can use anything as
an object in Python. Now moving on
to the next example that I'm going to show you is
for inner function. So how exactly do you
use in a functions. So I'm going to
take one function. Let's say found and inside this I'm going
to Define one more function.

So first of all,
let me Give it a statement. I'll say first function. And after this I am going
to Define one more function and this is going to be
function number two, or I'll just write it
as function number one. And after this I'm going to give
one more statement over here. Let's say first child function. Now I'm going to go
Define one more function. Let's say function number two. And inside this I
am going through print. Let's say second child function.

And let me take one more
statement so function to and function 1 now when I
print our function over here, let's see what the output is. So first of all, we are getting first function that is the base function
and then we are getting the child function
and the first child function. So this is how you can use
in a functions in Python. Basically, it's
a nested function. We are using multiple functions
inside a function.

So we have one function over
here and inside this we have two more chai functions. So this is a basic example
of a no functions and python decorators. Is it going to revolve
around this concept A Lot the first class objects
and in a functions, that is why I was telling
you about this. I'm going to show
you one more example, so I'm going to return
a function from a function. So basically what it
means is I am taking a function as an argument
for another function. So what I'll do is I'll just
write function and Define one function over here. I'll just write n and now I'm going to Define
one more function.

It's a function number one. So I'm going to return
let's say and Eureka. Yes, and now I'm going
to take one more function. Let's say function number
two and inside this function. I am going to return
let's say python. And now let me take
a statement guys. So if n is equal to let say 1 so I'm going
to return function number one unload use this I'll tell
you about this later else.

I am going to return function to so this is
my function guy inside this I have two more functions. I'll show you what it does. So I have a is equal to function
inside the cell right one and now again inside this. Alright, let's say 2 So now when I print a and let's say
I want to print be as well. You'll see what the output is. Give you have a name B
is not defined. So actually I had
to take be over here. So the output is
Eddie Rekha and python, so I'm successfully able
to return a function from a function guys. So I've taken these two
functions as arguments and this is how we can return
a function from a function. So now that we are true
with the python prerequisites. We'll talk about
decorators in Python. A decorator is
a design pattern in Python that allows a user
to add new functionality to an existing object
without modifying its structure.

So decorators are usually called before the definition
of a function you want to decorate let's take
a simple example. Able to understand how it works. So we'll go to pycharm again. I'll clear this off and okay. Let me just put it right here. Now. I'm going to take
a simple decorator example, so I'll just Define a function. Yes. And inside this. Let's say I want to pass
a function as an argument. I'll name it I Function One. Now again, I'm going
to define a wrapper function.

This is my inner function guys. And this is
basically The Decorator that I'm going to use here. I'm going to
pause function again. So you'll see what it does and I'm going to print
one more statement of this. So let's just say welcome
to python editor acre tutorial. Now I'm going to return
wrapper over here. And I'm going to Define
one more function and inside this function.

Number two. I am going to use
a print statement. Let's say pythonista. And let's just call a function
Now function number. Let's say two is equal
to function one function to so this is a very
important statement guys. Now, I'm just going to call
the function number two. Let's see what the output is. So my output is hello pythonista, welcome
to python editor tutorial, as you can see inside
the wrapper function over here. First of all, we are getting hello
after the function which we have right here
this one function number two, which we have passed
in function number one. So this is
my rapper statement guys. There is another approach
to this using a pie syntax or we can call it
a syntactic sugar as well. So it basically makes
it easier to use decorators in Python guys.

What I'm going to do is
I'm going to make a few changes in this code and you Understand
what I have done. So after this statement
that is returned rapper. Okay. Let me clear all this. I can just write
at the rate function number one, and now I'll just
Define my next function that is functional mode 2. And over here,
I'll just print pythonista. And now when I call my function number 2 the output
is going to be same.

So as you can see
the output is same which is hello pythonista. Welcome to python editor
a car tutorial. So what I have changed here is
I have changed this over here. So I've used this pie syntax, or you can call it
a syntactic sugar as well. It makes your job easier. So this is how you can use a simple decorator
in your functions guys. So now let's try
to understand the concept of decorators in Python
with a few more examples.

So I'm going to take a program inside which I'm going
to specify a decorator. Arguments, so I'll just
take function number one. And inside this I'm going
to pass function again. Now I'm going to Define
my wrapper function inside which I will have arguments. So earlier I didn't have
arguments over here. But now I am going to have
arguments inside this decorator. So I'm going to
print hello again. Like I did in the last program and I'm going to call
the function again. So inside this I am going
to use the arguments as well.

And after this I'm going
to print the same statement. That was welcome
to Erica Python tutorial. And I will return wrapper
after this I will use a syntactic sugar function
number 1 I will write and after this I'll Define my function number
two and over here. I will try to print statement. Let's say all right, we can use argument over
here as well and we'll use the string interpolation again. Yeah, then I
print function number. To I'm going to specify
a name as well. Let's say the scene now
my output is okay we have error which is function
one is not defined. So basically this we have made
a mistake over here now, it should work fine.

So we have hello Wasim, welcome
to Erica Python tutorial. So this is a very
simple example guys. So we have actually used
arguments in our decorator. Let's take a look
at the next function that we have. So I'm going to use
a function in which I'm going to return values
from a decorated function. so I'll just Define
function function number one and inside this
I'll pass function again and now I will Define
a wrapper function with the few arguments let's say and after this
it's going to work the same way like we did so I'm going to write
print let's say work so it will show us that it work I'll return wrapper
and after this I will have that same syntactic
sugar function one and I'll Define my function number two here
pass name over here and I will write print string
interpolation get name and now when I print let's say function number two with
name let's say python so what is the output that we are getting
it showing it work so now that we are through
with the decorative let's talk about fancy decorators in Python are nothing but the complex
features of decorators in Python and to explain this I'm going to take a few examples like
class decorator and let's talk about them one by one so
we're making a reference here so that we can use it for various purposes
in the future as well so we are not using
the parentheses over here because we're making
a reference to this function so I'll clear this up and we'll talk about
the class decorators now so there are two ways
to decorate a class in Python the first one is is where you can decorate
the methods inside a class and there are built-in decorators like class
method static method and property in Python so
class method and static method Define methods inside a class that is not connected
to any other instance of a class and property is normally
used to customize the Getters and Setters of a class attribute so let's take an example
to understand this so I will take a class I
will make them more relatable so I will not use
functions instead I'll use let's say Square And for my class over here, I'm going to
Define few functions.

So first of all, I'm going to Define
an inner function and inside of self. I am using one more variable that is side now
self dot side is equal to side and I'm going to add
a property over here. So this is going to be
my decorator guys. So this is going
to be my decorator. It's a built-in operator case. I show you what it does. So I'm going to Define
one more function named as let's say side and inside this I'm going
to pass self and now again, I'm going to return self side and I'm going to use one more.

So this is
my setup function guys, and now inside this I'm going
to use the side function and after this I'm going
to use the value. So if value is greater than equal to 0 I
am going to get the side. Is equal to Value else? I'm going to print
that there is one are over here. And now again I'm going
to use property. And over here, I'm going to Define
area self again. And inside this I'm going
to return the area. So I'm going to use
self dot side and I'm sure everyone must be familiar with the what is
the area of a square that is Side Square. So I'm using a double exponentiation
operator over there, which is used to
calculate the square. So if I make it as 3
it's going to be a cube, but we don't need that. So I'm just going
to leave it at two now. I'm going to define
a class method and it is going to have
one more function. Let's say you win it. Square and inside this
let's have one movie.

We will see LS and now
I'm going to return. one we are done with the so
we are done with the class which has all these functions
and built in class decorators, like property class method
and Setter and getter all those so I'm going to have
square over here. I'm going to be specified
side as five. Now. Let's say what my side is. Yes, and I'm going
to print the area as well. So when I do this
my output is 5 and 25 now, sometimes it's useful
to have a decorator that can keep a track of state. So let's take a few more
examples to explain decorators in Python in detail. So I'm going to make a Singleton
class using class decorators. So first of all, I will import found tools
and after this I'm going to define a Singleton class. So I'll name is as Singleton. Now after that, I am going to use
the function tools da traps inside this CLS. Now comes the wrapper function and inside this I'm going
to have a few arguments as well.

And after this I'm going
to get the instance is equal to CLS orgs and Chaos. I'm going to return wrapper
again making a reference to the function and not calling it but I am going to use this
to make an rapper dot instance. I'll give you making
a small Arrow here. no I'll just write
rapid dot instance is equal to none and I'm going
to return wrapper again after this I have a single ton
and after this I'll have class 1 I'm going to pass and let's say
first is equal to 1 and let's say second
is equal to one as well And I'm going to print
first s second. So let's see if we get true
or false beginning a error guys. All right. I have made a mistake over
here I had to add if statement That's why we are getting
this error guys.

And after this it
should work fine now. So it is actually true
and we know that a Singleton class
only has one instance and there are plenty of Singleton's in Python
including true none Etc. So now that we are done with
the making a Singleton class. I want to talk
about nesting decorators. So in a function, you can actually use
nested decorators as well. So I'll show you
the Syntax for that. So basically what you
can do is you'll just write function one and you
can write function to but you have to Define
all those before. That you use after that you can just
Define a function name and print whatever you want. You can use multiple decorators by stacking them
on top of each other. And now let's take an example in which I am going to take
arguments in a decorator.

So for that I am going to import
function tools and after this I will Define a function, let's say repeat
and inside this. I'll write number now again,
I will write one more function. Let's say decorator. Repeat and after this
I will pass a function inside this and now I
will make one decorator. Let's say funk tools no traps
inside this I will pass function and I'll Define one more
wrapper function over here. And inside this I
will pass a few arguments. now for range number value is equal to I'm going
to return value of this and return wrapper making
not using the parentheses again, and after this I'm going
to return Deco reto repeat and again not
using the parentheses.

Now, we make our decorator. Let's say repeat inside this
I'll specify the number itself. Let's say five after this. I'll Define function and inside the cell past name
using a string interpolation. We will have a name again. So Let's just say I want
to print my name again, or I can use python as well. So just write python over here. Now when I run this we
should not be any errors. So I'm getting it as
python as 4 times. So instead I can use for over
here you get it four times. So this is my repeat function. So I'm using it as an argument
to times also we can use it for 20 times as well.

So it is always useful to pass
an argument in a decorator. Everything in the world
of programming requires a name, but still there are a few Anonymous
Mysteries Lambda functions or Lambda expressions are one
of these kind of entities that are in fact nameless. So before we begin
just make sure guys that you subscribe
to our Channel and hit the Bell icon to stay updated with all the latest
Ed Eureka videos coming back towards the session we shall
first begin with understanding what our Lambda functions or Lambda And why
they're used following that I'll be showing you all how
to write these Lambda functions along with some user-defined
functions as well as some predefined functions
such as filter map and reduce finally. We will be using these Lambda functions to solve
some algebraic expressions. Okay. So without any further Ado, let's move on towards the first
topic of this session, which is understanding what exactly are
Lambda functions. Python Lambda functions are functions that
do not have any name. They are also known as Anonymous
or nameless functions the word Lambda is a key word that specifies what
followers is anonymous now that you are aware of what
these Lambda functions are.

Let's move on further to see
why they're actually used the main purpose of anonymous
functions comes into picture when you need some function. Just once they are created
wherever they are needed due to this reason why
the Lambda functions are A throwaway functions. There are also used
within higher order functions which take a function
as an input or return it as an output
another very good advantage of using these Lambda functions
is reducing the size of code, and I'm going to be showing
you all in this session how to do this.

So now let's move on
towards our next topic which is to see how to
write Anonymous functions. Lambda functions are created
using the Lambda operator and its syntax is as follows the first thing that you need to specify Phi is
the Lambda keyword and following that you'll have to specify
the arguments or the inputs and finally after
the colon symbol, you'll have to
specify the expression that needs to be solved Lambda Expressions can take
any number of arguments. So as you can see over here, my first example is
a Lambda expression without any arguments
in the second example. I've taken a Lambda expression
with just has one argument a one finally. I'm demonstrating
a Lambda expression which has inputs A 1
to a n just remember that all your arguments or inputs need to be
separated by a comma so now let's move on towards
our jupyter notebook and see how we can actually write
these Lambda functions. I'll just create
a new notebook of here guys.

I'll just open a new
notebook of here guys and I'll rename it
as Lambda functions. So guys now just let me write the syntax as
a comment over here. This is going to be good
for a referral purpose. So first is the Lambda keyword
like I already told y'all. Sorry guys for
the spelling mistake, Lambda and the argument. followed by the expression Okay. So the first thing I'll have to write down is
the Lambda keyword following that I'll have to
specify the arguments. So let me just give one argument
to this and after that I'll just say I want to multiply
this a with itself. So this is my Lambda function
but before executing this, I'll require some variable
that can hold the value of this. So I'll just specify that X is equal
to this Lambda function and after this I'll say x
of B and I'll hit run so as you can see over here
when I used X of 3, its return the output to be 9 so guys if I had to solve
the same expression using a normal function, then I would have had
to write a larger piece of code than this.

Let me just demonstrate
this to you guys over here. So I'll just Define
a function say new and I'll pass the parameter
as a now I'll be using return to return the value of a star
a to call this function. I'll have to use the name
of the function and specify some value
to the argument that I've already passed. So in place of a I'll pass
the value as for or let me take it as three itself
like the previous function. And I'll hit run as you can see over here
using Lambda functions. I just required
two lines of code. Whereas while using the normal function I had
to make use of three lines of code along with
this return statement over here. Okay, so guys, I hope you all have understood
how to write these Lambda functions. So guys as you
all have just seen I've used Lambda expressions in the example along
with some other variable X now, I did this because these functions
are nameless and Acquire some name to be called but doesn't it seem confusing as to why a assign a name
to a nameless function? And what is the need of it? It's a legitimate question guys, but the point is this is
not the right way of using Anonymous
functions Anonymous functions.

Like I've already told
y'all are best used with in higher order functions
these functions either take a function as an input or return it as an output
to demonstrate this. Let me just move on
towards our next topic of this session. First thing that we're going
to study is anonymous functions within user-defined functions. So as you all can see
on the screen, I have a user-defined function that takes the Lambda function
as an input in this example over here the normal python function which in my case is
new funk takes one argument X this argument is then added
to some unknown argument which is supplied
through the Lambda function.

Let me just jump onto my jupyter notebook
to explain this in detail. Let me just first create
a heading over here guys. Just remember the number
of prefixed ashes tells which heading it is. So if it is H1, it will have one hash
prefixed to it. If it has to then it's h 2 and so on so I'll just create
a heading over here of H1 level and I'll give the name
as user-defined functions. or Lambda within
user-defined functions Lambda Within user-defined So I hope you guys know
what are user-defined functions.

Okay. So as you all know when you have to create
a function in Python, you'll have to use the d e f keyword followed
by the name of the function. I'll just name the function as a and I'll pass one parameter
to its ax after that. I'll be using
the return statement and within this I'll specify
a Lambda function. I'll pass y as the argument
to this Lambda function and I'll use X Plus y
as my expression now. Let me just give some value
to the variable X and store it in another
variable T So a of 4 and a I spent the value of T of 9 or sorry eight
and I'll hit run. So as you all can see
on the screen, the Lambda function that is used within the function
a is called Whenever I Call this higher order function, and the first thing that I'm doing over
here is passing a value to the variable X and then I'm
printing the value of x plus y so, I hope everyone's
understood this part.

Okay. Now let me just copy
this function and pass a few other values
to this as well. I just ordered a new value
in the variable you and I'll pass the value
for x as say seven and I'll print. Two of five and I hit run. Okay, so I hope
everyone's clear with this. If you have any doubts, please do let me know
in the chat box at my team is here to help you. Now let's move on
towards the next topic which is using Lambda functions within filter map
and reduce functions. The filter method is used
to filter the given iterables, which can either be
lists set Etc. Now this is done with the help
of another function which is passed as
an argument to test all the elements to be either true or false after
applying the function to the set of iterables. If the value is true, then that value is returned
in the output now, let me just jump
onto my Jupiter.

Notebook and use
the Lambda function within the filter method. I'll just give a new heading
over here again. Just for your reference guys. I will create a heading
of H2 level by prefixing it by two hash characters. So I'll just use Lambda Within. filter and since
this is a method like I already told you all
the filter function needs iterables now here, I'll just create a list. I'll say my list. And I'll specify
some elements to this.

The filter method is going
to check for all the elements to either be true or false in accordance
to the expression that is passed within
the Lambda function. Like I already told you
all the filter method is going to check if the expression that is specified
within the Lambda function is either true or false
for all the elements that are present within my list
and it returns all the elements that satisfies the expression. So as a result,
I'll have a new list. So I'll just name
it as a new list.

And I'll use the filter function and within this I'll be using
the Lambda function. Like I already told you all. Let me just specify the input as a and the given
expression over here. Say a I just want to check
if any of these values when divided by 3
will equate to to and I'll pass my list and I'll pass my list
as an argument to this. And since the output
is going to be a list. I'll just use the list
method over here. And one more point. I want you guys
to note is the syntax of the filter function. And since I forgot to specify
this before beginning the demonstration, let me just specify the syntax
of this function over here. I'll see syntax. You have to use
the filter keyword along with some function. followed by the iterables Okay,
so as you can see over here, I have the filter keyword. I have the function
which is Lambda and then I've passed my list as
the iterables to this function. Now, let me just
print the new list.

And I'll hit run. Sorry guys have made
a spelling mistake of here. So it's fi lter. so as you can see over here
I've passed the elements 1 2 3 4 5 & 6 to this filter method
and after checking if this expression is true for all the iterables
it has returned six as the output now let me
just cross check over here so if I divide 1 by 3 I
will not get a result which is equal to 2 similarly
if I divide 2 by 3 I'm not going to get the result
as to again finally as we all know if I divide all
these these elements by three only for six
I'll get the output as too so I hope everyone's clear with
how to use the Lambda function within the filter function So
now let's get back to our presentation and see how we can use
the Lambda function within the map function guys. The map function
in Python is a function that applies a given function
to all the iterables and returns a new list. So I hope you're understanding
what exactly it does. It takes a function as the input
and some iterables as well.

And then it applies
this function to the set of iterables that are passed
and it returns a new list. So now let's get
back to Jupiter. And do the same I'll create
a new heading of course. And it's going to be
Lambda within map. And I had to run so
before moving on towards the demonstration. I'll just write the Syntax
for the map function. So it has to have
the map keyword, of course. And the parameters that are passed to it is
a function and the iterables.

Now, let me just make
use of the same list which I was using previously
and I'll copy that over here and then I'll just store
the output in a new list p and I lose the list function since I want the output
to be a list within this I'll use the map function
and to that map function. I'll pass a Lambda
function as the input. I just passed one argument to this as a and the condition
I'm going to specify is to check if any element
present within my list divided by 3 is not equal to 2 and I'll pass my list
as the set of iterables.

And then finally,
I'll be printing this. Now, let me hit run. So as you all can see over here, it has returned a list
with some Boolean values. The expression that I
wanted to check is a pi/3 not equal to 2 now. Let me just move on
to my list and see what happens when I divide 1 by 3, of course, I'm not going
to get to so I have true as the output now when I divide 2 by 3 again, I'm not going to have
the outputs as to and therefore I have true
as the Boolean value for this. similarly all the elements
present in my list are divided by 3 and it's going to check if the condition
is true therefore only for six is going to be false
and I have the output as false okay so I hope you
guys have understood how to use the Lambda function
within the map function if you have any doubts please do let me know
the chat box guys and my team will revert to you okay now let me just jump on
towards our next topic which is using Lambda function
within the reduce function so guys the reduce function is used
to apply some other function that is passed as a parameter
to it to a list of iterables and finally it
returns a single value and to demonstrate
this I'll just jump onto my jupyter notebook again
and I'll create a heading This is going to be
Lambda with introduced.

And I had to run so first. Let me just write the syntax
of this function. It is the reduce keyword. And it takes a function
as a parameter. The first parameter
is a function. And second is a sequence now to
make use of the reduce function. You'll have to import
the funk tools library or from that Library. You'll have to import
the reduce function to do this. I'll be using from Funk tools. import reduce you
can also directly import the funk tools Library
as import Funk tools or you can also use from
Funk tools import Star these are just the alternate ways
that you can also use over here okay so now I'll be using
the reduce function and within this I'll specify
a Lambda function pass two parameters A and
B and let me just print the sum of a and b.

And finally, it has to have
a sequence as its input. So I'll just specify
a list over here. I'll say the list of values to
be 23 5643 ninety eight and one. Okay, so now let
me hit run and see what it returns. So as you can see
over here guys, I have to 21 as my output. So what this reduce function
is actually doing is it first adds 23 256. So guys the first thing that the This function
does is ADD 23 and 56. And the output of this
is going to be 79. Now after adding
these two values to this output, it will add 43 so 279. It's going to add 43 and it
will produce a new output. After finding the output of 79 and 48 it's going
to add the result to 98. And finally it's going to add that result with one
and Returns the final output, which is 221.

So I hope you
guys have understood how this function
is recursively adding each value to the next value that's present in
the sequence guys. If you have any doubts, please do let me know
in the chat box. Okay. Now let's move on to see how you can actually use
these Lambda expressions or Lambda functions to solve some algebraic
expressions for this. I'll just go back
to my jupyter notebook and I'll create
a heading over here. Sorry guys. I'll just delete
these two kernels. And I'll create a heading. I'll just say
Lambda for algebra. So guys first we'll be taking
some linear equations. So I'll just create a heading
as linear equations. So as we all know algebra, right linear equations
consists of variables of degree 1 which means
they'll have the power as one. So now let's just use
the Lambda function to solve some linear equations. I'll just say s is
equal to Lambda. And I'll pass the argument
or the input as a and the expression
I'll specify as a star a and I'll use S
of for and I hit run.

So as you all can see over
here 4 cross 4 is 16 now. Let me take
a different linear equation. So let me just write the linear
equation over here as a comment. So I just want say 3x
plus 4y, okay, so if I want 3x Plus 4y So I'll have
to specify some name to this CD is equal to Lambda
and X & Y as the inputs. And since I want
3 star x + 4 star why? Okay, I have 3 into X
plus 4 into why okay, and then I'll pass
the values as for comma 7 and I hit run as you all can see 40
has been returned as the output when I pass the value of x as 4
and the value of y as 7 now. Let me take
some quadratic equation. So I hope you all know. What is a quadratic equation. It's an algebraic equation
with the degree to let me just give the heading
as quadratic equation. Okay, so now let me just try
to solve the very famous a plus b the whole Square. He plus b the whole Square so
I'll just say part 2, okay. Now, let me write
a Lambda function that's going to return the value
of a plus b the whole Square.

I'll just save it with a new
variable X and I'll use the Lambda function
and the arguments or the inputs are A and B. The expression that I'm going
to use is a plus b and like we all know we
will have to use double star when we use powers and then I'll print this x
I'll pass the values of A and B as 3 comma 4 and I hit Run Okay.

So as you all can see
I found the value of a plus b the whole Square
using the Lambda Expressions. We love shortcuts and everything
and with Pythons built. function it just
gets more exciting and in this session you
will be learning about three very important built-in
functions namely map filter and reduce so before we begin just
make sure you subscribe to our Channel and hit
the Bell icon to stay updated with all the latest Erica videos
coming back towards the session we shall first begin with a
small introduction to map filter and reduce functions after which
we shall take a deep look at each of these and see how you can actually
use these functions along with user defined as well as Lambda Ian's finally we
shall try to put these functions within each other and see
how it works so I hope everyone's ready to
start with this so let's move on towards the first topic
of this session which will be a small
introduction to map filter and reduce functions okay so let's move
on the map filter and reduce functions are
inbuilt functions of python these functions enable the
functional programming aspect of python in functional
programming the arguments passed are the only factors that decide upon
the output these Since can take any other
function as a parameter and can be supplied to other functions
as parameter as well.

The map function takes
another function as a parameter along with
the sequence of iterables and returns an output after applying the function
to each of the iterable that's present in the sequence. The filter function as the name says is used to
create an output list consisting of values for which the function
returns true the reduce function on the other hand applies
a given function to the iterable and returns a single value. Okay. Okay, so now let's move on and take a deeper look
at each of these functions and how you can actually
write them in Python. Like I've already mentioned before the map function
will take a function and a sequence as a parameter and it applies that function
to the iterables that are supplied to it as you all can see
on the screen.

I have a map function to which I've supplied
a Lambda function as a parameter and a list of iterables. All I want to do over here is
ADD 3 to each of the iterables that are present in this list as you all can see I'll have
an output list with three added to each iterable that's present
in the original list. So now let's move on towards
our jupyter notebook and see how this works. Okay, so I'll just
create a heading of here. Okay. So before I begin
writing this function, let me just write
the syntax first. I'll just write it as a comment. So basically the map function
takes a function and a set of iterables as a parameter. Now, these iterables
can be either a set Tuple or anything here. The function defines
an expression that is in turn applied
to the iterables. The map function can take
user defined as well as Lambda functions as a parameter.

Let us first take a user-defined function as
a parameter to the map function. So just create
a function of here. So I'll use the keyword DF. Okay, so I'll just name
my function as new and I'll pass a parameter as a to this and I just want
to return a star a now. I'll take a variable as X and then I'll use
the map function. I'll take a variable X which will be my map object and then I'll write
the map function to which I'll pass
the new function as a parameter and the list of iterables.

All I'm going to do
after this is print X just to show you all
that this is a map object and then I'll print
the list of x. So as you all can see
on the screen X is basically the map object and the list of X consists of
all values multiplied to itself. So I hope everyone's clear
with this instead of using the list function. You can also use other functions
such as Tuple sets Etc. Let me show you what happens when I used to pull as
the function over here. So as you can see previously
I had an output list and now I have an output Tuple similarly for
the input iterables. You can supply
anything such as lists. Pupils sets Etc. Okay. Now, let's try to take
a Lambda function along with the map
function map function can take more than one list
of parameters as well. Let's see what happens
when we try to do that.

So I'll just copy the severe
and I'll paste it and I'll pass another list
as a parameter. I'm going to make a small change
to the function of here. So I'll pass two parameters. So I'll say a comma B
and I'll say a star B now. I'll hit Run Okay, so as you all can see
on the screen these values present in the iterables
have been multiplied and I have a resulted to bill. So I hope everyone's
clear till here. If you have any doubts, please do let me know
in the chat box and my team is here to help you. So now let's see
how to use Lambda functions along with the map
function Lambda functions as we all know are functions that do not Have any name they
are also known as Anonymous or nameless functions.

These functions are generally provided as an input
to other functions. So now let's move on and see how to use Lambda functions
along with the map function. Okay, so I'll just take
a list over here say LSD and then I pass
some random values to it. I'll take a new variable save I and then I just want
to print the list of and then I'll use
the map function along with the Lambda function. Lambda functions are
single line functions. So we have to provide the expression along
with the function itself. So I'll just say x + 3 and then I'll pass
the parameter as LSD, which is my list and then I'll just print this. Okay. So as you all can see on the screen 3 has been added
to all the elements that are present
within this list over here. Now, let's get back
to our presentation and see how the filter function works. Like. I already mentioned before the filter function
is used to create an output list consisting of values for which
the function returns true.

So as you all can see
on the screen, I have a small example
with a condition where I want to print the values which are greater
than or equal to 3 where I want to print the values
which are greater than Or equal to 3 within this list
present over here. So now let's jump onto
our jupyter notebook and see how the filter function works. I'll just create
a new heading over here. The syntax of this function
is similar to the map function. So basically it takes
a function and the set of iterables as a parameter.

Okay, just like the map function
filter function can be used along with user defined as
well as Lambda functions. So first, let us take a user-defined function
as a parameter to this. So I'll just Define
a function of here. So I'll say new one
and I'll pass a parameter say aye now if I is greater
than or equal to 3. I want to print the value. Now take another variable
J. Which is going to be my filter object. And then I'll use
the filter function and I'll pass new one
as the parameter and I'll Supply a tuple
of random iterables to this.

And then I'll just print out. What is J. Okay. So as you all can see over here, I just printed J2
which the output says that this is a filter object. Now if I want
to return the values that are present within J. I'll just have to use
print Tuple of J. Okay, as you all can see all
the values that return true for this condition
has been returned as the output of this function. So now let's try to use
the filter function along with Lambda functions. I'll take a new variable. Say Z and then I'll use
the filter function to which all Supply a Lambda
function as a parameter. So I'll say Lambda X where X is greater
than or equal to 3. Sorry. I have to put this within
brackets and then I'll pass the same Tuple as a parameter. I'll just copy this. This time I'll print
out the list of see.

Okay, as you all can see
the output has been returned. Just make a note of your guys
that last time I wanted my output to be a tuple and this time I just
said print list of Z. So I have a list as
the output of here. Okay. So I hope everyone's
clear to this. Now. Let's get back
to our presentation and take a look at the reduce
function the reduce function as the name describes
applies a given function to the iterables
and returns a single value.

So here I have a small
example wherein I want to add all the values of these iterables and return
one single final value. So in the first iteration,
I'll have one as x + 2 as Y and then I'm going
to add X Plus Y which is 1 plus 2 and it gives me 3 after the first
step this output 3 becomes X and this input
3 over here becomes Y and then I get an output
as 6 this process Will Go On Till all the values present in the iterables
have been ready.

Used to a single value now, let's jump onto our jupyter
notebook and see how this works. So I'll just create a heading. just like before I
write the syntax first so reduce it takes
a function as a parameter and a set of iterables now
one thing you'll have to note over here is to import
the reduce function from the funk tools module so
all I'm going to do is say from Funk tools import
reduce so I have just made a spelling mistake of here Just like filter and map you
can use reduce functions also with user defined as
well as Lambda functions.

So first, we'll take
a user-defined function. Say a 2 which I'll pass
the parameters as X and Y within this
I'll just say return. X Plus y now, I'll just
take a new variable SAS and I'll use the reduce function to which I'll pass
a as the parameter and I'll pass a list of values. and then I'll just
print s Sorry guys. I've added an extra come
over here in our hit run as you all can see all
the values have been added to each other and I have
the output as 49 now.

Let's try to use
the reduce function with Lambda functions. I'll use the reduce function
directly over here and then I'll use
the Lambda function within this I'll pass parameters and X and Y or this time I'll change
the names I'll take you and pee and then I'll just use Q star p and I'll pass a list
of values to this. And then I hit run. Okay. So as you all can
see all the values that are present in this list
have been multiplied to each other and I have
the corresponding output.

Okay. I hope everyone's
clear till here. If you have any doubts, please do let me know
in the chat box and my team is here
to help you now. Let's get back
to our presentation and see how you can use these functions
along with each other. So first we will be using
the filter function within the map function when I use the filter function
along with a map function. It filters out
the values that satisfy. The condition which is present
within the filter function and IT supplies that output list as a parameter
to the map function. So as you all can see
on the screen, I have a filter function with says I want
to filter out the values that are greater than or equal
to 3 from the Tuple of values that are supplied as
a parameter to this. I'll have three and four as
the output of this function which will be supplied as
the input to the map function.

Okay. So now let's move on
to our jupyter notebook and see how this actually works. So I'll just take
a variable say C and then I'll use
the map function to which I'll Supply a Lambda function
first as a parameter. So I'll say Lambda X. I'll just say X
Plus X you can specify any expression of your choice and then I'll use
the filter function to which I'll Supply another Lambda
function as a parameter. And as a condition, I just say x greater than
or equal to 4 I'll pass a list of values to this.

Say two three four five and then I'll just
print the Tuple of see. So as you all can see
the first thing that happened was filtering
out the values that are greater than or equal
to 4 present within this list after that 4 and 5, which is the output
of the filter function will be supplied as an input
to the map function and then using the map function. I'll add 4 + 4 + 5 + 5
which is 8 and 10 respectively. Okay. Now we've use
the filter function within the map function. So now let's move on and see how you can actually use
the map function within. Filter function. So when we use the map function within the filter function
the set of iterables that are supplied as
an input will be operated upon first by the map function and the output of this map
function will be supplied as the input list
to this filter function.

So now let's get back
to our Jupiter notebook and see how this works. So I'll just take
a new variable say d and then I'll use
the filter function. I'll use the
same condition again, so I'll just copy this. And then I'll use
the map function within the filter function and I'll use Lambda
within the smart function. So just say X Plus X
and I'll pass a list of values. Then I'll just print the Tuple
of t or this time. I'll just say set of tea. So as you all can see
on the screen, I have an output set which is a resultant
of applying matte function to the given set of iterables and then applying this condition
within the filter function to the output
of the map function. So now let's move on
towards the final topic of this session. We're in will be using map and filter within
the reduce function. Okay. So as you all can see
on the screen, I have a small example wherein
I have a reduce function to which I've supplied map and filter as
the input functions Now the innermost function
is the filter function, which says I want all the values that are greater than or equal
to 3 from the list of iterables that are supplied to it.

So as an output
of the filter function, I'll have three and four to this output list
of the filter function the map function produces
a new list of iterables, which is 6 and 8 which are obtained after adding
each of these values to itself and finally six
and eight will be supplied to the reduce function
as a parameter. So now let's get back
to our Jupiter notebook and do the same. So just say map
and filter with introduced. Okay, so I'll just take
a new variable say are and then I'll use
the reduce function to which I'm going to supply a
Lambda function as a parameter. So I'll just say
Lambda X comma Y and then I'll just say X Plus y. Now I'll take the map function to which I'll Supply another
Lambda function as a parameter and then I'll just say X Plus X. After this, I'll be using
the filter function.

And again, I'll use
a Lambda function within this filter function. I would say X. I want
to return all the values that are less than or equal to 4 to this I'll pass
a list of iterables. Say one two, three, four, five six seven
and then I'll just print out our Sorry guys. I've made a small
mistake of here. Okay, so now let me hit run. Okay, as you all can see
on the screen first, my filter function
will filter out all the values that are less than or equal to 4 the output of this
is supplied to the map function and all the values
are added to each other.

Finally the output list
of the map function will be supplied as an input
to the reduce function and all the integers
will be added to each other and I'll have one output
which is 20 generating iterable. Considered to be a painful task, but with generators in Python
this task becomes very simple before we begin just
make sure you subscribe to our Channel and hit
the Bell icon to stay updated with all the latest
Eddie Rekha videos coming back towards the session we shall
first begin with understanding what our generators and their advantages then
we shall be differentiating between normal functions and the generator functions
following which I'll be showing you all how to create
generators in Python.

Then we shall take a look
at generator expressions and finally a few use cases which will be generating
the Fibonacci series generating a stream of numbers and generating the sine
wave using Seaborn along with generators in Python. So let's move on
towards the first topic which is what our generators generators
are basically functions that return traversable objects or items these functions
do not produce all the items at once rather. They produce one
at a time and only when required also whenever a
for statement is included to Do what a set of items
a generator function is run generators have a number of advantages as
well without generators in Python producing iterables
is extremely difficult and lengthy generators make
our task very simple.

This is because the implement
the emitter next and stop iteration methods
automatically generators. Also help save memory
as the items are produced only when required unlike
normal python functions. This fact becomes very important when you need to create
a a huge number of iterators. This is also considered as the biggest advantage of generators along
with this generators can be used to produce
infinite number of items and to pipeline
a number of operations. So I hope everyone's
understood what our generators and their advantages. Okay. So now let's move on
to see the difference between normal functions
and generators generators and python are created just like how you create normal functions
using the d e f keyword but generator functions make use
of the yield keyword instead. for the done this is done
to notify The Interpreter that this is
an iterator not just this generator functions are run when the next function is called and not by the name as in case
of the normal functions and like I've already mentioned before generator functions
produce items one at a time and only when required whereas the normal functions
produce all the items in a single go now that you have a brief idea
about generator functions let's move on to see how to write
generators in Python so as you can see
on the screen green I have a small example where
and I've defined the function and then I've used
the yield keyword instead of return so now let me jump
onto my jupyter notebook and show you all how to write
generators in Python I've already opened
a new notebook of here I just reading the notebook
as generators in Python and then like I've
already told you all before I'll have to use
the d e f key word to define a generator function so I'll just name the function
as new and I'll pass the parameter as a dictionary after this I'll use
the for statement and I'll use for X comma y n
I'll use for X comma Y in my dictionary and I want the items
as well Yield.

X comma y Okay, after this, I'll have to
specify a dictionary. So I'll say a is my dictionary
and I'll specify one as hi. and two as welcome You can give
any values of your choice. Now after this. I'll have to create
a generator object for my function. So I'll name that object as B and I'll specify B is equal
to Nu of a just to show y'all. What is B. I'll print B. And like I've already told y'all
before instead of the name of the function.

You'll have to use
the next keyword to return values from generators. So I'll say next of B
and I'll hit run. So as you can see over here. The first output
over here specifies that b is a generator object and the second output is
generated by this next function. Now, let me just copy
this function again and I'll paste it over here and I'll hit run. So as you can see over
here the first time I use the next function. It Returns the first key
value pair of my dictionary and when I used it again, it has returned the second key
value pair of my dictionary if I try to use
the next method again.

It says that stop
iteration has been called. Okay. Now let me take another example where in I'll
specify some condition. I want to return iterable that satisfied that
particular condition. Okay. So here I'll just
Define another function. So I'll say it Define my funk
and I'll pass the parameter as a or I'll use some of the name since I've used a last
time I'll use I now while the value of I
is less than or equal. two three You defy so I have made
a spelling mistake of here. It's why I ELD. Okay, so he'll die. Now for this. I'll have to create
a generator object again. I'll say the generator object is
J which is equal to the name of my function. And I'll have to specify a value
for I so I'll just specify the value as to after this. I'll just print next of Jay
since you all know that J is the generator object.

I'm not going to print it again. Okay, so as you can see
over here the first time I use next of J. It has returned to as
the value now just copy this. And I'll rerun it. Oh, sorry guys, I forgotten to
increment the value of I please keep in mind that
when you're using while Loops, you'll have to increment
the value of the variable that you're using
as an iterator. So now let me hit run. So as you can see over here
without incrementing the value of I when I use the next method
it has returned to now that I've incremented the value
of I I'll hit next of J again and as you can see over here, I've got three as my output now
if I use next of J again. It has called
the stop iteration method.

So I hope everyone's
clear with this. Now, let me take another example where in I'll have
two parts in my function. So I'll just Define
a new function. I'll name the function as X and within this I'll just
specify some variable n equal to 3 and then
I'll yield the value of this. After this, I'll make
some changes to the value of n I'll say n is equal to n star n and then I'll yield and again. I have to create
a generator object. So I'll just say V is equal to and then I'll use
the next method. So as you can see over here when I use next of v it has
returned only the first value of my function now in case I
use the next function again, it will return the second value
which is present in my function.

And after this if I do it again, it has to call stop iteration in case you want to execute
the same function at once you can make use of the for Loop this Loop
helps iterate over the objects and after all implementations, it executes stop it. Shouldn't let me just jump
onto my jupyter notebook and show y'all how to do this. Okay, so I'll use
the same function which I've used previously. and after this I'll use the
for Loop so for X in v print X So as you can see over here
after using the for loop, I have both the values that are returned one
after the other the for Loop has not returned
them simultaneously, but using the for Loop, I'm getting into the function
printing the first Value First and after that I'm printing
the second value.

So I hope everyone's clear till here in case
you have any doubts. Please do let me know
in the chat box and my team is here to help you. Now let's move on and see how to use generator Expressions
generator Expressions can be used along with
for Loops to produce iterators. This usually makes
the generation of iterables much easier generator Expressions
resemble list comprehensions and like Lambda functions generator Expressions create an
anonymous generator functions.

Let me just jump
onto my jupyter notebook and explain this in detail. I'll use some variable F and I'll specify the values
of this to be in the range of 6. after this I'll just
print list comprehension and I'll end this with a colon
I'll use another variable Q when I'm going
to store the values of list comprehensions so to specify the list
comprehension I'll be using the square brackets so
I'll say X plus 2 for X in F and then I'll print queue
after this I'll just copy these two lines and create
a generator expression so I'll just change
the name over here I'll say generator expression
and make a note you'll have to change the braces
too It Embraces and then I'll print queue again. I'll change the name to our
and then I'll print our As you can see over here
when I use list comprehension, it has returned a list
of values corresponding to the values of F.

And when I used
a generator expression, and after that when I said print
our it has just returned that are is a generator object to print the values using
the generator Expressions. I will be using the
for Loop so for X in r print X So as you can see over
here using the for Loop, I've generated the values
one after the other whereas using the list
comprehension all the values were generated
at once generator functions. Like Lambda functions can be used within
other functions as well. So in case you want
to find the minimum value of our I just copy this
and I'll paste it over here and then I'll say print. minimum of our So
as you can see over here, it has returned
the minimum value which is present in our and that is too so I hope
everyone's clear till here.

Okay. So now let's move on
and look at the use cases that we will be discussing
in the session today. Like I mentioned before I'll be taking
three use case examples, which is generating
the Fibonacci series generating a number stream and generating the sine wave
using generators in Python. Okay. So let's move on
towards the first one which is the Fibonacci series. Fibonacci series as we
all know is a series of numbers where in each number is the sum
of preceding two numbers. The first two numbers
of this series are assumed to be a 0 and 1. So for example, as you can see on the screen,
I have values 0 1 1 3 Etc.

Ok, so now let's get back
to our Jupiter notebook and see how you can use
generator functions to produce Fibonacci numbers. Okay, so I'll just give
a heading over here guys. I just give the heading as fib. Okay, and I'll
Define a function. I'll name the function as fib. And within this I'll just
specify the first variable and the second variable as
zero and one after this. while true I want
to use the value of f which is the first number
of my series after this. I'll have to increment the values the second number
becomes the first number and the third number is the sum
of the first and second number. So I'll just use f comma s will become S and F plus s
in case you have any doubts, please do let me know
the chat box guys.

Okay. So after this,
I'll use the for Loop. so 4X in fib now I'll specify
some condition over here so that the iterators that I'm producing satisfies
some limit so I'll just use if if the value of x
is greater than 50 then I want it to stop so
I'll say break after this I'll just print
I'll just print X and I'll end this
with a space Now, let me hit run. So as you can see over here, I have all the values
of the Fibonacci series that are less than 50. So I hope everyone's
clear with this. Okay. So now let's move on and see how you can generate
a stream of numbers. The stream of numbers can be
anything from 0 to any number or even numbers or odd numbers? Okay.

So let me jump onto
my jupyter notebook and see how you can actually generate
a stream of numbers. So I'll just create
a new heading over here. I'll name it as number stream. And I hit run. Okay, I'll just
take a variable a and I'll specify the range
of this to be hundred. After this, I'll use
a generator expression. So I'll say B is equal
to X for X in a I want to print all the values of a
within the range of a hundred. So after this,
I'll just print be. And I'll have
to use the for Loop. So for y in be Print why? So as you can see over here, I have all the hundred values
of a now in case you want to generate only
odd or even values. You just have to make a change
to the range function. So I'll just copy this. And I'll paste it over here
and to print even numbers. I'll just say start
from to go on to the hundred and in the range of two.

So as you can see over here, I've generated a stream
of even numbers in case you want to generate or numbers. All you have to do is
change the values over here. I'll just say one. So as you can see over
here by just changing the first value from 2 to 1. I've generated a stream
of odd numbers. So what does range function
actually does is it starts from 1 it will go on to the hundred excluding hundred
in the intervals of two. So I hope
everyone's understood this. Okay. Now let's move on towards
our third use case example, which is generating
the sine wave using si bon and generators in Python. So as you can see on the screen
using the normal function, my sine wave is going to produce
all the waves at once but using the generator function I
can produce one wave at a time. Okay, I'll just move on
to my jupyter notebook. I've already written
a function for that.

So I'll just paste it
over here and I hit run. It's going to take a few minutes since I've imported
the numpy matplotlib and the Seabourn Library. As you can see over here
using the normal function. I've generated all
the sine waves at once now, let me show you what happens when I use
the generator function since I already
have my function. I'll just copy
paste it over here. And then I had to run. So as you can see over here, I've produced just one wave
among all the waves that are present in my output. Now if I want to print
another wave I'll just copy this next function again. So I'll say control C
and I'll copy it and I'll hit run. So as you can see over here when I use the print statement
for the next function again, it has returned
another sine wave. Okay, so I hope you
are clear with this. Let me just print
the sine wave again. As you can see on the screen the third sine wave
has been returned.

And then when I print it again, it will return
the fourth sign wave Loops, which basically stands for object-oriented
programming system or object-oriented programming
as its most popularly known is one of the most popular
programming Paradigm now, although python is not completely an object
oriented programming language, but still it uses major concepts of object oriented
programming style as part of this now in this session, what will majorly be talking
about our classes and objects classes in Python and object-oriented Concepts
in python as well. Now, let's first start about classes and objects
now to those of you who are not familiar with the
different programming Paradigm, two of the most programming
Paradigm is object oriented programming and procedure
oriented programming now. You look at older
programming languages like C, or you can see
Visual Basic as well. These followed procedure oriented programming
language staff. We're in what used to happen was that the entire program
was divided into smaller parts are known as functions and the importance
was not given to the data but the sequence of actions
which were performed. Also what used to happen. There was that the entire
process took a top-down approach as such but what happened is when When you're programming
languages came up, they realize the value
of the data and they came up with the opportunity of creating
something known as objects.

Now objects are quite similar
to what you can relate to in real world entity as well. Now anything that we
see around anything that has different properties
can be called as an object and hear how it differs
from the older style. That is the program procedure
oriented programming style is that it goes from
a bottom-up approach? Which as well as there's
more data security as and you can use
various operations, like data accessing data
over loading data expansion. And so for now some of
the examples of object-oriented programming languages is
C Sharp Java Visual basic.net and so far now, let's first address the question
of what exactly is a class and object now to help
you understand this better.

Let's actually look at
an example here now to give you a simple one-line definition. A class basically is
a logical grouping which helps us reuse and rebuild our data as part
of the code now to put it quite simply it basically
is similar to a template or a blueprint that we use once I have defined
a specific requirement of my then what I can do is that I can go on very ating
with respect to that. Now, let's look
at the example here now, if you look here I have created
a class called employees wherein I have defined some of the most common parameter each of my employees
will be Having that would be his name. There'd be that age and they
would be the salary now. I have defined a blueprint
but it comes there comes a time where I need to implement
this so and instance which is basically a entity of the class is referred
to as an object here. Now, if you look here there are basically
three different objects, I have object one, which is referring to Sarah
whose age is 37 as well.

As salary is 10,000
my object to is John. On Whose age is 43 and salary is 21,000
similarly is Jessica as well whose age is 26
and the salary is 24,000. Now, how does pythian
implemented classes now again, go back to the definition
a class basically is a blueprint for which objects are created. Now coming to the basic Syntax for how to write
a class in Python. It's quite easy because you just need
to define the keyword class following which you need to
specify the name of the class.

Now, let's go. If you take
the previous example, the name of that class
would be employees. And each of the objects
would be created from that same class. Now what I'm going to be writing inside the class would be
three major aspects. I would have my class variables. I would have instance. World and I would
have data members. Okay. Now these are the three major
aspects to any class as such now if I need a variable which is going to be shared by
all the instances of the class now do not get confused
when I say instance. It basically is referring
to the object itself. So here we refer to an object
as instance now each if I want each of the instance
to share a common variable then I would make it a class variable
but let's say I want each of the instances. Has to have a specific variable. Okay, then I would be using
an instance variable as such.

Then comes the third part
which basically is your data. Remember this basically
is a class variable or an instance variable as such
that actually holds the data associated with respect
to the class and objects. Now without confusing
you any further. Let me actually switch
to my pycharm. Okay, and let me show you this by writing by defining
a class here itself. So let's start by creating
a simple classroom. Now, let me use the first
keyword for defining any class that is class. Then comes name of the class. Now for today's example, what I'll do is I'll create
a class called cars, okay? So I've created a car class
called cars, okay? Can you guys see this? Okay. And here what I'm going to do, is that right now I'm not going
to write anything. So I'm just going
to use the keyword pass then comes the time for me to create objects
for this class. So what I do is let
me call an object. Let's take Honda for it. Okay. So this is the name of my object and then I'm going
to specify to which class it belongs to so it belongs
to the class car.

And this is how you create an object
in Python quite easy, right? Similarly, let me
create another one. Let me call it start. Okay, tata is also
going to be of car. Okay. So basically what I
have done here is that I've created two objects
that belong to a specific class. Now time now comes the time when you actually assign
values to these instances or objects are such now
let's say I want to add the name or the model number
for the Honda car.

So I'm going to say Honda
which is my object following which use a DOT operator and then specify what instance
variable you want to use now. Let's say I want to specify model name OKAY model
name is equal to I'd say City because I like Honda City
okay now I'll also add another variable
which is year of manufacture so I'll see you here M okay and this basically is going
to be equal to Let's say 2017. Now I'll also add price. Okay. I'd say about ten lakhs. Does that sound fine? Now, let me just copy the same
and let me create an object for Tata car as well now here. Let me just change it to data. and let's say
this is bored Okay. So let's keep the you're
the same or let me reduce it 2016 and let's say the price
is let me reduce it.

I'll make it six. Okay. Does that sound fine now? What I have done here is that I have created
instances of the class or objects to that class. And each of these
instances themself have a specific variable
assigned to them as well. So in this case what you see here
is the model name what you see is the year and
what you see is the price. So these are basically
variables Associated to each of these instances as well. Now if I say just print
and I say Honda Dot model name Okay, let me take
the price itself. Let's try running this. Okay, it's with respect
to the definition of the class. Now. If you go back to if we go back
to our slides here, can you see there's
a small semicolon here that we have missed out. So this is how it is a single semicolon
can make a lot of difference. Okay. Now let's just save this. Let's run it. Okay, I can see the price
of my Honda car here.

Now. This is a lot of pain for me when I'm working
with multiple instances which have unique
variables to them. But let's say if I have common values
that needs to be created for all of these if I was using
other programming languages, we had a concept
known as Constructors, but don't worry that same is present
here as well with python. So create a Constructor use the following command
which is deaf, which is basically defined. A function and use in it now in it is basically
a Constructor here and what it is representing is that it is going to initialize
the value of the variables. Now if you notice here, there is a keyword
that is already added here that is self self basically
is a reference to the object which is going to be
calling this function. Now those of you
who are not familiar with functions can check out
our video on python tutorials where we have talked
about functions and also check Check out our python
function video as well.

Okay. Now what happens is to this. Let me pass a model name. I'll also passed
the year manufacture. And let's see the price as well. Okay. Now I need to assign the values for these variables
for all the object. Now. If I need to do that,
then what I need to do is that I need to First
reference the object. So that's self Dot. model name
equal to the model name that it's getting so then
serve Not yet of manufacturing. And finally self dot price. Okay. Now what I'm basically doing is
that further my Constructor, I would be passing
these three parameters.

So for the object
or the instance, which is going to be created, please add these
values for that. Okay. Now let me show you
how to change this as well now, I don't need this so I will remove all this. Okay, so here what I'll do is I'll pass
Honda I'll pass City. Okay. I also pass the year of manufacturing is 2017 and let
me pass the price again.

Same for Tata So
what I've basically done is that I have generalized the requirement that I want
now again if I run the same. What you can see here is I
am getting the same output that I had gotten
earlier as well. So this basically
is a Constructor that is going to be used when I have to assign
specific values to my objects or instances at the time that they are creating
apart from this if you want to create or you want to add
any specific value, you're free to do that. Now, let's say I want
to add a new value. Let's say I want to create
Honda dot let's say I want to add the CC as well
the CC of Honda City which is equal to 2500. Okay. So this is also very simple. Now what happens here is that I have created
an instance variable for the Honda object. Okay. Now same thing, let me just say If I want
to see the complete values that are associated
to an object then what do I do is that I check
the namespace for now. How do I check the namespace for it is that I use
the dictionary option.

Sorry. I use a dictionary function. okay, so if I use tick function
and if I run this then what you see here is
that I have a model name, which is City. I have a year
of manufacturing 2017. I have a price and I have the CC Associated
as a to it as well. Okay. Now what basically
it tells me is if I use this object and request any of these values
then this is the output that I would be getting same
if I change for Tata. And I run this. Then what you see here is
that cc is not present.

So I hope you understand
the difference between both. Can I have a quick confirmation
in the chat box? Okay, that's great. Good to see that all
of you are following it. Now if I have a class then if I don't perform
any operations in it, then I'm basically
not optimizing our using the complete capability
of that class as well. Now. What I'll be doing is that I'll be creating
a function here. So this function what
it basically does is that it's going to increase
the price of my car so what I'm going to do is that for defining any function
use the keyword Def okay following which the name of the function so let's say
price underscore increase okay now this is a function but it's going to be performing on itself as well
so you self here okay and I'm going to start
defining this function what do I need to do is that I basically just need to
update the value of price okay so what I'm going to do is that I'm going to use
self dot price equal to then I'm going to do a simple computation let's say
the present self dot price Sorry about the typo.

Into okay, how much do you think
the annual price range would be? Let's take a guess. Let's maybe fifteen percent
rise in that case. I'll go with 1.15. Okay. Now I have defined
a function here. But what you need
to understand is that it's not exactly
in the scope of the class. So Sorry about that. Now how do you identify
if it's in scope or not? It's basically one of the he's
with respect to pie chart if I expand it, then I know what is part
of the class and what is not so this is one
of the major reasons that we recommend you use
pycharm as an IDE as such. Okay. Now I need to
increase the price. So what I'll do
is let me go back. Let's say I want to check
the price of the Honda first. Okay, then what
I'm going to do is that I'm going
to call the function with respect to the class.

Now. It's defined to that class. So what I'll do is
that I'll send this funk. I'll use the Honda Honda object
to call that function now. Do you use any of the functions
Associated to a class make sure you're using the instance
or object of that class? So Honda Dot Now you can already see here
the different suggestions that comes to it. Now price increase is
the function that I want. Okay. And again, let me copy
this and paste it. Okay. So again see the major issue
here is it's considering this. So if you just double indent
it it's going to set back. Okay, just save this
and let me rerun this. Okay, now it's giving
me the output so it's converting at let me just add in here just
to convert it to integer type. Okay, so the output
should be converted to integer type for me.

So it's incremented
the value to 1.15 times. Okay. So these are basic
function operations that you can perform
with respect to python. Now, let me go back
to my presentation and here let's talk about
the various object-oriented Concepts invite them. Now in this session. What we'll be talking about are
the three major Concepts which is inheritance
encapsulation and abstraction. Now when we come down
to inheritance inheritance, basically is the ability
or The opportunity for any class to inherit
the attributes and behaviors from the parent class. Now when I talk about a parent class it refers
to a superclass as such.

Okay, so let's take cars
itself for an example. But before that let's look
at the example here. Now your parent becomes
a base class and Son becomes the derived class as such this is same that will be implementing
in our program as well. So in our pycharm, what I'll do is that I'm going
to create new class and let me call it super car but if it has to inherit
it the properties that are present in the car class then
what I need to do is that I need to specify car here okay that means it becomes
the parent for the supercars okay so here I'm not going
to Define anything I'm just going to say pass and let me remove this from here
And let me add it here.

Okay, now rather than making
Honda as instance of car class. Let me let me make it
of the Supercar class. Okay. Now I have not defined
an init operation on nor I have I initiated the values
for these variables as well. Okay. So what I'm going to do is that let me just
try running this. Okay. Let me remove this. Okay, and let me just print. the namespace for
Honda Which is Honda Dot? Before that, let
me just show you. Let me just print one
of the values itself first before I show you
the name space completely.

Let's say on Dot. here Okay. So your of manufacturing
is defined here. I have not explicitly defined
in the child class. But let me make sure
let me just run this and let's see the output. Okay, so here basically
it's just passing it. Ah spelling mistake. Let's rerun this now here. What is happening is that it is referencing
to its parent. Okay now to get
a better understanding of what exactly is happening here. Okay, we're going
to use something interesting.

What we're basically
going to do is that we're going to use
the help function. print help and here. What I'm going to do is
that I'm going to pass Honda. Let me just comment this. Now this is something that I really want
to show you guys. Okay. Now if you see here
what is happening is that it's showing me
the method resolution order. So basically it's showing me how it is going
to follow the sequence of operations first. It is going to check
in Supercar for init method, but I have not defined it here.

So what it's going to do is that it's going
to refer the car class if it is not defined
there as well, then it will go back
to the parent. Class for all objects
with this built-in dot objects. This is the parent class that is going to be inherited
by all the classes used in this language as
such so it's found the init method present in cars. Okay, and it's shown methods inherited from class is
the initiative in it method and it has initialized itself. Okay. Now this is basically
the sequence of operations that happen as well. Now when I create Define
any Function with respect to the child class is going
to check the child class. If it is not present
then it's going to check the parent glass as such now, it can be anything
as such it can also be the price increase as well. and okay. Okay, let me just comment
this section out. So here again, it has inherited
this method as well. Now, let's say if you do want to Define an init
method as part of the class, then what you basically do is that you follow the same
sequence you right defined.

Okay, following which
you use in it? Then you specify the parameters. It has to take. okay, and then
what you basically do is that you shouldn't actually
copy this entire code and replace it here. What you can do is that you can use
the keyword super. . In it. Okay. So what I'm referring to is that it should call
the init function present in the superclass. Okay, in that case, what I'm going to do is
that I need to pass the parameters here as well. So I'm going to pass
the model name. I'm going to pass. The year of manufacturing as well as I'm going
to pass the price as well. Now this is basically
to reduce the code that you're going to be writing
as such now apart from this.

Let's say there are
few other variables that are going to be taking
let's say I'm going to include CC as part of my super class then what I can do is
that I can write here self. dot cc is equal to CC so
I am basically building on what is already present and this is one
of the major aspects that you can use
inheritance for this in turn reduces a lot
of codependency as well and is one of the most
popular and major factor for any programming language that uses object-oriented
programming systems okay now coming back to the next concept that is associated
to python okay you have Encapsulation
basically is the method through which you bind your data
and your code together.

Now, it also helps you
in hiding your data from people whom you don't want
to do it don't want to give visibility to so this is one of the major key factors for any programming
language as such now, there are two major ways
through which you can I access Or achieve
encapsulation one is by using the getter and Setter method and the next
is by using at project. Okay. Now we'll be talking more
about that in our next session. But let me give you a simple
understanding what happens is that you want to change
a specific value as on when in the go itself. Let's say my year of development
or my year model. You're just keeps changing
continuously in that case. What I need to should do is
I need to update these values on regular interval. But let's say if there is
a specific dependency on these variables
ahead as well.

Then it becomes an issue
same can be said with respect to price
now price is going to be increased continuously
through getter Setter method. I can ensure that this is going
to be implemented every time there's going to be
a change as well apart from that one of the major
concepts with respect to object oriented programming
is abstraction now with respect. Back to abstraction
what basically it means is that it hides
the implementation details and only provides
the functionalities to the user. Now. If you look at the image here
now a mechanical engineer or an automobile engineer who works with your car is aware of the inside and out
of your car as well. Now if I need to drive a car, I don't need to know
that I just need to know how to turn on my car how to change the gears
and how to move forward as well. That is what abstraction
helps me achieve. I don't need to understand
what exactly happens when a gear shifts
from second to third but I just need to know that a gear shift from second to third
is going to make it easier for me to move ahead as well.

Okay, so this can be achieved
by using abstract classes and an abstract class
is quite similar to an actual class itself. But how is it different
from an actual class? Is that an abstract class
cannot have an object of itself you need? Inherit the abstract class and you need to create an object
of that abstract class as well. Now, let me go back
to the same example. Let's change it here. Okay. Now what I'll do is that I'm going to add
a few additional lines of code. Okay. Let me just copy. here, let's say I'm going
to say from vici ABC and create abstract method Okay. Now what I'm going to say is
that my car class ABC is also. inheriting this abstract now, I'm going to remove all this and Here I'm going to make
this an abstract method where and I'm not going
to define the logic here. Okay, for now what I just do is
that I call it. Okay. And in my superclass
what I'll do is that I'm going to create
the same function. But here I'm not going
to Define any logic.

Okay. So what I'm basically doing is
that in my abstract class, I'm defining the method
to increase the price but based on my requirement now, let's say I don't want
my supercars to have an increase of just 1.15. So what I'm going to do is
that I'm going to increase this. Let's say the annual increase
is going to be two percentage. So this is one of the major uses
through which I can perform or I can use abstract classes. I can just Define
the basic logic which is needed to be
implemented in all the classes.

Ahead and then what I can do is that I can implement
or very 8 these functions as per my requirement. Okay. Now with this, let me go back to our slide
and let me just summarize. So we started with
classes and objects. We talked about
classes in Python, and then we talked about
the various object-oriented programming Concepts in Python. Let's talk about the init
function in Python. So what exactly is the init function init function
automatically gets called each time an object
is created for a class. Now, when we add
an init function to a parent Class A Child class will not be able to access
the parent class method. So to overcome this the child
class init function overrides the parent class init function. So now let's take a look
at an example to understand this now to show
how init function works. Let me first clear this Will I
do init function over here? Yes and instead of self.

I will add one more variable. Let's say F name and f h now what I'll do is I'll just write
self dot name is equal to F name and self dot h is equal to FH now take
one more function guys. So I'll just name it
as let's save you. And for view I want to print
the value of f name.

Self dot name and self dot age. So this is
my parent function guys, and for the definition in the child class, I
will also make one in function. So I'll just write
it as in itself. And again, I have to add F name. And FH. And let's say self dot name
is equal to F name and self dot h is equal to FH. Now. This init function is going
to overwrite the pennant in function guys. So let's make one more function. So this is going
to be view as well. And in this let's say
I want to print okay before we move on we have to specify the parent function
with the init function as well. And we don't have to mention
these variables instead. I'm going to add one more. Let's say I want to add
last name as well. And I'm going to add it
as let's say Eddie Rekha. Now, I'm going to print over
here self dot h self dot last name and self-taught. Let's say name. All right, I have
to remove these. Let's make one more object.

And give it the value,
let's say I want H to be 23, and last name is going to be python in the inverted commas
name we have already specified so we don't have
to give it again. And I'm going to just
call the function. Let's see what happens. What is the output will be so as you can see I'm getting
the output as python at Eureka and when you see so this is how you can override
the parent class init method using the child class guys. So this is all
about doing it function. Now, let's talk
about the next topic that we have which is
the types of inheritance. So depending upon how many types of painting class in child class
are going to be there inside the program following
are the types of inheritance in Python guys.

So there is single inheritance. There is multiple inheritance, then there is multiple
Level inheritance hierarchical inheritance and there is
Hybrid inheritance as well. So we haven't talked about each
of them in detail guys. So first of all,
let's talk about what is single inheritance. So when their inheritance
involves one child class and one parent class
only it's going to be a single inheritance the example that I showed you before
is the example of single inheritance guys and talking
about multiple inheritance. It is going to involve
more than one painting class, which means we are going to have
at least two parent classes and the child class is going to derive properties
from both of them. M and this is called multiple inheritance now talking
about multi-level inheritance. Let's say we have
a single inheritance going on. We have a parent class
and we have child class but the child class also
act as a parent class for another child class that is going to be
a multi-level inheritance guys and talking about hierarchical
inheritance hierarchical inheritance actually
involves multiple inheritance from the same vein in class and talking about
hybrid in Hayden's if a program has
more than one types of in it and let's say we have a
single and multiple inheritance going on simultaneously.

It's going to be a I
played inheritance guys. So let's take a look
at examples for each of them. Let's go to pycharm guys, and I will remove all
this so I will start with single inheritance guys, so I'll just take
a parent class. And give it a function. Let's say Function One. And give it a statement. Let's say this is function 1. Now, let's take
another class guys class child and give you the value
of the painting class. And after that we can move
for another function. It's a function number
two and give it a statement. Let's say print this is function
to now Mega child class object and call the function so we can call both of these functions
for just call function one give it the output and we are getting the output
as this is function 1 so this is a basic example
of single inheritance guys. Now talking about
multiple inheritance. What I'm going to do
is I am going to make one more class over here.

Let's say class. parent too Now what happens is let's say give
it a function number 3. Let's say. And print statement. This is function 3 and in
the Declaration over here. I'm going to just
specify two classes. And when I call the functions I
can call function number one and I can call
the function number three as well guys. So let's see what is happening
here in the output. I'm able to call the function
number one and function number three as well
from the child class object.

So this is the example of multiple inheritance guys
now talking about multi. Level inheritance. So what I'm going to do is
I'm just going to specify parent over here. And from this let's say it
doesn't have any Declaration of parent 1 which is this class. So it is not able to inherit
any properties from that but what I'm going to do is I'll
just specify parent to over here and I can still
call these functions because there is an inheritance
going on between them which is multi-level inheritance, which basically
means this class.

The parent one class
is actually giving properties to pair into class. And paid into class is giving
properties to the child class. So this is example
of multi-level inheritance guys. Now talking about
hierarchical inheritance guys, but I'm going to do is instead
of pairing to over here. I'll just specify parent. So for these two child classes, I have the same parent class
and now let's see if I can have
the same output or not. I'm not going to get the
properties from the parent to because I have not specified it
in the United ends. So I'll just remove this. And let's see what happens. I'm getting the output
as this is function one. Okay, let's make the object
for parent to as well. All right, give it one
and Obi One Dot. Let's see what functions
we can have. I can have the function number
three and I can have the function number one as well. So I just print function number one and from both
the child classes. I'm able to print
the function number one.

So this is the example of
hierarchical inheritance guys. I am using the same parent class
to give the properties to both parent to
and child class as well. And now talking about Hybrid
inheritance Hybrid inheritance actually involves more
than one inheritance going on in the single program. So we Have a single
inheritance over here. So let's say I want to have
multiple inheritance as well.

So I'll just see if I parent to now
and this is the example of Hybrid inheritance guys because we have a single
inheritance going on over here and in the child class, I'm inheriting both the
parent 1 ampere into and this is the example
of multiple inheritance. So this is a Hybrid
inheritance example guys. We are getting a type error which is saying cannot create a consistent method resolution
order for base parents parent 1 ampere into okay. Let's say said of this I will make
one more class over here. Give it a value. Let's say pair in number 3. Give it a function function. Let's say four
and print statement.

This is function for now
instead of parent. Number two. What I'm going to do is
I'll just take parent number three guys and with
the child class operator. Let's see if I can actually get
the function number one and let's say I want
function for as well. I'm able to do that. So in the output,
let's see what I got. I'm getting the function
1 and function for so this is Bill example
of Hybrid inheritance guys now that we are done
with the type of inheritances. Let's take a look at
what all we have now. So we're going to talk
about the super function guys super function actually calls the parent
class method directly. So let's take a look
at a simple example guys how it works. So I'll just remove all this.

Now what I'll do is I will make
let's say parent class. and give the function
Function One again, the print statement Now what I can do is instead of
calling the parent function from the object. I can just use the super
function and over here. I can just call
the function 1 now. I will just print this is function to let's make
a child class object. Now, let me see if I can call the function
to or function one. I can do that. So I'm going to call
the function to eyes. Let's see what the output
will be some actually able to call the function one directly from the super
function over here.

So this is the function
of super function guys. It can directly call
the parent method and now that we are done
with the super function. Let's take a look
at the next topic that we have which is
method overriding in Python. So method adding
can also be achieved to change the functionality
of the painting class function. So let's take a look
at an example. Understand how we
can actually achieve method overriding in Python guys. So instead of
naming them separately. I'll just name them as same so when I create the child
class Constructor and if I call the function now, okay function 1 which is so when I'm calling
this function technically, it should call
the parent function. But what happens is
it overrides the parent method? Okay to specify
this run it again. Now, I'm getting the output
as this is function to even though I'm calling this function 1 which should be ideally
calling the parent function, but it is printing
out the function which I have specified
in the child class so this is how I have overridden
this parent class method and this is how we can perform
method overriding in Python guys in this session let me walk you
through on how you can learn and make use of exceptions in Python guys this session
is intended to be useful for anyone considering to kick-start their
learning about Python and need some insight
on how you can go about making use of ins to make
coding very easy for you so the focus is basically
on approaching the language in the easiest way
possible and to find out what it has to offer to
the community and all of the learning enthusiasts
out here so let's begin by checking out the agenda for the session will start
by checking out why we need exception handling first
later we'll check out what an exception
actually means followed by that we'd be walking
through the entire process of how we can handle an exception and lastly we look at
how easy it is to code with python Where will take
a programming approach and learn the concepts
through code now that we're done with the agenda
without further Ado.

Let's begin by checking out why
we need exception handling well to understand the concept. Let me quickly walk you
through a very simple scenario consider the case where you're dividing any number
by 0 what will happen. Can you divide a number
by 0 you cannot correct? But how would a kid approach
this problem the kid would think that you can actually
use regular division to divide something by 0 so you do. Dividing something by nothing. So it stays the same something like this right little
does the kid know that this is wrong now check out how a programmer would approach
the same concept. Well, it is established
that dividing by 0 is not possible mathematically so as programmers we know
it is not correct.

So this basically leads
to two cases either an exception or an error so a Python
program terminates as soon as it encounters
an error well in Python and error can be
either a syntax error or an And it is as simple as that. Well, let us actually divide
by zero for fun guys. So this is what happens
in python python presents us with this beautiful
error message saying that it cannot divide
something by 0.

Well, in fact, let us head to pycharm
which is my ID for coding in Python so we can actually
walk through this practically. So guys here I am in my pycharm. So let me quickly go and type out some simple
code for you guys. So let's start
with y equal to 10. We can actually
print y by zero now, so let me quickly go around. Run this in the console.

So as you can check out that says zero
division error division by zero is not possible. So you cannot divide
anything by zero. So let's establish that at this point is
that was good enough, right? So let's get started. Then let us quickly check
out what exception handling actually is well guys
to get a clearer picture of what that is. We need to start with
understanding the definition for both exception
and exception handling. Well, what is an exception guys
an exception is an event. which occurs normally during
the execution of a program that disrupts the normal flow
of the program's instruction so instead of the program
actually executing evenly and nicely there is
actually a disruption in between the curve so
this we basically call as an exception so next what is exception handling guys
this is the process of actively responding
to An Occurrence of an exception as simple as
that so basically the process of responding to the occurrence during compilation
of exceptional statements which requires special
processing is actually what as exception have been guys so this is basically done
because of the change in the normal flow
of the program execution well it is a very simple concept and I'm sure at the end
of this session you guys will agree
well at this point what do you think of exception
handling in Python guy's head to the comments section and let
me know what you think so we can interact there and now that we know what exception handling is
we need to understand how the entire process of exception handling works
so let us take it out first let us walk through what happens in Python so let us say
the user makes an error what happens next When
you think about it is either the user
that finds out the error or python will actually tell
you what the error is, correct.

So once you know what
the error is and you know, where it is, you can basically start
analyzing it to know if it is fixable or not. Well if it is fixable, how can you go
about doing that? Well, if it isn't nothing
to worry guys python is so good that no matter
on what level you mess up. There is always a way
out of it guys. So now if it's fixable, how can we handle the exception check out
the image on the right side, so we need Need
to First find the error if we cannot do it
by then we'll find out for us. Well, next is to make sure
you take caution while coding if you think that there is going
to be an error in that particular piece of code.

Well remember the word try
at this point. All right, and later
will actually fix the error and we call this as catch. This is remember the keywords
for now and we'll be walking through these in detail
in the following slides. In fact, let us Begin
by checking it out right now. So Guys, these are some
of the important terms that you need to take a note
of before starting to code and standing exceptions so
first we have try we'll try is basically the key word which is used to keep
the code segment under check so whatever code you put
under try is actually the code under scrutiny guys and next we have except well
except is this segment which is actually used
to handle the exception guys so how do we know
that the exception is occurred if our piece of code
in the try block has actually caused an exception then we
can handle it in the exact block and how do we use else well
else is basically run when no exceptions exist guys and lastly we have finally
finally we'll run the even if there is an exception finally will run if there is not an exception as
well so I want you guys to note this at this point of time and this will help you a lot
in the coming slides guys so not coming back
to python this is what at visually looks like we first have the try block
where we run a piece of code and next we have the except where the code
actually runs only when there is an exception
in the try block and if there are no exceptions
then we run the else block guys and lastly no matter what exception or
no exception We Run The finally block
always guys Sounds simple right? Well, it actually is another
we are familiar with the process of exception handling.

Let us check out how we can go
about understanding this using python practically guys. Well syntax errors occur when the parser detects
an incorrect statement will check out the tiny arrow
on the left side here. Well, this is
basically to indicate where the parser ran
into the syntax error. Well in this particular example,
there were too many brackets, right so there was
an extra closing bracket. Well, if you actually
remove it and run it you'll actually get a different.

Her this time we'll check on
the right side part of the code. Well this time you actually ran
into an exception error. Well this type of code occurs
whenever syntactically correct python code results
in an error guys. So the last line of the message
indicated is what type of an exception error that
you actually ran into well in this particular case. It is 0 division error
and it says that the integer division
or modular by 0 is not possible.

So this is basically
the same case that I showed you in pycharm awhile ago, but instead of
showing the message, Error python details what type of exception
error was encountered? Well, as I mentioned
in this case, it was a zero
division error, right? Well python comes with various built-in
exceptions as well as the possibility to create
self-defined exceptions as well. And now that we
are clear with that. Let us check out how we can go about raising
an exception on our own so we can basically make use
of raised to throw an exception. If a condition occurs, the statement can
be complemented with a custom exception. Well, if you want
to throw an error when a certain Condition
occurs using race. You can actually go about it like the
following piece of code. You actually see on the screen and when you run
this piece of code, you'll be greeted
with the following output guys. So it says exception X2
not exceed 5 and the value of x was 10.

So let me quickly
jump back to Python and we can execute this there. So guys, I'm
in my pycharm right now. So now quickly typed out
the code for you guys. So let me quickly go
ahead and run it and we can check out the error as you can see it's as exception neck
should not exceed 5 and the value of x was 10. Perfect, right? So let's quickly jump back to the presentation
to check what's next. So the program basically comes to a halt and displays
are exception to screen. Right? So this basically offers clues
about what went wrong and now that we're clear with that we
can actually proceed to checking out the assertion error guys.

So instead of waiting
for a program to crash Midway, you can actually start by making
an assertion in Python. Well, we assert
that a certain statement as actually met and
if this condition turns out to be true then excellent
the program can continue But if the condition
turns out to be false, you can have the program to throw an assertion error
exception for you guys. Well have a look
at the following example on your screen. Well, this is basically
where it is asserted that the code can be executed
in a Linux system guys. So if you run this code on a Linux machine
the assertion passes if you were to run this code
on a Windows machine the outcome of the assertion would be false
and what would happen? Well, definitely the result
would be something like this.

Right. So it would basically present us
with an assertion error and says the did
this code runs only on Right. So I'm using a Windows desktop
in this particular case. So let me quickly
open up my pycharm and then we can actually run
this piece of code to check out our exception guys. So I'm back in my pycharm and
I've typed out the code guys. So let me quickly go
ahead and run this as you can check out
since this is a Windows machine. It says this code
can run on Linux only but this particular case
this assertion would be true. If you are actually running this
on a Linux machine base. So if any of you
guys are using Linux machine, make sure to try it out
and on that note. Let's quickly come back
to the Presentation-wise well in this particular example throwing an assertion
error is the last thing that the program
will do the program will definitely come to a halt
and it will not continue guys.

But what if that is
not what you want what if you want something different from this or that you
want the program to continue while displaying an
exception for you guys when other we actually have
a fair idea about how we can go about understanding exceptions. Let us Dive Right Into the Heart
of exceptions now. Yes, I'm talking about the try
and except block guys. So basically the try
and except block and pie.

Is used to catch
and handle exceptions. Well python basically executes
code following the try statement as a normal part
of the program the code that follows the
except statement is the program's response to any exception
in the preceding. Try glass guys. Well, as you saw
in the earlier examples that I actually showed you when syntactically correct code runs into an error python
will throw an exception error and this exception error
will actually crash the program if it is unhandled guys. So the except Clause determines how your program response
to these Exception guys, so instead of actually
crashing our program. We can actually tell python what to do when this
particular exception occurs. We'll check out
the following function guys. So this function can basically help us understand
the try and the except block while the Linux interaction
function can only run on a Linux system. The assert in this function
will actually throw an assertion error exception if you're using it or any other operation system
apart from Linux. Well, we can actually
give this a try in Python.

So let me quickly open up that
so as I'm quickly or my pycharm, so let me quickly go. and select this and run
it well this won't say anything right now because well if it was actually
a Linux platform the message would have been printed right so let's quickly jump back
to the presentation so basically if we run the tiny piece of code
you see on the bottom the way we actually handle the error
in this particular case is because we gave out
a pass right well if you were to actually
run this code on a Windows machine you
would get the following output which is already on your screen
right so it is a blank output you get nothing well
the good thing here is that the program
actually did not crash – but it would be nice to see if some sort
of exception occurred when you actually
ran your code well to this end you can actually
change the pass into something that would generate
an informative message like this check it out so let me quickly go ahead
and run this and pycharm But as you can check it out
at just the Linux function was not executed.

Right? So basically this happened because I am
on a Windows machine guys. So let's quickly go back
to the presentation and guys when an exception occurs in a program running
this particular function, the program will continue
as well as inform you about the fact that the function call
was not successful. Well what you did not get
to see was it the type of error that was actually
thrown as a result of this function call guys. So in order to see
what exactly went wrong you would need
to catch Catch the error that the function through well
check out this particular piece of code I have for you guys.

So here is basically where we actually capture
the assertion error and we print the output message
to the screen. So we have a try block. We have the same function and we
have except as error, right? So we're going to print
what type of an error it is followed by
a message for us, right? So running this particular case on a Windows machine will
actually give us this following output device such as function
can only run on Linux system and whatever you have chosen
in the print block is actually being printed for us. So let me run this in pycharm
says And check it out. We have the
message printed, right? So it was the same
as I told you. So it was the same message as I told you before heading
back to the presentation. Well in the previous example, we actually called a function
that we wrote ourselves, right? And after that when we
actually executed the function, we caught the particular
assertion error exception and then we printed
on the screen.

Well I have for
you another example where you actually
open a file and use a built-in exception guys. In fact, let us dive into pycharm and we
can actually run this and we can come back
and take a look at the output. So guys I actually came into pycharm and I actually ran
that particular piece of code. Why does it say
could not open file log? Well guys, basically if the file DOT log
does not exist. The block will give
you this output, right? So it says the file
could not been opened. Well, this is an informative
message and our Python program is actually still able
to continue to run. It has not crashed. Right? Well actually in
the python documentation, you can see that there are a lot
of built-in exceptions that you can make use
of and here is one exception that I have for you guys
that you can check.

Out so the exception file
not found error. Right? So basically this
is raised when a file or directory is requested, but that doesn't actually exist
and this is just one among many that python offers to us guys. Well to catch this type
of an exception and to print it on the screen
you would actually use this following piece of code guys. So in the try block, we actually going
to open it as file and we're going to read
something present in it guys. We're going to accept it
by pushing a file not found error as an object and later. We actually end up printing
that object right? So let me quickly go
ahead into pie. Um, and we can check it out. Well as you can check it out
we have error number two, which is no file
or directory, right? So it's perfect. Well, you can have
more than one function call in your try Klaus actually guys and anticipate catching
various exceptions as well.

Well a thing to note here is that the code in the try Klaus will actually stop as soon
as an exception is encountered but there is one important thing that I want you guys to know
down as that while catching an exception it basically hides
all of the errors guys. Well, definitely there are
some unexpected errors in your program, right? You're catching an exception. And even these are completely
hidden from you. Well, this is why basically
you should avoid using bare except statements Clauses
in your python programs guys. So instead basically, what you can do is you can refer
to the specific exception class that you want to catch and then handle those
particular exceptions guys. So look at this following piece
of code I have for you. So you are basically
you first called Linux interaction function and then later actually
try to open a file guys.

So let us quickly jump into Python and we
can actually check it out. So as you can see I actually
Looted the program guys again, if the file doesn't exist
running this code on a Windows machine
will give you their output. Right so it's basically says that the function can will run
only on a Linux machine and then we have actually
printed something guys. Well, what we actually
did here is inside the try Klaus we directly ran
into an exception immediately and will not get to the part where you actually
try to open our file or log right now. Basically when you actually
run it on Linux machine, it's going to says no file or directory found
check it out here guys. So this is the windows output that you get and this is
the Linux output guys. This point let's take
a quick break and check out what are the key takeaways
of this particular module guys.

So basically a trike loss
is executed up until the point where the first exception
is encountered and inside the except clause or the exception Handler what we basically called
we can actually determine how the program actually should respond
to that particular exception and we can actually
manipulate multiple exceptions and differentiate how the program should respond
to each of them. Right? And lastly. We actually learned why
we should avoid using their exit Clauses guys, and now that you're clear,
With this next up I have for you is the else Clause guys. So basically in Python
using the else statement, you can instruct a program
to execute a certain set of code only in the absence of exceptions guys will check
out this following diagram on your screen. So basically in the Tripod, we have the code except
when we actually want to handle the exception or else
in case there is no exception. We're going to run
the piece of code that comes in under else guys.

So let me quickly walk you
through the code guys. So here is basically the same
Linux interaction function. We have an associate editor here and we actually are going
to print the error right so else if there is no assertion error. So we're going to
have an else clause and we're going to print saying
executing the else Clause right? So let me quickly open up
my pycharm and we can run this piece of code guys. So as soon as I go ahead and run
this it says function can only run on a particular
Linux system, right? So as you can see
how the output is the function can run only
on Linux systems, right? So in this case,
I have a Windows machine. So we are actually not printing
the except Clause here. But if you are running this
on a particular Linux machine, this is the output that you would get guy
such as doing something and executing the else class.

Correct? This happened because of
the program did not run into exceptions any
exceptions, right? So else Clause
was actually executed. Well, you can actually
try to run the code inside the else clause and catch possible
Exceptions there as well. Well again, we have the same Linux interaction
you are we going to print it. So the Linux output
says doing something and no such file
or directory found. Well, this is basically
for the else clause and we using the same
file example here, but then we're actually
trying to catch an exception in the else block as well.

So the output is pretty much
straight forward as well. Right? Well from the output
you can actually tell that the Linux and traction
function actually ran well because no exceptions
were encountered an attempt to open file DOT log
was actually made and that file did not exist
and instead of opening the file. You actually caught
the exception which is the file not found
exception pretty simple. Right and I hope you
guys are clear with all of the concepts that we
discussed on till now and next up. We need to check out
how we can actually use the finally Clause guys well
to begin with imagine that you always had
to implement some sort of action to clean up
executing your code guys.

Well python basically enables
you to do so using the finally claws have a look
at the following example guys, check out the workflow
on your screen. I'm pretty sure we're
all familiar with try except and else
at this point of time, right? So, this is
the Grand Lodge Order that you need to go into first. You have the try to check for an exception then
we actually handle if there is an exception
using the except or else if there is no exception. We're going to print whatever is
there in the else block and lastly we have something
called as finally guys. So no matter what we are going to execute this in case
of there's an exception. The finally block is going
to run in case there is no exception finally block
is going to run there as well. So let us quickly check
out a coding example guys.

So basically this is
the particular code I have for you guys and let
me jump back into my pycharm and we Can actually execute
this so guys I'm back into my pycharm. So let me quickly go
ahead and run this well as you can check it out. It says the function
can only run on Linux machines. This is because I'm
on a Windows machine right now and no matter what right so exception
or no exception we have this message which is
cleaning up irrespective of any exception guys. So this is basically
the use of finally guys and that is as simple as it gets so it's pretty
much simple, right? Well try except else.

Finally all of this is
a really simple concept. And once you understand
what it actually does, you can go about doing
a lot using python guys. Well, no matter what
the python application is. There is a very good chance that you'll actually make use
of exceptions guys. Well on that note, let me quickly summarize
the entire session for you guys. Well in this session we
cover the following topics will basically we started out with the introduction
to exception handling and later.

We looked at why we
actually needed right and then we checked out
the following concepts in the screen. So we checked out a raise
which I doubt I answered which I doubt try
which I thought except. Else and finally
guys, well guys, I would suggest you
actually take a screenshot of this right now or take a note of all
of the keywords and how you can use
them in Python guys. So this will actually
take your really long way and your python career and knowing exceptions in Python
is always an upper hand when you're coding guys..