Hang tight while we fetch the video data and transcripts. This only takes a moment.
Connecting to YouTube player…
Fetching transcript data…
We’ll display the transcript, summary, and all view options as soon as everything loads.
Next steps
Loading transcript tools…
Python Full Course For Data Engineers [6+ HOURS] | Ansh Lamba | YouTubeToText
YouTube Transcript: Python Full Course For Data Engineers [6+ HOURS]
Skip watching entire videos - get the full transcript, search for keywords, and copy with one click.
Share:
Video Transcript
Video Summary
Summary
Core Theme
This comprehensive Python masterclass is designed for aspiring data engineers, covering essential Python concepts and their practical applications in the data engineering domain, with a focus on interview preparation and real-world scenarios.
Mind Map
Click to expand
Click to explore the full interactive mind map • Zoom, pan, and navigate
In this 6 hours long Python master class
for data engineers will cover Python
variables, data structures, list
comprehension, conditionals in Python,
iterables and infinite loop, dynamic
functions, lambda functions, classes and
objects, static and instance methods,
exception handling in Python, single
level, multi-level and multiple
inheritance, getters and setters in
Python, request module to fetch API
data, parallel processing using
multi-threading and much more Python is
the most important skill that you have
to master if you want to crack data
engineering interviews and you know what
Python is widely used in so many domains
and you need to understand what to cover
and what not to cover. So that is why
this complete guide will tell you
everything you need to know for data
engineering and do you know the best
part this course has covered realtime
scenarios that are strongly aligned to
data engineering directly. So if you
want to master Python and want to crack
multiple data engineering offer letters
in 2025, then let's get started with
this amazing
video. So what's up? What's up? What's
up my data fam? Happy Sunday. And
finally, finally this video is here. Uh
or I would say this master class is
here. This masterpiece is here. I
received so many requests for this
video. Python, Python, Python and I can
say that in today's era, Python has
become much more important and if we
just talk about data engineering domain,
Python is the I would say only
programming language that you should
learn as your like top priority. You
will say Scala is also there, Java is
also there, blah blah is also there.
Python will be at the top. Will be at
the top and is is on the top. So basically,
basically,
Python is such a wide programming
language. So that means they have so
many use cases. Python is widely used in
so many other domains as well such as
software engineering, web development,
data analytics, data science like so
many other domains as well. Right now we
as a data
engineers need to learn Python smartly.
So basically if you are just getting
started with data engineering or even if
you are a data engineer maybe you are
not much familiar with Python concept
that we need to understand from the data
engineering perspective then obviously
this video is for you. If you are
totally a beginner this video is for
you. If you have like you can
say good years of experience till this
video is for you. Why? Because we going
to cover so much amazing stuff in this
video. Let me just give you some hints
for those who are very pro. So we going
to just cover multipprocessing, multi-
threading and all. So now you know like
what I'm talking about. Okay.
So this video will start from zero.
Okay. And this will go like this
exponentially. And the most important
part that you should know about this
video is um obviously Python has so much
to discuss and I would say it is
neverending topic because the moment
you'll be just about to cover all the
topics there'll be a new update new
library new update in the existing
library. So what we going to cover in
this video? You should know the agenda.
We going to cover Python concepts which
are which are the most important
concepts in the data engineing domain
which are
non-negotiables. Obviously we going to
cover much more than that but we will be
purely focusing on Python for data
engineers. Python for data engineers. So
do not say like hey this part is
missing. Hey this topic is missing. No,
we going to cover which are more
important or I would say the most
important non-negoti sorry
non-negotiables for data engineers. Got
it? This is the agenda of this video. So
that is why the title is Python for data
engineers. Make sense? And I know there
are so many tutorials for Python in
YouTube and they are really really
great. I'm not like denying but there
was a need to just create a kind of
master class for Python just for data
engineers like what things you need to
focus more on what things you can just
neglect what things are like little bit
less important from data engineers
perspective what things are like the
most the most the most important now uh
you will be like we are all charged up
an Lamba now obviously we going to learn
Python for data engineer So do we need
any kind of prerequis? The answer is no.
The answer is no. Yes, we'll be starting
from the zero. Yes, we'll be just
leveling up very very very rapidly
because you are a data engineer and you
need to learn the main things instead of
just like devoting more time on those
things which are not directly related to
your domain. Right? We going to learn
multi-threading and all everything.
You'll be like what is multi-threading?
Don't worry, don't worry. Don't worry.
Everything will be crystal clear for
you. And the best part we do not even
need any kind of installment for this
really installment installation sorry we
do not need any kind of installation for
this. Why?
Because we have so many online Python
compilers. So we can easily use those
compilers because this will save you a
lot of time to just get started
immediately because whenever you're
learning something new you do not need
to waste your time in the installation
of something. just get started quickly
so that you will just catch the momentum
right once you have that momentum you
can just install so many things and
that's what we will be also doing so
first of all you will just get started
with the online compiler and at the end
I will just show you some things which
are let me just give you some hints we
will just focus on OS module as well
which is like operating system module in
Python library which is really important
for you as a data engineer so for that
obviously you would need like local
python uh interpreter but that is like
um will be discussed at the end of the
video. Okay. So to get started we going
to use our online Python compiler and
uh you can use any online Python
compiler also like I use like any random
compiler as per the link that I see on
the top that's it because all the Python
compilers are same not compiler because
Python is an interpreter okay so because
it interprets the code like line by line
so you can use like any online Python
interpreter and you will be good okay
there's no you can say Uh I'm not
inclined towards any one or two Python
compiler interpreters. You can use any
one. Okay. So without wasting any time,
let's get started with the Python. And
obviously we going to we not going to
just start with with hey, what is
Python? Hey, who started Python? Hey,
when was Python launch? No, we going to
we we are data engineers. We going to
just get started with the actual thing,
right? Let's get started with Python.
Let's write our first code. Let's see.
In order to get started with any online
Python interpreter or compiler, you
simply need to go on Google and simply
say write online Python compiler, you
will get a lot of links. Okay? And
again, I'm not a fan of any particular
one. I'm just fan of an interpreter or
you can say compiler. So, I will simply
click on the very first link that I'm
getting on the screen. You can also like
click on the any link. Okay? Because all
are just interpreters. You just need to
write the code. You will simply see the
output. That's it. Okay? So I'm simply
click on clicking on this. Okay. Oh,
perfect. This UI is good. Okay. I like
like black UIs for programming. So this
is our interpreter or you can say
compiler. Um again I will just remove
your confusion like what is a compiler
and what is an interpreter like why we
call Python as you can say interpreted
language instead of compiled language.
You will get to know don't worry. So
first of all let me just tell you this
is our compiler. Okay, let's call it as
compiler. You will like why why why is
this different? So basically in other
languages like C, C++ all are like uh we
use compilers to compile that. Okay, so
now this is your area. Okay, here we
will just writing our code. This is the
area where we will just write anything
any program that you want to build. This
is the output. Whatever we will be
writing we will simply say it here.
Simple like parallel screens screens I
like it. So I think it is the perfect
compiler or you can say um interpreter
that we got luckily um like most of them
are like same. So it's up to you. Okay.
So this is the thing and you can see a
lot of languages here JavaScript R HTML.
So we are not covering that. We are just
covering Python. So simply select this.
Maybe you are just selecting this one
and you are saying hey my code is not
working because you are just running R.
So simply click on Python. Okay. And now
you can even switch the colors. I think
this button is for yeah toal light mode.
You can simply pick this. I like black
color. So I will simply pick this one.
So now I can simply expand the screen as
well. Like I think this is for
expansion. Yeah. Enter because lot of
you can say compilers are same. So
simply expand it. Yeah. Perfect. Now our
screen is expanded and this is our area.
Perfect. So basically let's get started
with the code and let's write our first
code. Let me remove everything. I still
remember those days when I started with
Python. Actually uh Python
was you can say a kind of entry point
for the data domain for me and I still
remember those days. Um I started
writing Python on my mobile phone
because I didn't have the laptop at that
time. So what I did I installed a Python
interpreter using Play Store on my
Android mobile and I was simply writing
the code. I was feeling so happy when I
was just seeing the output. I was like
okay okay this is the thing. Then I
think later I attached the keyboard to
my phone and I was just literally
writing the code on my mobile phone and
I think yeah yeah
um that's a long story and I would
prefer sharing that story on TEDex stage
instead of like this. So just wait for
it. Just wait for it. Just wait for it.
You'll get to know everything what
happened, how happened and everything.
Okay. So first of all let me just tell
you the first code that is very popular
code that you will write in Python if
you are learning. Okay. And what is that
code? The code says print command
because you will be just writing
something in any programming language.
Today we are covering Python. So
whatever you want to let's say print or
whatever you want to display to your
customer or even to yourself. So we have
a function called print or you can say
we have a command called print. Now when
you write print you need to just use
these braces and within this whatever
you want to print let's say I want to
print a string called hello world which
is very popular in all the programming
languages but today we'll be just
printing hello anal lamba or you can
simply pick your name as well. So how we
can just do that for string? Obviously
uh we know that we need to simply
encapsulate it in the double quotes. So
we will simply do that and I will simply
say hello anal
lamba. So this is the thing whatever I'm
writing within this print command it
will be displayed on the output. It will
be displayed on the screen to the user.
Simple. So let me just click on
run. Oh perfect. You can see that hello
an Lamba whatever I put it here in the
print command it is here and it is
saying code execution successful which
is just a kind of log that you are
getting. Okay, this is super super super
useful. Now let me just write one more
print command. Okay, let's say I want to say
say print
print [Music]
[Music]
hello. Okay, let me just run this. So
what it will do? It will first execute
this one and this one. Really? No. So
basically whatever you write in this
area, this will be treated as one
program or you can say one py file
because the extension is py for python
file. So it will be treated as only one
py file. And you want to see what is the
name of that py file. It is called main.
py. Who created it? Not us. it is
already there by the online compiler. So
whatever we are writing here behind the
scenes it is running our main py like
this. So whenever we go to terminal we
simply write uh python then we simply
give the location of that file. Okay the
full path and if you're just running
from the existing directory you can
simply name it like main. py make sense.
So you can simply provide this thing. So
behind the scene whenever I just click
on run button it is doing this thing and
it is giving me the results. So whatever
I'm writing it here in py file I am just
seeing it here on the parallel screen.
When you install this particular you can
say setup on your local machine. You
will see the same stuff but you do not
need to every time say hey python
main.py because we rarely use terminal
to run our python scripts. We simply use
run command that we get with the help of
any code editor. What is the most
popular code editor? VS code editor.
Okay, I love VS code. So we see the
similar U user interface there as well.
But you should also know the basic
stuff. It is like if you just want to
run the Python script from the terminal,
you can simply write something like
this. Python and then main.py. It will
simply run your Python script. Make
sense? Make sense? Makes sense. Now let
me just tell you like how our code is
being interpreted. Let me just tell
you happens when you run a Python
script. Okay, this is like very
fundamental knowledge and you should
have this knowledge. So there are
basically two steps involved. Okay, the
first step is whatever we write in the
code, it will be first compiled to pite
code. But Anlama, you said like it is
not a compiled language. Yeah, but not
completely. Basically whenever we run a
Python file or you can say py file
python first compiles the entire script
entire script that means whole dot main
like main py okay into an intermediate
form called byte code. So it will be
converted into byte code the whole code
the whole script. Then that bite code
will go to the Python virtual machine or
you can just take it as a kind of uh
interpreter. Okay, Python interpreter.
Then the bite code is executed line by
line. It will not be executed like the
whole code. It will be executed line by
line. This part happens during runtime.
This is why Python is considered as an
interpreted language because it will be
interpreted line by line the whole byte
code. But yes, it will be compiled to
the bite code first. Make sense? Make
sense? Whereas in the other languages
C++ C, it is not an interpreted
language. It will be simply converted
into bite code and then into the machine
code. Make sense? That is why those are
like pretty much faster. But yeah,
Python is very much popular and Python
is performant. Python is reliable.
Python is taking over like with like it
is like well integrated with all the
modern AI tools and everything. So that
is why but C++ C those are pretty much
fast very fast like because it is
directly converting the code into
machine code and they are just running
locally they do not need any kind of
interpreter and all they are really
really fast they are really fast that's
why in the data engineering space as
well you are seeing something called as
photon in data bricks okay you are
seeing native executors in fabric those
are all built on C++ libraries using
Apache gluten and there was one thing more
more
um I forgot the name of the library the
one package is apache gluten and second
one I I I don't remember right now but
yeah those are just using your C++ as
the base okay that's like additional
knowledge but you should have that okay
so now you know like what's happening
behind the scenes now let's focus on the
code only because now you are well
versed with all the fundamental things
as Let's see. So I hope now you
understood like how we are just running
our Python file behind the scenes. Okay.
So this is different from C++ C
languages because again like those are
directly being compiled into machine
code and operating system can understand
the machine code right but in this case
you need an interpreter which is Python
virtual machine to understand your byte
code and then it will simply interpret
it line by line line by line and it will
simply uh give you the output that's the
only difference and let's now try to
master print statement first of all so
basically there are some things that you
can just do. So you will simply say hey
Anla can we also include let's say um
something other than string something
other than string. Yes you can just do
that. So basically let's say you want to say
say hello
hello
lamba. Okay. And now you just want to
include something else within the same
print statement. You can do that using a
comma. Okay. If I just do this, comma, I
can say hello lamba
lamba
one like this. Okay, I just want to do
that. Simply hit run and let's see what
happens. And if you just want to clear
your output, you can simply click on
clear and then simply run fresh. So you
will simply see hello an Lamba and then
one. Make sense? Make sense? Make sense?
So this way you can actually combine
multiple things and then if you again
want to add a string, you can simply do
that. Oops, not here. Here you can
simply do that. Let's say hello an
Lamba and then simply run it. See, you
can actually combine these things. Okay.
And you know what's the best thing? Let
me just look at the checklist that I
have made for you. The long chest check
checklist checklist. [Music]
[Music]
Okay. Let's cover this. This is very
very special and I I personally love
this. So
basically you will simply say hey anal
lamba what if we want to separate this
thing using a
delimeter example we know that we have
first string as hello and slamba then we
have second which is integer then we
have third. Is there any way that we can
actually add a kind of delimeter so that
we will know okay this is the first
value this is second this is third yes
you can actually do that so we have
something called as just add comma and
then say separated equals to and then
just type your delimter let's say I want
to add delimter called um dollar sign
okay now simply run this and you will
see hello anamba then dollar sign then
one then dollar sign then I love you or
eloop just write anything else. So this
is the way that you can actually create
a separator between your different
different entities that you are passing
within your print
statement. Now why did I write or why
did I use single quote here because I
wanted to make you think. So the thing
is whenever you are using print
statement you have liberty you have
liberty to use double quotes and single
quotes result will be the same. Let's
say this is in double quote. Let's say
this ILU is in the single code. It
doesn't make any difference. You can
simply run it and you will see. See
everything is same. So yes, you have
liberty to use double quotes and you can
say single quotes as well. Now one very
important thing you will say hey an
lamba can we do something like this? Um
let's say let me just create a new
statement. Let's say you are writing
I Hello Anala. This is
XYZ. How are you? Then you will say I
want to go to next line. Okay, I want to
go to next
line. So can we just do that like
something like this?
Um how is your
day? And should we just try run this
because Anela it makes sense right? See
um this is inside the double code so we
are not breaking any rule actually you
are. Let me simply run this. So it will
simply throw an error and you should
know the reason
why. You should know the reason bro. So
the reason is Python interprets the code
line by line. It will simply go to this
line. It will simply say hey what's
going on? you started the string and
where is the ending point? Then it will
go to next line. It will simply say hey
what you are doing man even like if it
will not even go to next line because
this will throw an error. But still let
me just tell you like how you can just
act like an interpreter. So it will
simply say hey in the next line what you
are doing you just started a string
without a double quote. So it will
simply throw an error. So it will simply
throwing an error called syntax error
un terminated string lit. That means
this string literal is not even
terminated here. So we got the error
here. But yeah, I'm just telling you
like what's going on. Okay. So now you
say okay. So you mean to say that in
Python we have to write all the
paragraph, all the text in one line.
Does that make any sense? No. So for
that we have the power of let's say this
is your code. If you want to just use
multi-lines to perform your you can say
anything which are constant right you
just need to write it and you cannot
write everything in the just in just one
line. So for that you simply need to use
three double quotes or three single
quotes. It's up to you. So let me first
use three single quotes. 1 2
3 1 2 3. That's it. Now you can just run
this. It will work. See it will work.
and it will simply give you how is your
day in the next line because it is in
the next line. Okay, you can even use
three double quotes 1 2 3
uh let me just remove it. 1 2 3 and
then 1 2 3 it will also work. It's up to
you. Okay, see I know we are just
covering from very basics but yeah it is
required. So now I hope that it makes
sense. Let's see what do we have next.
Um okay so
let's try to
cover hm now one important thing so let's
let's
say this is also important in the print
statement so let me just tell you that
as well so basically let's say you want
to write something like this hello anal
lamba can you do that let's say you want
to write something like this hello can
you do that
Yes. Yes, you can do that. But let's
remove this. If you are not using three
quotes, if you are let's say just using
single quote and you are just using
single quote here as well. Can you do
that? No. And you can see the error,
right? Because it doesn't know like
which is the main starting point and the
ending point because you are using the
same stuff here as well. But what if
this is your requirement? So we call it
as like escape character. There are like
many options to tackle escape
characters. You can even do like this.
Just add one more single
quote and one more single quote here as
well. Then it will be treated as escape
character. We will simply say hey just
escape this. Hey just escape this. That
means it is helping you helping you to
escape your characters. Okay. If I just
run this, it will simply give you
something like this. Hello an number.
Oh, it didn't put it like that. Yes. And
it should
not it should not. So the best way to
tackle it or you can say the simplest
way to tackle it I just perform this
step. Just change the double quote or
just change the single quote. If you're
using single quote here let's say you
want to uh do something like
this. So just use a starting and the
ending quote opposite of it. Double
quotes double quotes. Simple. This is
the simplest way. Okay, this is the
simplest way or it makes sense and it
promotes readability as well. What's the
other thing? You can even use backslash.
Okay, why do we use backslash?
Backslashes are used to tell Python
interpreter, hey, this is not a
character. Basically, this is not a kind
of literal that we are using. This is
just a constant that we want to use in
our string. So, what you can do, let's
say this is your double quote. Okay,
let's go back to the error view. So this
was the error. Now in order to mitigate
this thing, you can simply write
something like this. You can simply add
backslash like this. Add backslash like
this. Now if you just run this, it will
simply behave like this. So what it is
doing? It is escaping the character
backslash. It is escaping the character.
So it is saying hey I know that it is
using single quote here but you do not
need to treat it as like your normal
code. It is something that is related to
that user only. This is something a
constant. It is not your um defined
literal because in the programming
languages we have defined some meanings
to these characters like single quotes
for string double quotes for string like
this. So it is simply saying hey escape
escape escape this character. Make
sense? Why I'm just covering the string
in detail because in data engineering
domain we work with strings a lot. Let
me just give you a real time example
because whenever you let's say you are
using pispark if you do not know about
pispark pispark is like one of the
leading big data technologies that we
use. So in that we oftenly use like uh
paths storage path cloud urls and all.
So for that you need to make those URL
paths dynamic. you need to include uh
even functions in that. So for all those
purposes you have to use string you have
to just master strings and obviously we
are just trying to cover a lot of stuff
through print statement so that you can
actually see those things with your eyes
make sense. So this is not just your
print command. Do not say like why we
just covering print command in detail.
No, we are trying to learn most of the
stuff that are in the string not in just
print statement. Make sense? And there
are like a lot of stuff that we will
just covering uh in the very few next
minutes. Let's say fring. What are
frings? I love frings. If you are just
working with cloud urls, fstrings are
like the best thing that we have. And we
have indexing as well. So we will just
cover all these things. But now I know
that you have built a strong base in
string. you know how to work with like
double quotes, single quotes, multi-line
and all. Now you're good. Now you are
good. Okay. Now let's try to clear
everything and let's start with the
variables. Okay. Let's start with the
variables. Now let's talk about the
variables. Okay. Variables. Yes. Let's
talk about the variables. Basically what
are variables? Variables are like your
containers. Containers. Yes. a kind of
jar in which you can just save something
in you in which you can just put some
value and you can just store it let's
jar not
now okay so let's say this is a
container okay this can be a variable
okay this variable can hold your data or
can hold some value, can hold anything.
Let's say you are putting sugar inside
this. This will hold sugar. Let's say
you are just putting pulses inside this.
This will hold pulses. Let's say you are
just um putting salt. It will hold hold
salt. So that's why similarly your
variables are the same. Let's say I'm
just creating the variable. Variable
name is let's say my variable. Okay. So
I want to store my name inside this. I
will simply say an perfect now I can
access this name through this variable.
If I just simply write print my variable
I will simply see my name an I didn't
say print an but still I'm seeing this
value. Why? Because I have hold or you
can say I have stored this information
inside this variable which is my
variable. Make sense? This is very
simple concept. to not make it
complicated. This is just a variable.
Now you will say, hey, can I store
integer values in this? Can I store
numeric values? Yes, you can store
anything. Let's say I'm saying my where
or let's say uh x because it is very
popular term in mathematics like x
equals to this, y equals to this.
Similar to that one, let's say I'm
storing x= 10. I can simply say print
print
my and x together. And you know like how
we can just do this because of this
comma right let's say see an 10 simple
simple simple simple now let's say I'm
creating another variable
y I will simply say five if I want to
perform arithmetic operations on top of
these variables we can do that really
yes I will simply say
print x + y. Okay. Then I will simply
see 15. Oh, so it automatically
automatically
performed arithmetic operation which is
addition on x and y. Yes, you can do
that. Okay. What if I want to add the
strings? You will say, "Hey, Anchula, we
cannot add the strings." Um, by saying
adding the strings, I'm not saying like
add like real addition of strings. We
can even combine the strings using
variables. Let's say this is my variable
and I'm creating another variable called
last name and I was simply saying lamba.
If I just want to do this, I will simply say
say
variable plus last name. Let's see what
happens. You will see an lamba. So it
has just combined the strings because
obviously we cannot add an into lamba.
But yes, we can combine them. Make
sense? Very good. This is just like
addition of both the things. So what it
did, it simply put an then it simply put
lamba after this. That's it. Now, now,
now, now one very interesting thing. Can we
we
add 10 vidanch? Can we do this? Just
try. So if you just write this print x
plus my variable it will say bro have
some water. What you are trying to do? x is
is
integer. My variable is a string. What
do you want to achieve by combining
these? We cannot do that. We cannot do
that. If we want to do that you first
need to convert this x into string. Then
it is doable. Let's run this. Now you
can just do this because now it is a
string right and it is also string so it
needs like it knows like it will simply
combine both right very good now let's
see what do we have next so don't bother
I was just looking at my checklist so
because I want you to know everything
okay so we have discussed this this yeah
so now let's discuss multiple
assignments multiple assignments let's
say let's clear all this Let's say you
have values. Let's say x = 10.
Oops. x = 10, y = 5, then z equals or z
= to 20. You can just do this. But
there's a better way of doing it. Or you
can say if you just want to reduce a
line of codes, lines of code. So you can
simply say x ya z equ= 10a 5a 20. Really
just run this. Yes, it is successful.
Now what we did, we simply assigned
multiple variables together within
single line. It is called multiple
assignments. I hope that you are taking
notes. Okay, I hope you are taking notes
and if not just start taking notes right
now. Okay, because these are very basic
stuff that we are just going to wrap
really quick and then we going to just
cover like the advanced things and if
you are not taking notes you will not be
able to refer to the basic or
fundamentals. Okay, because we are just
wrapping it really quickly because these
are really basic stuff. These are like
really really basic. Okay. So this is
like multiple assignments and perfect
perfect and one more thing let's say if
you are all the variables have the same
values you can simply say x= y= z = 20
you can even do
this so all the variables will be having
the same value make sense make sense
make sense make sense very simple very
simple very simple so now we're going to
cover comments okay Why do we need
comment? Let me just write a code. Let's
say um let me just undo all the things.
Let's say I'm writing this code. Uh
yeah, let's say this is my code. This is
my code. Okay, it can be my code, right?
It is my code. So why do we need
comments? You will simply say an Ramba
comments are used to describe something
to just help us to review it later. This
is just like eight lines of code. What
do you want to describe it? We can
easily understand what is going on.
Okay bro, you are right. Just imagine
that you are writing thousands of lines
of code. What? Yeah, in real life you
write it bro. So can you understand the
part of let's say you have uh 1,000 rows
of code. Okay or you can say 1,000 lines
of code. Now within those 1,000 lines of
code, you are trying to understand the
line number 20. what that line is doing.
Trust me, you would spend the whole day
and I'm just I think talking like one
day is very less. Uh you would spend
maybe a whole month to figure out like
what is going on because it becomes so
so so complex to understand the code
when you're just reviewing it after a
month after 2 months after 3 months
after 1 year. That's where comments help
us to just tell us, hey, we did this in
this stage, we did this in this line, we
did this in this function, we did this,
we did that. So comments are really,
really handy for you as well and for
others as well. Let's say you wrote your
code and you are a superhum. You just
remember everything. Just imagine like
another developer is trying to read your
code. Everyone's um coding style is
different. Okay, how the person can
actually interpret the code? how the
person can understand like what is
written here. So for that we need
comments. So what I can do for comments
we have multiple option for comments.
Let's say I want to describe that this
is my name. Okay, this is my name. I
#myame. So this will be acted as a
comment. I know it is like really really
light color but yeah um you can even
change the colors but I don't want to
spend time on that one but you can just
actually see see my name. So whenever
now if anyone wants to understand this
code the person will say okay okay this
is his name this is maybe user's name or
anything. So this way you can add the
comments. Make sense? Very good. Now
this is one way of adding comments which
is very handy. Simply put hashtag and
write anything. But you cannot add
comments in the multi-lines. You cannot
extend your comments to the next line
because this will simply perform comment
on the same line only. Let's say you
want to write write at least three to
four lines of comments. So for that we
have another option. Let's say you want
to write comment here. So for that same
thing in uh string we use like three
single quotes or three double quotes.
Same thing. If you simply write here
like this 1 2 3 and then you simply say
comment I
uh I am
statement. So you can just write any number
number
of lines of you can comment then just
close it 1 2 3 that's it. The moment you
did this, this is your comment. You can
write anything between three single
quotes and three double quotes. The
choice is yours. Usually for comments,
we use three single quotes. Okay, so
this is the way to add multi-line
comments. Make sense? And whatever you
want to write it here, you can just
write it. Okay, this is like about your
comments and yeah, I I hope like this is
like pretty much clear. This is again
optional thing but this makes you a good
developer because this is really really
required if you are just trying to make
a user friendly code. Okay, makes sense. So
So
now let's talk about multi-line code.
Multi-line code. Yes. So let's say I
want to achieve something like this. Total
Total sum
sum
equals 10 + 20 + 30 + 20
+ 20 + 10 let's say so many numbers
right and the these numbers are like
taking all of my space okay now what I
can do obviously it will simply turn the
sum print total
sum okay it will simply print the sum
110 very good now you can even do this
thing. Let's say you just wrote your
code 10 + 20. Now you want to go to next
line. You will simply hit
enter. Okay. Then just move it to the
same you can say indentation. Now if you
just try to run this simply run this. It
will simply throw an error. It will
simply say hey what is this? Because
this is fine. This line is fine. But it
will when it will go to this line it
will simply say hey what is going on?
Then you need to tell that this line is
the part of this line. So for that we
use something called as backslash. The
moment you hit backslash this line will
be treated as the part of the previous
line. So backslash allows you to write
your code in multiple lines. Right?
Let's run this. Perfect. Now you are
seeing 110. This is again very handy
when you just write spark code or let's
say Python code for data engineering.
You just want to split your code in
multiple lines. So that's where it it
has become very useful. Another way of
achieving it that I have seen like other
developers use this way as well. You can
simply add a bracket in the at the start
and at the end of this this will also
work. If I hit run, this will also work
because this knows like this is the
beginning and this is the end of the
bracket and whatever inside this is the
part of the same stuff. Simple. It's up
to you. It's totally your choice what
approach you want to use. Right? Okay.
Very good. So this is also done. Now
let's talk about indentation. Now what
is this indentation? And I still
remember those days when my class
teacher used to scold me a lot. An Lamba
what you are doing? Why don't you indent
your code? I was like why I need to
indent my code? Because I back in the
school days u we had a computer lab and
um I was really new to those computers
and all. So C++ doesn't require indentation.
indentation.
No, because it is just like compile
directly. So we can just write our code
within one line. It will just behave
like normal. But in Python we cannot do
that. So I said like why do we need to
indent our program? My teacher used to
say like C. I know it is not important
for C++ but it promotes readability.
Second thing indentation is crucial part
in other languages as well and now I can
feel that. So basically what is
indentation? So I will just write a a
code that you will not or maybe you may
not understand but you will understand
it later just for the understanding I'm
just explaining you the indentation. So
I'm writing a code let's say like this
if x
= 1 then just print
print wow
wow
okay and x equals 1. So if I just run
this, it will work fine. It will say
wow. So what is indentation? So
indentation means I have started this
condition. If condition, don't worry
about that. We will talk about if just
after this. Okay. So it will simply say
if I have started this, you can say
condition. And this is my syntax for if
condition. Then I know that everything
I'll be writing under this will be part
of if condition. Right? This is not a
separate print condition. Make sense? I
know it doesn't make sense for now if
you do not know about if condition but
try to make some sense because once I
will discuss about if it will be very
much clear but try to just grasp the
context of indentation. So basically if
you just do this you will simply say hey
if x= to= to 1 print wow it should work
right really no because it is saying if
x= 1 then what I need to
do okay I'll simply say print wow okay
and then if I just put here wow it will
work it will work see wow wow because
this small wow is the part of this
particular if condition. That means if I
am just writing print right from the
start of the line, it will not behave
like it is a part of if condition. That
is called indentation. You need to
indent your code. You need to just
follow the hierarchy. That means this is the
the
parent. This is its child. That's it.
You need to follow the hierarchy. You
need to have some space before the child
before the child code. Okay, this is the
kind of hierarchy that you need to
follow. Make sense? Very good. This is
all about indentation. So do not worry
about if condition. We will just talk
about if condition as well. It is very
simple. And if you already know Excel,
this should be a piece of cake for you.
But still, I'm just explaining these
stuff because this is really important
from the fundamentals perspective. So
yeah I have to
now now let's talk about type casting it
is really important type casting. So
basically what is typ casting? This is
very fancy term but the meaning is so
simple. Let's say you have a equals to
10. Okay.
And b equals
um 10. Make sense? One is integer. The
second one is string.
If we try
to add these
numbers, can we achieve this? Obviously
no. We have already seen the error. Let
me just show you again. Print a + b. We
will see the error, right? Error.
Perfect. But we can convert this number
into a different type. That means we can
perform type casting something like
this. We can perform
string to integer. Make sense?
We can perform like this string to
integer. Wow. Can we do that? Yes. This
is called type casting. When you are
just converting one data type to
another, that's it. This is type
casting. So how we can just do that? We
have a function called cast. Okay. I
will simply
say first of all let me just show you
how you can see the type. If you are not
sure like what type is this? I know it
is very much evident but sometimes it's
not. So in order to see the type, you
can simply say print type of B. it will say
say
string see class string so it is a
string data type now if you want to just
type cast it okay so how we can just do
that I will simply say b new so I will
simply create a new variable and I'll simply
simply
say cast or you don't need to write cast
so you will simply say integer of
b okay now let's try to see the type of
b new let's
Oops. We need to write
type. Okay. Now let's try to do this.
Now it has converted into
integer. Wow. So whatever you want to
convert, let's say you want to convert
it into integer. You can simply write
this. What if you want to convert this
into string? Maybe you want to just
convert into string. Simple steps are
very simple. Let's say a new. Okay. Let
me just go to the next line. I will
simply say a new
new
equals string of a and let's see the
data type of a. This time you will
simply see string. Wow, perfect. This is
so simple. This is called
explicit type
casting because you are explicitly
telling Python, hey just change this
data type to this. Hey just change this
data type to this. So this is explicit
type casting. We do have something
called as implicit type casting as well.
Like what now? What's this? In implicit
type casting we do not tell that hey
just change this number. It becomes
understood to change that. Really the
very good example is this one. Let's say
you have a equals to 10 b= to
10.5. So now this is a different data
type right? This is integer. This is
float. This is float, right? This is
float. I can even show you print type of
B. Okay, makes sense. Float. Now, if you
just try to perform a plus b, you can
really how? Because this is integer,
this is float. But we know that we
cannot perform at like any arithmetic
operation if both are of different um
data types. But if Python can do that it
will basically both are numeric data
types. One is numeric means like in
numbers. Okay. 10 and 10.5. So it knows
that it makes sense that it will simply
convert this a= to 10 equals to
10.0 10.0. And this will do it
implicitly. That's why it is called
implicit type casting. So it will simply
add 10.0 0 to 10.5. Okay, make sense?
Very good. Very good. Very good. So
every time you do not need to just
perform type
casting. Now let me just tell you that
the string the string actually behaves
as an array. Now what is an array? Array
for the simplicity for now you can
just try to understand if you just want
to understand array. array is like group
of values or if you're familiar with
list, list is actually a defined type
but if you because list is very common
and that can be used in let's say other
things as well not just in programming
languages. So basically if I'm just
writing something like this let's say um
variable or let's say x
equals lamba okay so
actually we can say that it is equivalent
equivalent to
to a
a n
n s
s
h. So each character each character is different.
different.
Oops. Each character is different. So
that's why we can actually treat this
text as an array. Really? Yes. So let's
say you just want to print the first
character of this particular string only
the first character. And we already know
that in the programming languages we
start the counting from zero not from
one. And if you don't know now you know.
So we always start the counting from
zero. So let's say I want to print the
first character. So what will be the
first character? I will simply say x.
And in order to define the index, we use
these square boxes or you can say
braces. And then I will simply say zero.
If I just run this, I should see a
perfect. Let's say I want to get the
next alphabet. I will simply say one. I
will simply get n. So that means I I can
simply perform indexing on top of this
string because this acts as an array.
This acts this behaves exactly same as
an array. The string makes sense. Now
obviously we'll be just learning a lot
about slicing in the lists but you
should have a strong grasp over you can
say slicing concepts and all. So now let's
let's
say I want to fetch the first four
characters. First four characters I want
to fetch a and sh how you can do it
because obviously we know that we can do
something like this x of0 okay we'll get
a then we'll get n
but what if you want to just fetch first
four characters together so it is called
slicing. So how you can just perform
slicing? We have something called as
let's say zero. Okay. Then you will
simply say colon and then whatever your
end number is. My end number is four. So
I'll simply say four. Now you will see
my name an make sense. So how it is
going through each alphabet? It is first
going to a which is zero then n which is
1 then s which is three uh sorry two
then h which is three. So where is four?
So the thing is this four is not
included not included. So every time it
will go till n minus one. So if you if
your uh last number is four then it will
simply perform n minus one and it will
simply give you three.
Make sense? That's how it works for your
strings. I hope it makes sense. Okay.
So, this is your slicing. Let's say you
want to just pick like specific numbers.
Let's say you want to pick only
um numbers from h till m. So, you can
just count the index. You can simply say
0 1. So, a is 0. Okay. So, this is zero.
Let me just expand the screen. Okay.
Perfect. So this is zero. This is one.
This is two. This is three. This is four.
four.
5 6 7
8. Make sense? 0 1 2 3 4 5 6 7 8. If you
just want to fetch H L A M. So what
should be the index? Index should be
three as the starting point
and 3 4 5 6 6 from 3 till 6 but now you
know that we simply go till n minus one
that means you will simply give seven so
that it can include the sixth index so
we'll simply write something like this
three and then six sorry seven you can
simply run it this time you will simply
say c hm
Perfect. Perfect. We even have something
called like this. And this is really
interesting. If I do not specify
anything, what will happen? What will
happen if I do not specify anything? And
I simply specify a colon. That's it. You
will see the whole text. Why? Because we
have a concept here. Let me just tell
you what's that. So if you do not put
any value in the starting point, it will
automatically take zero.
If you do not put anything in the end
point, it will automatically take n as
the end point. Now what is n? This can
be a good question. What is n? n is your
length length of your
string. In our case, what is the length?
Length is 9. So it will simply say x
x
0 colon 9. This will be your past you
can say
arguments and it will automatically feed
that. Let me just show you. If I simply
write zero and if I simply say len of x,
you will simply see the same thing.
Anchel lamba. Now what is this len? Len
is a function that we use with the
arrays to find the length of it. That
means how many elements do we have
within that list or within that array.
And as we just mentioned, strings behave
similar to
arrays. That's it. That's it. Now one
interesting thing. Let's say you do not
put anything here. Just a quick quick
check for you. What will happen? We will
simply see everything. Why? Because it
will simply put zero here
automatically. Okay, very good. Simply
put zero here automatically. This way
you can just slice your text. Whatever
you want to get, whatever you want to
just fetch from the long text, you can
just do this. Make sense? We will just
learn about a lot in around like slicing
in the list chapter. So, do not worry.
Let's see what do we have next? Next, next.
next.
So, okay. So, let's discuss some of the
you can say string methods that we use
on a daily basis. Uh there are so many
string methods. You can even Google and
methods in Python. There are so
many you can simply click on this and
you will see capitalize case fold center
count and code like so many see there's
a long list and as per your convenience
you can just use these functions but
simply just to make you aware how they
work I will simply show some of the examples
examples
but this will be really helpful when you
actually working with Python in the data
engineering projects because this is
something that you cannot Remember this
is something that okay I need to perform
this let's see what function do I have
in Python tuck tuck tuck tuck tuck you
will simply go on Google then you will
see oh I have this function for this
then you will use that because you
cannot remember all the functions so do
not worry you do not need to remember
anything if you want to use let's say
count function if you just want to use
let's say length function you will
simply go on Google hey tuck tuck length
function in strings in Python you simply
need to know the concept that's it
that's That's it. Then you will simply
grab the particular function because it
is not possible to remember all the
functions. You need to remember like yes
we do have a function like this. Yes, we
can just do uh this thing in Python with
this approach. You need to know all
those things but you not need to
remember like all the functions.
Exactly. Because you would be working
with so many languages. Every language
has a different naming convention for
the functions. How you can just remember
all those things? Impossible, right?
Impossible. And we are in the AI era.
You need to just learn things smartly
because what those things are like
easily available in just one click. So
you need to focus on the complex things
now. You do not need to just waste your
time in just getting hey how I can just
use upper hey how I can just use lower.
No. Okay. So let me show you some of the
things. So how you can just do uh where
should I just keep my notebook? Okay.
Here it is fine. So let's cover very
basic stuff which is upper and lower.
Okay. So let's say my name is
number make sense if I just want to
capitalize all the things I will simply
say print X dot
upper. Okay. And it will simply say
anlamine capital. Same with lower. If I
just want to make make it lower, I will
simply say lower. That's it. Simple
simple simple simple in you can say
Excel we have something called as proper as
as
well. So we do not have proper here. So
if you just want to find proper see so
now how I will just approach I know that
we should have a proper function in uh
Python right? So you can simply go on
Google you'll simply say proper string
Python and you can even open this one
but yes you have something called Python
string methods as well. So here you can
simply try to find something called as
like related to string. So these are all
the methods and you can just have a
quick look like what are the functions
available and what I can use here. So
you can simply say format format
specific value in a string. So you can
actually see like what do we have? See
capitalize capitalize like converts a
first character to uppercase. So I think
it should work here. Capitalize. So I
can simply use this capitalize and copy and paste. So you can simply
and copy and paste. So you can simply say x dot
capitalize. Okay. So it will simply make my first alphabet equals to capital. So
my first alphabet equals to capital. So that's how you need to fetch the
that's how you need to fetch the functions accordingly because if you're
functions accordingly because if you're using any other language, you will have
using any other language, you will have another function name. But you know that
another function name. But you know that the purpose is there. We would have some
the purpose is there. We would have some functions available in Python. So that's
functions available in Python. So that's how you need to learn with the
how you need to learn with the requirements. And yes, the more
requirements. And yes, the more functions you would be using, the more
functions you would be using, the more familiar you will be with those
familiar you will be with those functions. We like rarely use these
functions. We like rarely use these functions like upper lower and we use
functions like upper lower and we use upper and lower a lot but not
upper and lower a lot but not capitalized alone because we are not
capitalized alone because we are not designing a website. We are just simply
designing a website. We are just simply using those function the joining key. So
using those function the joining key. So we use upper lower a lot. Okay. So next
we use upper lower a lot. Okay. So next we have a very good example. It's called
we have a very good example. It's called replace. So let's say I want to replace
replace. So let's say I want to replace something within this text. How I can
something within this text. How I can just do that? So I'll simply say I will
just do that? So I'll simply say I will make use of replace function. What it
make use of replace function. What it will do? As the name suggest it will
will do? As the name suggest it will simply replace something. Let's say I
simply replace something. Let's say I want to replace print x
want to replace print x dotreplace and I want to replace h with
dotreplace and I want to replace h with let's say z. Okay, let's see what we
let's say z. Okay, let's see what we will get. I will get uns
will get. I will get uns lamba. So actually you can perform
lamba. So actually you can perform replace function like this if you just
replace function like this if you just want to replace anything within the
want to replace anything within the string. How it is possible? Because it
string. How it is possible? Because it acts and it behaves like an array. What
acts and it behaves like an array. What if I want to replace two things? Let's
if I want to replace two things? Let's say I want to replace sh with Z. Can we
say I want to replace sh with Z. Can we do that? Yes. And
do that? Yes. And lamba. So we can do that. It is
lamba. So we can do that. It is possible. Okay. Now what do we have?
possible. Okay. Now what do we have? Yeah, this is really important. This is
Yeah, this is really important. This is really important because this is
really important because this is something related to list and for data
something related to list and for data engineers list is very important. So
engineers list is very important. So basically let's say you have this an
basically let's say you have this an Lamba and let's say um this is my
Lamba and let's say um this is my nickname at home. um let's say these
nickname at home. um let's say these three things. Okay. So
three things. Okay. So basically what if I want to split all
basically what if I want to split all the things within the string based on a
the things within the string based on a delimeter let me repeat let's say this
delimeter let me repeat let's say this is one entity an this is second entity
is one entity an this is second entity this is third entity and I know this I
this is third entity and I know this I want to separate this and I want to
want to separate this and I want to store it how I can do that there's a
store it how I can do that there's a function called split so what split
function called split so what split function does split function will
function does split function will automatically split your string based on
automatically split your string based on the character that we will define and it
the character that we will define and it will simply store all the items within a
will simply store all the items within a list within a list. Let me just show
list within a list. Let me just show you. I will simply say uh my list equals
you. I will simply say uh my list equals I will simply say x do.split and now on
I will simply say x do.split and now on which telemter you want to split the
which telemter you want to split the values. Here we have a special
values. Here we have a special character. No, we cannot see it. You can
character. No, we cannot see it. You can see it. Space is
see it. Space is also a delimeter in Python. Okay. So,
also a delimeter in Python. Okay. So, we'll simply say space. That's it. And
we'll simply say space. That's it. And let me just print the list. Don't worry,
let me just print the list. Don't worry, we're going to cover list next. But you
we're going to cover list next. But you should have some basic understanding
should have some basic understanding like about list. List is just like
like about list. List is just like holding your all the items. Okay. So,
holding your all the items. Okay. So, let me just run. See this is a list.
let me just run. See this is a list. list is having all the things like my
list is having all the things like my name, first entity, second entity, third
name, first entity, second entity, third entity. This is a list. So this way you
entity. This is a list. So this way you can actually convert your string into a
can actually convert your string into a list based on a delimter. And here space
list based on a delimter. And here space is the
is the delimer. So we have like a lot of
delimer. So we have like a lot of functions as well like other than these
functions as well like other than these and string we have let's say r strip.
and string we have let's say r strip. Let's oh yeah ends with first first I
Let's oh yeah ends with first first I will just cover ends with and starts
will just cover ends with and starts with it is very important for data
with it is very important for data engineers. So let's say you have because
engineers. So let's say you have because we use these things when we are just
we use these things when we are just trying to read some data from the files.
trying to read some data from the files. Let's say you have a file like this um
Let's say you have a file like this um raw
raw data dot CSV. Yeah, let's try to just
data dot CSV. Yeah, let's try to just use our own analogies because we are
use our own analogies because we are just covering it for data engineering.
just covering it for data engineering. Let's say you have something like this.
Let's say you have something like this. Let's say file name file equals raw data
Let's say file name file equals raw data dot csv. But you need to only read this
dot csv. But you need to only read this file if this is a CSV file. What you
file if this is a CSV file. What you will do in this scenario? you will use a
will do in this scenario? you will use a function called ends with or starts
function called ends with or starts with. It's up to you whatever you want
with. It's up to you whatever you want to use. So how we can just use this? I
to use. So how we can just use this? I will simply say
will simply say um print or I will simply use if
um print or I will simply use if condition basically because again I will
condition basically because again I will just explain if condition as well. But
just explain if condition as well. But if condition is simply like checking
if condition is simply like checking like what is going on and what's the
like what is going on and what's the condition. It will simply return true or
condition. It will simply return true or false. I'll simply say if
false. I'll simply say if um file dot ends with ends with the
um file dot ends with ends with the function ends with ends with what dot
function ends with ends with what dot CSV. If it is ending with dot CSV then
CSV. If it is ending with dot CSV then print CSV file. Okay, make sense. Let me
print CSV file. Okay, make sense. Let me just run this. Perfect. Yes, this file
just run this. Perfect. Yes, this file is ending with dot CSV. That is why we
is ending with dot CSV. That is why we are getting dot CSV.
are getting dot CSV. This is the thing that we use in data
This is the thing that we use in data engineering. While reading data on a
engineering. While reading data on a daily basis, you can just apply check
daily basis, you can just apply check marks. You do not need to just read all
marks. You do not need to just read all the data. You can just simply read
the data. You can just simply read selective data. Make sense? Very good.
selective data. Make sense? Very good. So now let's say this data is dot
So now let's say this data is dot [Music]
[Music] um let's say what I will get nothing
um let's say what I will get nothing because this is not a CSV file. So
because this is not a CSV file. So that's how you use dot ends with method
that's how you use dot ends with method with
with your
your strings. Same thing you can just do with
strings. Same thing you can just do with starts with as well. Same you can simply
starts with as well. Same you can simply say
start. Okay. And I will simply say if it is starting with raw then simply say raw
is starting with raw then simply say raw data raw file. Let's see. Yeah perfect
data raw file. Let's see. Yeah perfect because it is starting with raw. So it
because it is starting with raw. So it will simply check the starting alphabets
will simply check the starting alphabets and from here like in the previous
and from here like in the previous example in dot CSV it checked the last
example in dot CSV it checked the last alphabets. Okay, very good. I hope it
alphabets. Okay, very good. I hope it makes sense. It makes sense. Now what do
makes sense. It makes sense. Now what do we
we have? Oh, okay. Let's do this
have? Oh, okay. Let's do this now. Let's say you have a statement.
now. Let's say you have a statement. Okay, let's say you have a statement.
Okay, let's say you have a statement. UI statement something like this.
doing? [Music]
Hey, I'm talking to you. Okay, now this is very interesting. Why? Because you
is very interesting. Why? Because you can ask me hey an you didn't even define
can ask me hey an you didn't even define like three quotes or three single quotes
like three quotes or three single quotes why it is like still a string because I
why it is like still a string because I didn't hit enter I was just writing and
didn't hit enter I was just writing and due to the insufficient space it moved
due to the insufficient space it moved to next line. So ideally it is just a
to next line. So ideally it is just a single line for Python right just to
single line for Python right just to make you aware it moved to next line
make you aware it moved to next line because of the space. Okay. So now in
because of the space. Okay. So now in this statement if I just want to check
this statement if I just want to check like how many times unword is appearing
like how many times unword is appearing can we do that? Yes, we have something
can we do that? Yes, we have something called as count function. I will simply
called as count function. I will simply say
say print
print statement dot count and what are we
statement dot count and what are we counting? Let's say un. Okay, simply run
counting? Let's say un. Okay, simply run this and I will get two because I'm just
this and I will get two because I'm just seeing my name two times. That's how you
seeing my name two times. That's how you can just find these words. If you are
can just find these words. If you are just let's say building a model or if
just let's say building a model or if you just want to make sure like how many
you just want to make sure like how many times we are using that word, you can
times we are using that word, you can simply perform word counts like this.
simply perform word counts like this. Okay. Okay. Let so we have like so many
Okay. Okay. Let so we have like so many functions available in string. Again we
functions available in string. Again we are covering this video for the data
are covering this video for the data engineering perspective. So you can just
engineering perspective. So you can just refer the function whatever you want to
refer the function whatever you want to use. Obviously we cannot just look for
use. Obviously we cannot just look for all the functions in string. These are
all the functions in string. These are the major functions that we use with
the major functions that we use with data engineering. And that's the agenda
data engineering. And that's the agenda of this video because we'll be cover we
of this video because we'll be cover we will be covering those things which are
will be covering those things which are directly aligned with data engineering.
directly aligned with data engineering. Python is a vast or you can say widely
Python is a vast or you can say widely used language. Okay, why am I again
used language. Okay, why am I again repeating this? Because you will feel
repeating this? Because you will feel like hey we have this thing as well. I
like hey we have this thing as well. I know I know we have a lot of stuff in
know I know we have a lot of stuff in Python. We have a lot. So now let's say
Python. We have a lot. So now let's say we going to
we going to cover. Yeah, this is important. This is
cover. Yeah, this is important. This is important. So let's
important. So let's say you have a string like last thing
say you have a string like last thing that we are just covering a string
that we are just covering a string because this is also important. Okay,
because this is also important. Okay, then we're going to jump on if
then we're going to jump on if statement. I know you are waiting since
statement. I know you are waiting since so long. So in this thing let's say you
so long. So in this thing let's say you have a variable okay or let's say demo
have a variable okay or let's say demo demo string okay you have demo string
demo string okay you have demo string like
like um or even not even string let's say
um or even not even string let's say because this is like irrespective of
because this is like irrespective of string this is a function that we use
string this is a function that we use okay this is also called is functions
okay this is also called is functions this is called is
this is called is functions okay so let's
functions okay so let's say you need to just define a demo
say you need to just define a demo string like this. Hello. Simple. Then
string like this. Hello. Simple. Then you can say demo
you can say demo variable. Okay, obviously this is also
variable. Okay, obviously this is also variable. This is also a variable. This
variable. This is also a variable. This is just a name. And this has a value
is just a name. And this has a value let's say 10. Okay. If I say
let's say 10. Okay. If I say print demo
print demo string dot is number, what it will
string dot is number, what it will return? What? Error. The is numeric.
return? What? Error. The is numeric. Sorry, not is number is
Sorry, not is number is numeric. See, every language has
numeric. See, every language has different
different functions. False. False. Oh yeah, by the
functions. False. False. Oh yeah, by the way, so this is another reason why do we
way, so this is another reason why do we use code editors? Because in the code
use code editors? Because in the code editors, we get some suggestions
editors, we get some suggestions whenever we are just writing something.
whenever we are just writing something. So it is not giving me suggestion
So it is not giving me suggestion because we have not installed pylance.
because we have not installed pylance. Pyance is just like an extension that we
Pyance is just like an extension that we use with VS code editor. But I would
use with VS code editor. But I would recommend you to use those core editors.
recommend you to use those core editors. It is really good. So yeah we were just
It is really good. So yeah we were just talking about is function. So it is
talking about is function. So it is simply saying is it numeric? No. Why?
simply saying is it numeric? No. Why? Because is it string?
Because is it string? Yes. So that's how we check like if a
Yes. So that's how we check like if a particular variable is numeric is alpha
particular variable is numeric is alpha numeric is string is something like
numeric is string is something like that. So we have so many is functions.
that. So we have so many is functions. If I write demo variable let's say like
If I write demo variable let's say like this. Will it return true? No. Why? So
this. Will it return true? No. Why? So here you have to use as functions with
here you have to use as functions with with only and only strings. So if I just
with only and only strings. So if I just encapsulate in double quotes that means
encapsulate in double quotes that means it becomes string right? If you just run
it becomes string right? If you just run this it will say true. Wow this is
this it will say true. Wow this is really helpful. If you just observed
really helpful. If you just observed what it did, I know this is string but
what it did, I know this is string but still we can confirm that within this
still we can confirm that within this string do we only have numbers or
string do we only have numbers or string. Wow, this is amazing. This is
string. Wow, this is amazing. This is amazing because we are getting
amazing because we are getting everything that we need if we just want
everything that we need if we just want to inspect like what is inside that
to inspect like what is inside that string. Is it a number? Is it let's say
string. Is it a number? Is it let's say a string? Okay. And we have something
a string? Okay. And we have something called as is alnum as well. What is
called as is alnum as well. What is al-nam? So al-nam means like alpha
al-nam? So al-nam means like alpha numeric. Let's say I I write 10 a bc. If
numeric. Let's say I I write 10 a bc. If I just run this, it will simply return
I just run this, it will simply return false. But if I just write is
false. But if I just write is alnum, it should work and it will say
alnum, it should work and it will say true because it has numbers and text
true because it has numbers and text both. So let's say you are reading one
both. So let's say you are reading one file and you know that in your file you
file and you know that in your file you should see text and number both. You can
should see text and number both. You can apply this condition and you can simply
apply this condition and you can simply say if it is alum only read that file
say if it is alum only read that file otherwise do not read that. So you can
otherwise do not read that. So you can just perform these things. See how
just perform these things. See how powerful it becomes when you just
powerful it becomes when you just combine these things with data
combine these things with data engineering. Make sense? Very good.
engineering. Make sense? Very good. These are very very like very simple.
These are very very like very simple. Very
Very simple. It's just like more you work
simple. It's just like more you work with these things better you understand
with these things better you understand that thing. Okay. So now let's finally
that thing. Okay. So now let's finally cover if else statement or you can say
cover if else statement or you can say conditionals in Python. So if else
conditionals in Python. So if else statement is so popular it's even in
statement is so popular it's even in Excel. Okay. And because of that people
Excel. Okay. And because of that people make a fun of Excel that Excel is also a
make a fun of Excel that Excel is also a programming language just because of
programming language just because of that if else statement. So basically
that if else statement. So basically what is if else statement? It is pure
what is if else statement? It is pure English. If this is true do
English. If this is true do that if not do that do other thing.
that if not do that do other thing. That's it. Same thing it is here as
That's it. Same thing it is here as well. So let's say I define a variable
well. So let's say I define a variable called x= 10. Okay. If I say if now it's
called x= 10. Okay. If I say if now it's up to me if I want to encapsulate my
up to me if I want to encapsulate my condition in uh braces. Ideally I would
condition in uh braces. Ideally I would recommend you always encapsulate the
recommend you always encapsulate the condition in braces. It promotes
condition in braces. It promotes readability and sometimes it eliminates
readability and sometimes it eliminates the errors as well. Okay. Very good.
the errors as well. Okay. Very good. These small things make you a better
These small things make you a better developer. So if x equals to equals to
developer. So if x equals to equals to 10. Now what is this equals to equals
10. Now what is this equals to equals to? We cannot say if x equals to 10.
to? We cannot say if x equals to 10. Why? Because if we say x equals to 10,
Why? Because if we say x equals to 10, we use single equals to to assign the
we use single equals to to assign the number to that variable. But to check
number to that variable. But to check the condition, we use double equals to.
the condition, we use double equals to. Okay, this is a simple thing but you
Okay, this is a simple thing but you should be aware of. If x equals to
should be aware of. If x equals to equals to 10 then you need to once you
equals to 10 then you need to once you just return your condition. Okay. Then
just return your condition. Okay. Then you can simply say colon and hit enter.
you can simply say colon and hit enter. By default you will not land in the
By default you will not land in the first you can say character line like
first you can say character line like this. You will not land here. You will
this. You will not land here. You will automatically land here. Why?
automatically land here. Why? Because this compiler promotes this com
Because this compiler promotes this com compiler promotes indentation and most
compiler promotes indentation and most of the compilers promote that as well.
of the compilers promote that as well. So you do not need to every time hit tab
So you do not need to every time hit tab and then go to that particular area. No,
and then go to that particular area. No, you can simply hit enter and you will
you can simply hit enter and you will land on the right place. So now you can
land on the right place. So now you can just print anything or you can do
just print anything or you can do anything. Anything means anything. You
anything. Anything means anything. You can simply say
can simply say print. Okay, you can simply say print
print. Okay, you can simply say print um x is 10. Simple. If I run this, you
um x is 10. Simple. If I run this, you will see that. Oh, okay. So now in if
will see that. Oh, okay. So now in if else condition, we can either use if as
else condition, we can either use if as an independent operation or we can
an independent operation or we can combine it with else as well. That's
combine it with else as well. That's what we do most of the time. If x equals
what we do most of the time. If x equals to equals to 10 that means print x is
to equals to 10 that means print x is 10. Now we need to take exit from this
10. Now we need to take exit from this if. Now we need to use else as an
if. Now we need to use else as an independent command. We'll hit
independent command. We'll hit backspace. I'll simply say else. That
backspace. I'll simply say else. That means if x is 10, print x is 10. If x is
means if x is 10, print x is 10. If x is not 10, then what? We will simply
not 10, then what? We will simply print. We will simply print x is not
print. We will simply print x is not 10. Make sense? Okay. And see
10. Make sense? Okay. And see indentation here as well. We get x is
indentation here as well. We get x is 10. If I say x= to 11, I will simply say
10. If I say x= to 11, I will simply say x is not 10. So that means it will first
x is not 10. So that means it will first go here. If this condition is not met,
go here. If this condition is not met, it will simply go here on this line.
it will simply go here on this line. Make sense? Now what if we want to add
Make sense? Now what if we want to add something like third statement? If x=
something like third statement? If x= to= to 10, make sense. If not makes
to= to 10, make sense. If not makes sense. What if I want to do something
sense. What if I want to do something between those? If x= to= to 10, then x
between those? If x= to= to 10, then x is 10. If x may be greater than 100, I
is 10. If x may be greater than 100, I will say x is too big. and then I will
will say x is too big. and then I will say x is not 10. So for that we simply
say x is not 10. So for that we simply use something called as l if. l if means
use something called as l if. l if means else if together. Okay that means if
else if together. Okay that means if then else if then else. Else will be
then else if then else. Else will be treated as the end of the condition.
treated as the end of the condition. When neither of the conditions were
When neither of the conditions were succeeded were like met then it will
succeeded were like met then it will simply go to else but before that will
simply go to else but before that will simply go to lf. Okay. I will simply say
simply go to lf. Okay. I will simply say lf x greater than 100. It will simply
lf x greater than 100. It will simply say
x is too big. Make sense? Let's say I assign x= to 110. It will simply say x
assign x= to 110. It will simply say x is too big. So it will simply go
is too big. So it will simply go to this command first. It didn't pass.
to this command first. It didn't pass. It will go to second. It passed. Wow. It
It will go to second. It passed. Wow. It returned this. If I say x equals to 11
returned this. If I say x equals to 11 for one more time, it will simply say x
for one more time, it will simply say x is not 10. That means it went here, it
is not 10. That means it went here, it failed, it went here, it failed, it went
failed, it went here, it failed, it went here. Obviously, it will always be
here. Obviously, it will always be passed because this is the last
passed because this is the last statement. It has to return something
statement. It has to return something like this. Okay, make sense? This is
like this. Okay, make sense? This is like else if statement. Now you can
like else if statement. Now you can perform inherited else if statement as
perform inherited else if statement as well. That's what we do in data
well. That's what we do in data engineering as well. So let's say let's
engineering as well. So let's say let's say if our x = to= to 10, we want to
say if our x = to= to 10, we want to continue this as a separate branch. Let
continue this as a separate branch. Let me just explain. If x= to= to 10. Okay,
me just explain. If x= to= to 10. Okay, if x= to= to 10, I will simply say
if x= to= to 10, I will simply say another if condition within this. This
another if condition within this. This is called nested if. I will simply say
is called nested if. I will simply say if x or you can say if x equ= to 10 or
if x or you can say if x equ= to 10 or let's
let's say let's perform nested if inside this
say let's perform nested if inside this because we we can just generate so many
because we we can just generate so many uh you can say conditions within this
uh you can say conditions within this let's say if I want to do
let's say if I want to do if x because we just know that x is
if x because we just know that x is greater than 100 it can be 1,000 it can
greater than 100 it can be 1,000 it can be 10,000 it can be one lakh it can be
be 10,000 it can be one lakh it can be 10 lakh so it can be like any big
10 lakh so it can be like any big number, right? So, we will simply define
number, right? So, we will simply define the level of x. We will simply say if
the level of x. We will simply say if x greater than
x greater than uh or let's say yeah greater
uh or let's say yeah greater than
than 200 make sense. If x is greater than 100
200 make sense. If x is greater than 100 or let's say 100 because it will simply
or let's say 100 because it will simply continue with that statement. If x is
continue with that statement. If x is greater than 100
greater than 100 and and x is less than 200 then you need
and and x is less than 200 then you need to
to print
print between 100 and
between 100 and 200. That's it. You can run this. So
200. That's it. You can run this. So I'll simply say 110. What it will do?
I'll simply say 110. What it will do? Let me just show you. So we will
Let me just show you. So we will understand it using the flow. It will
understand it using the flow. It will simply go here. First of all it failed.
simply go here. First of all it failed. So it is rejected. It went here. LF, it
So it is rejected. It went here. LF, it passed. So it is now entered within the
passed. So it is now entered within the L if command. Yes, here. Then within
L if command. Yes, here. Then within this, it just went through the if
this, it just went through the if condition. It is saying if X greater
condition. It is saying if X greater than 100 and less than 200 simply print
than 100 and less than 200 simply print between 100 and 200. You can even
between 100 and 200. You can even continue with this else statement as
continue with this else statement as well. Let's say
well. Let's say else
else print greater than
200. Make sense? Let's say I say 210. It will simply say greater than uh
210. It will simply say greater than uh wait
wait what? And x less than
what? And x less than 200. Oh, I see. So that's why I always
200. Oh, I see. So that's why I always say that add braces as much as you can.
say that add braces as much as you can. And this is the best example to
And this is the best example to demonstrate my point and I'm happy that
demonstrate my point and I'm happy that I saw this error. So basically it is
I saw this error. So basically it is creating a conflict a kind of conflict
creating a conflict a kind of conflict because it is not actually treating it
because it is not actually treating it as like two different
as like two different conditions. So in order to mitigate the
conditions. So in order to mitigate the risks you simply need to encapsulate
risks you simply need to encapsulate this as a separate and this as a
this as a separate and this as a separate condition. That's the power of
separate condition. That's the power of braces. And that's why whenever you're
braces. And that's why whenever you're doing any programming language your
doing any programming language your instructor or let's say your teacher if
instructor or let's say your teacher if you are in university or anything they
you are in university or anything they will simply ask you to just add braces
will simply ask you to just add braces wherever you can so that it will make it
wherever you can so that it will make it simpler for your compiler or interpreter
simpler for your compiler or interpreter to understand what you are actually
to understand what you are actually trying to do. If I just try to run this
trying to do. If I just try to run this again I should see greater than 200.
again I should see greater than 200. Perfect. So now what it is doing let me
Perfect. So now what it is doing let me just explain it one more time. It is
just explain it one more time. It is going here. It is not fulfilling the
going here. It is not fulfilling the condition. Failed. It went here. It
condition. Failed. It went here. It fulfilled. Then it actually entered
fulfilled. Then it actually entered within this LF. It simply performed X
within this LF. It simply performed X greater than 100. Yes. Is less than 200.
greater than 100. Yes. Is less than 200. Is it condition true? No. So it failed.
Is it condition true? No. So it failed. Then it went to else. Is it true?
Then it went to else. Is it true? Obviously because this is the else
Obviously because this is the else statement. So it simply returned this.
statement. So it simply returned this. Will it go to the next line? Obviously
Will it go to the next line? Obviously no. Because this condition is already
no. Because this condition is already true. Only one condition needs to be
true. Only one condition needs to be true. That's it. That's how your nested
true. That's it. That's how your nested if works.
if works. I would recommend you to build more and
I would recommend you to build more and more functions and not like functions
more functions and not like functions like real functions use cases using else
like real functions use cases using else and if statement because more you are
and if statement because more you are wellvered with if and else statement you
wellvered with if and else statement you can easily work with anything because
can easily work with anything because everywhere you will be using if else and
everywhere you will be using if else and nested if
nested if else okay so it is just a tip or you can
else okay so it is just a tip or you can say kind of homework for you so just do
say kind of homework for you so just do that okay now I know you are very very
that okay now I know you are very very very much wellvered with if condition
very much wellvered with if condition let Let me just tell you. Oh, finally my
let Let me just tell you. Oh, finally my favorite. So, now we're going to talk
favorite. So, now we're going to talk about
about loops. Loops are like data engineers
loops. Loops are like data engineers favorite thing. Favorite because let me
favorite thing. Favorite because let me just remove all the things. Okay. So,
just remove all the things. Okay. So, why why why loops are so important for
why why why loops are so important for data engineers? Because we work with big
data engineers? Because we work with big data. We get a lot of objects and we
data. We get a lot of objects and we need to perform iteration. Loops are
need to perform iteration. Loops are basically used for
basically used for iterations. Okay,
iterations. Real time example. Let's say you want to perform a loop or forget
say you want to perform a loop or forget about loop. Forget about loop. Let's say
about loop. Forget about loop. Let's say you need to read data from let's
you need to read data from let's say table one which is called orders.
say table one which is called orders. Okay. Then
Okay. Then products, then
customers, okay? Then let's say comments, then let's say
comments, then let's say um reviews like so many tables, right?
um reviews like so many tables, right? So these are your tables that you need
So these are your tables that you need to use while reading the data.
to use while reading the data. Basically, you need to read the data
Basically, you need to read the data from these tables. One way of doing it
from these tables. One way of doing it is simply perform the same code for
is simply perform the same code for individual table 1 2 3 4 5 here are
individual table 1 2 3 4 5 here are there are five in real world there can
there are five in real world there can be like hundreds of
be like hundreds of tables. Other thing what you can do is
tables. Other thing what you can do is you can simply run a loop a loop which
you can simply run a loop a loop which will
will perform iteration for all these items
perform iteration for all these items which are in this particular
array. Make sense? Make sense? Make sense?
sense? So it will simply perform iteration. So
So it will simply perform iteration. So iteration number one will be orders.
iteration number one will be orders. Iteration number two will be products,
Iteration number two will be products, then customers, then comments, then
then customers, then comments, then reviews. Make sense? Let's try to
reviews. Make sense? Let's try to understand this in deep with the help of
understand this in deep with the help of an example. Okay? And with the code as
an example. Okay? And with the code as well obviously. So very popular loop is
well obviously. So very popular loop is for loop. And you will be using for loop
for loop. And you will be using for loop at least I think 60% of the time or I
at least I think 60% of the time or I would say 80% of the time 20% of the
would say 80% of the time 20% of the time you will use while loop. And I will
time you will use while loop. And I will just talk about while loop as well. Uh
just talk about while loop as well. Uh it totally depends but yeah most in most
it totally depends but yeah most in most of the case you will use for loop. For
of the case you will use for loop. For loop is very simple. For loop is also
loop is very simple. For loop is also simple but you need to just manage while
simple but you need to just manage while loop and for in the for loop it is
loop and for in the for loop it is pretty much simple. You do not need to
pretty much simple. You do not need to perform iterations. So basically let's
perform iterations. So basically let's say you have a list. Let's say you have
say you have a list. Let's say you have a list. list is something like this um
a list. list is something like this um my
my list and it has values such as let's say
list and it has values such as let's say ABC or let's say orders
ABC or let's say orders orders
products products okay then you have let's say uh customers let's say three
let's say uh customers let's say three tables you want to simply run a loop on
tables you want to simply run a loop on top of this how you can just do that you
top of this how you can just do that you will simply say for Okay, for is like
will simply say for Okay, for is like for for loop. I I is nothing but just a
for for loop. I I is nothing but just a variable that you want to use as an I
variable that you want to use as an I iterator for I in on which we need to
iterator for I in on which we need to apply a loop on my list. Right? Simple.
apply a loop on my list. Right? Simple. This is a concept. Simply add colon go
This is a concept. Simply add colon go to the next line. Now I can simply say
to the next line. Now I can simply say print I because I want to see the value
print I because I want to see the value of I for
of I for each iteration. Right? It will simply
each iteration. Right? It will simply return values like this. Order,
return values like this. Order, products,
products, customers. Did I write this code? Print.
customers. Did I write this code? Print. So one option was for me print order.
So one option was for me print order. Okay.
Okay. Print
products and then print
print customers. Right? One option was this.
customers. Right? One option was this. If I just comment it out, one option was
If I just comment it out, one option was this or the second option was just
this or the second option was just simply run a loop. Simply run a
simply run a loop. Simply run a loop. I can simply run the loop.
loop. I can simply run the loop. Simple. That's the concept of
Simple. That's the concept of loop. Make sense. Okay, I hope it makes
loop. Make sense. Okay, I hope it makes sense. This is like very simple, very
sense. This is like very simple, very common example of for loop. We can even
common example of for loop. We can even use loop without this particular list.
use loop without this particular list. Let's say I want to run a loop on
Let's say I want to run a loop on specific um numbers. Let's say I want to
specific um numbers. Let's say I want to run a loop from start from one and it
run a loop from start from one and it should go till let's say 100. So for
should go till let's say 100. So for that we have something called as range
that we have something called as range function. I will simply write range and
function. I will simply write range and starting point is 1 and ending point is
starting point is 1 and ending point is 101. Why it always goes to n minus one.
101. Why it always goes to n minus one. Okay let me just print and you will see
Okay let me just print and you will see counting from 1 till 100.
counting from 1 till 100. See, so this is a range function that
See, so this is a range function that acts like an array. This is equivalent
acts like an array. This is equivalent to this one. 1 2 3 and till
to this one. 1 2 3 and till 100. Okay. So this is similar to this
100. Okay. So this is similar to this one. Make sense? This is similar to this
one. Make sense? This is similar to this one. This is like just a range
one. This is like just a range function. Just a range function. Okay.
function. Just a range function. Okay. Make sense? And let me just tell you one
Make sense? And let me just tell you one thing. You can even combine loops with
thing. You can even combine loops with if
if conditions. Really? Yes. Let's do that.
conditions. Really? Yes. Let's do that. So let's say you got like the previous
So let's say you got like the previous example. Let's say you got because this
example. Let's say you got because this is something similar to your data
is something similar to your data engineing stuff. So let's say this is
engineing stuff. So let's say this is your tables list. Let me just write
your tables list. Let me just write table. Okay. Now you want to run a loop
table. Okay. Now you want to run a loop on a table list and you need to check
on a table list and you need to check the table name because every time being
the table name because every time being a data engineer you cannot process all
a data engineer you cannot process all the data. You need to perform some
the data. You need to perform some validation steps as well. Right? So you
validation steps as well. Right? So you will simply say hey
will simply say hey um if my table name equals to equals to
um if my table name equals to equals to order then only I will just process data
order then only I will just process data otherwise not. This is the use case for
otherwise not. This is the use case for you as a data
you as a data engineer. Make sense? Very good. How you
engineer. Make sense? Very good. How you can just do that? So first of all it
can just do that? So first of all it will perform loop for I in table list.
will perform loop for I in table list. Perfect. Then it will simply provide the
Perfect. Then it will simply provide the value of I equals to order for first
value of I equals to order for first iteration. Very good. We will simply say
iteration. Very good. We will simply say if I equals to equals to
if I equals to equals to order equals to equals to order. Very
order equals to equals to order. Very good. Now let me just show you how we
good. Now let me just show you how we use upper and lower functions because
use upper and lower functions because the thing is it can be order it can
the thing is it can be order it can be order okay it can be order it can be
be order okay it can be order it can be anything right it depends upon the data
anything right it depends upon the data quality that we are getting so we just
quality that we are getting so we just need to make sure the errors we as a
need to make sure the errors we as a data engineer so we'll simply say I do
data engineer so we'll simply say I do lower so we'll simply convert the I to
lower so we'll simply convert the I to lower case and then we will compare it
lower case and then we will compare it like this equals to equals to order if
like this equals to equals to order if this is equals equals to order then
this is equals equals to order then print table order and obviously this is
print table order and obviously this is an example in the real life you will
an example in the real life you will perform your copy statement or you can
perform your copy statement or you can simply perform data reading you will
simply perform data reading you will simply write your code df equals to blah
simply write your code df equals to blah blah blah CSV read anything make sense
blah blah CSV read anything make sense are you are you getting my statement
are you are you getting my statement what I'm just using right now I'm just
what I'm just using right now I'm just trying you to relate with the data
trying you to relate with the data engineering how we are using Python with
engineering how we are using Python with data engineering that's why I'm focusing
data engineering that's why I'm focusing only on those stuff which are important
only on those stuff which are important for data engineers. Right? So let me
for data engineers. Right? So let me just run this and you will simply see
just run this and you will simply see table order. Now what happened? Now what
table order. Now what happened? Now what happened? Let me just show
happened? Let me just show you just to make you aware like how this
you just to make you aware like how this flows works. I will simply say else I
flows works. I will simply say else I will simply say
will simply say print no table
print no table order. Okay let me just run this.
order. Okay let me just run this. Perfect. Now let's understand what
Perfect. Now let's understand what happened. It simply iterated through
happened. It simply iterated through this list.
this list. For the first iteration, the value of I
For the first iteration, the value of I was order. Okay, it was in with capital
was order. Okay, it was in with capital O. We converted it and we just checked
O. We converted it and we just checked if it equals to equals to order simply
if it equals to equals to order simply return table order. This is done because
return table order. This is done because it will not go to else because this
it will not go to else because this condition is met. Second time this was
condition is met. Second time this was the value of I products, right? It went
the value of I products, right? It went here. It compared it. Is products equals
here. It compared it. Is products equals to equals to order? Obviously not. It
to equals to order? Obviously not. It failed. It went to this statement. else.
failed. It went to this statement. else. Very good. Then third iteration, the
Very good. Then third iteration, the value of I equals to equals to customer.
value of I equals to equals to customer. Okay, it compared it. Is it equal? No,
Okay, it compared it. Is it equal? No, it went here and it returned this. This
it went here and it returned this. This is how it is working for you. This is
is how it is working for you. This is how it is
how it is working. H okay. Makes sense. Makes
working. H okay. Makes sense. Makes sense. Makes sense. So
sense. Makes sense. So now now this is like all about for loop.
now now this is like all about for loop. Okay. And you can do a lot of stuff in
Okay. And you can do a lot of stuff in for loop. You can just even use like
for loop. You can just even use like multiple if conditions or you can even
multiple if conditions or you can even create another loop within this loop.
create another loop within this loop. How? You can even perform like loops
How? You can even perform like loops like
like this. Let's say you want
this. Let's say you want to create a loop on top of this list.
to create a loop on top of this list. Yes. So what will be the value of i?
Yes. So what will be the value of i? Equals to order. Makes sense. Common
Equals to order. Makes sense. Common sense. Now within
sense. Now within this you want to now run a loop on top
this you want to now run a loop on top of I. Are you serious bro? Hold on. I
of I. Are you serious bro? Hold on. I told you
told you that string is also like beh can be can
that string is also like beh can be can behave like an array right? Can behave
behave like an array right? Can behave like an array. So this is the value of
like an array. So this is the value of I. I want to run a loop on this
I. I want to run a loop on this particular string. Can can't I do that?
particular string. Can can't I do that? Now you will say yeah yeah we can do
Now you will say yeah yeah we can do that. So how we can just do that? Let me
that. So how we can just do that? Let me show you. I will simply say for I in
show you. I will simply say for I in table list I will first of all print
table list I will first of all print that just to show you print I
that just to show you print I immediately then I will simply say for
immediately then I will simply say for loop and this time let's create variable
loop and this time let's create variable called X in I in I then print X. So you
called X in I in I then print X. So you will see what happens see order. So
will see what happens see order. So first it just iterated through this
first it just iterated through this list. It got I equals to order. Then we
list. It got I equals to order. Then we created a loop on I. We get O R D E R.
created a loop on I. We get O R D E R. Same with products and same with
Same with products and same with customers as well. That's how we can
customers as well. That's how we can just run nested loops. Make sense? Make
just run nested loops. Make sense? Make sense? You can do a lot of stuff and my
sense? You can do a lot of stuff and my duty is you for like my duty is for you
duty is you for like my duty is for you to make you aware about all the things
to make you aware about all the things so that you can actually perform a lot
so that you can actually perform a lot of stuff and you do not need to worry
of stuff and you do not need to worry about the fundamentals and the concepts
about the fundamentals and the concepts because once you grab the concepts you
because once you grab the concepts you can practice it. You can try solving
can practice it. You can try solving questions. You can just do a lot of
questions. You can just do a lot of stuff that will make you a pro. That's
stuff that will make you a pro. That's all depends upon how much you practice.
all depends upon how much you practice. That's it. Because these stuff are same
That's it. Because these stuff are same everywhere. What I am trying to do I am
everywhere. What I am trying to do I am trying you I am trying to make you aware
trying you I am trying to make you aware these things about these things for data
these things about these things for data engineering domain. Okay. Yes we run
engineering domain. Okay. Yes we run loops like
loops like this. Got it? Very good. Now you will
this. Got it? Very good. Now you will say an Lamba for loops are really cool
say an Lamba for loops are really cool and we saw the power of it as well. What
and we saw the power of it as well. What about while loop? Like what what what
about while loop? Like what what what are loops man? Personally speaking, um
are loops man? Personally speaking, um you will hardly see anyone using Y loop
you will hardly see anyone using Y loop much. I would say 20% of the time you'll
much. I would say 20% of the time you'll be using Y loop but you will not be
be using Y loop but you will not be using Y loop a lot. Okay. And for with Y
using Y loop a lot. Okay. And for with Y loop you need to use break statements if
loop you need to use break statements if you are just if you're not iterating
you are just if you're not iterating something. So it is really really hard
something. So it is really really hard for you to just manage while loops.
for you to just manage while loops. Okay. Before talking about while loops,
Okay. Before talking about while loops, I need to talk about break and continue
I need to talk about break and continue statement. What are those statement?
statement. What are those statement? Those are really important. Once you
Those are really important. Once you understand those things, while loop is a
understand those things, while loop is a piece of cake for you. So basically,
piece of cake for you. So basically, let's take the same example. Okay, let's
let's take the same example. Okay, let's say this is a list. Okay, make sense? I
say this is a list. Okay, make sense? I know that in my list I have thousands of
know that in my list I have thousands of items. How much? Thousands. And I know
items. How much? Thousands. And I know that within that list I have only one
that within that list I have only one order table H and my duty is to
order table H and my duty is to just to just copy the orders
just to just copy the orders data. Okay. So what I would like to do I
data. Okay. So what I would like to do I would simply first of all I trade
would simply first of all I trade through all the items but the moment I
through all the items but the moment I find the orders table I want to break
find the orders table I want to break the loop immediately because I do not
the loop immediately because I do not want to go ahead after that
want to go ahead after that orders make sense make sense let's say
orders make sense make sense let's say let's put order in the between so that
let's put order in the between so that you can actually understand it let's say
you can actually understand it let's say like
like this like this so what it will do like
this like this so what it will do like what I want to achieve I want to
what I want to achieve I want to achieve. I want to iterate through this
achieve. I want to iterate through this list. I want to go
list. I want to go here. Is it equal to orders? No. Go
here. Is it equal to orders? No. Go ahead. Is it equal to order? Yes. Cut
ahead. Is it equal to order? Yes. Cut the loop. Break the loop. Immediately
the loop. Break the loop. Immediately break the
break the loop. Immediately. Oh, can we do that?
loop. Immediately. Oh, can we do that? Yeah, it's fun. I know. Let's do it. So,
Yeah, it's fun. I know. Let's do it. So, I will simply say for i
I will simply say for i in table
in table list. Okay.
list. Okay. I will simply say
I will simply say if
if I equals equals order and you will use
I equals equals order and you will use lower just to make sure case sensitivity
lower just to make sure case sensitivity is not affecting our code. If equals to
is not affecting our code. If equals to equals to order okay then
equals to order okay then break and obviously for you to see the
break and obviously for you to see the results I will simply first of all print
results I will simply first of all print the value of I let's see what will
the value of I let's see what will happen you will simply see two things
happen you will simply see two things not the customers perfect so what
not the customers perfect so what actually happened it started the loop it
actually happened it started the loop it printed the statement okay okay it
printed the statement okay okay it printed the statement and then it
printed the statement and then it compared it is it equal to order no so
compared it is it equal to order no so it didn't break it then for the second
it didn't break it then for the second value It printed the statement which is
value It printed the statement which is order and then it compared it. Is it
order and then it compared it. Is it equal to order? Break. It completed the
equal to order? Break. It completed the loop right away. Not completed. It just
loop right away. Not completed. It just break broke the loop. If I put print
break broke the loop. If I put print here, what should be the output? Just a
here, what should be the output? Just a quick question for you. If I say like
quick question for you. If I say like this, what output should you see? You
this, what output should you see? You have just 3
have just 3 seconds. Hm. Time up. You will just see
seconds. Hm. Time up. You will just see products. Not even products.
products. Not even products. So the thing is what actually
So the thing is what actually happened it started from here for I in
happened it started from here for I in tables list. Okay. So it compared it
tables list. Okay. So it compared it compared this with orders. Okay. Is it
compared this with orders. Okay. Is it equal to order?
equal to order? No. Then it compared it with order. Is
No. Then it compared it with order. Is it equal to order? Yes. So it break it.
it equal to order? Yes. So it break it. So break means it will not even go to
So break means it will not even go to the next line.
the next line. Oh, it will not even go to the next
Oh, it will not even go to the next line. It will break the whole code. It
line. It will break the whole code. It will break the loop and break do not
will break the loop and break do not execute the rest of the lines. It will
execute the rest of the lines. It will simply break it. Oh, okay. Yeah, makes
simply break it. Oh, okay. Yeah, makes sense. Now, what is continue statement?
sense. Now, what is continue statement? It is just opposite of break. Okay. What
It is just opposite of break. Okay. What does it mean? So, basically, let's take
does it mean? So, basically, let's take the example. Let's say you do not want
the example. Let's say you do not want to process order data. You want to
to process order data. You want to process all the other data. So what you
process all the other data. So what you will do? You will simply iterate through
will do? You will simply iterate through this list. Okay. This one, this one,
this list. Okay. This one, this one, this one. Make sense? Okay. Now what I
this one. Make sense? Okay. Now what I will do? If my data is products, it's
will do? If my data is products, it's fine. Simply print it. If my table name
fine. Simply print it. If my table name is order, continue. Continue means just
is order, continue. Continue means just skip that iteration.
skip that iteration. H just show us with example because then
H just show us with example because then only it will be much more you can
only it will be much more you can say visible and easy to digest. So
say visible and easy to digest. So basically for I in tables list that
basically for I in tables list that means it will iterate through each
means it will iterate through each entity 1 2 3 sorted sorted very good. So
entity 1 2 3 sorted sorted very good. So it will simply iterate through those
it will simply iterate through those items. I will
items. I will say
say if I do
if I do lower I dot lower equals to equals to
lower I dot lower equals to equals to order. Simply say
order. Simply say continue. Okay. And I will simply print
continue. Okay. And I will simply print the value here of I. If I run this, I
the value here of I. If I run this, I should not see order and I should only
should not see order and I should only see products. Why? It ran the loop.
see products. Why? It ran the loop. Okay. And then we said if this is equals
Okay. And then we said if this is equals to equals to order simply continue it.
to equals to order simply continue it. Continue means do not go ahead and do
Continue means do not go ahead and do not perform anything for this particular
not perform anything for this particular value which is I. And in this case it is
value which is I. And in this case it is order. Do not perform anything. So if it
order. Do not perform anything. So if it is products it will simply check it. Is
is products it will simply check it. Is it equals to order? No. Simply run rest
it equals to order? No. Simply run rest of the code. Simple. But if it is order
of the code. Simple. But if it is order it will simply say is it equal to equal
it will simply say is it equal to equal to order? Yes. Continue. Continue means
to order? Yes. Continue. Continue means just continue with the next iteration.
just continue with the next iteration. Do not run rest of the code. Do not run
Do not run rest of the code. Do not run the sprint I. No. Simply continue.
the sprint I. No. Simply continue. Skip. Okay. Makes sense. This is also
Skip. Okay. Makes sense. This is also easy. Yeah. And this is cool. Makes
easy. Yeah. And this is cool. Makes sense. Okay. Good. Now let's try to
sense. Okay. Good. Now let's try to understand the Y loop. Now let me just
understand the Y loop. Now let me just tell you what is Y loop and why do we
tell you what is Y loop and why do we use Y loop and how do we use Y loop. Now
use Y loop and how do we use Y loop. Now let's try to understand Y loops. Why
let's try to understand Y loops. Why loops are really handy when you do not
loops are really handy when you do not actually want to iterate but yeah you
actually want to iterate but yeah you want to iterate. Let me just tell you
want to iterate. Let me just tell you what's that. Basically um let's remove
what's that. Basically um let's remove this example. Okay let's say my x value
this example. Okay let's say my x value is equals to
is equals to 10. I want to iterate or let's say I
10. I want to iterate or let's say I want to perform my iterations till the
want to perform my iterations till the time my value
time my value is 10. I know you didn't understand
is 10. I know you didn't understand anything. Let me just explain. Wait. So
anything. Let me just explain. Wait. So basically I want to run a loop. Okay. I
basically I want to run a loop. Okay. I want to run a loop in for loop. I know I
want to run a loop in for loop. I know I can simply say for i in range
um let's say 1 till 11 because n minus one. Okay. I can do this. But if what if
one. Okay. I can do this. But if what if I want to just do the same stuff in y
I want to just do the same stuff in y loop? In y loop what I will do? I will
loop? In y loop what I will do? I will simply first of all create the variable
simply first of all create the variable x= to 10. Then I will simply say while
x= to 10. Then I will simply say while again it's English, right?
While x is less than 11, perform my thing. Perform my thing.
11, perform my thing. Perform my thing. Whatever I want to perform. Here's a
Whatever I want to perform. Here's a catch. The catch
catch. The catch is here for loop is iterating the values
is here for loop is iterating the values for us. While loop doesn't do that. So
for us. While loop doesn't do that. So we need to make sure once our work is
we need to make sure once our work is done for that iteration we need to
done for that iteration we need to iterate it. That means let's say this
iterate it. That means let's say this these are my lines of code that I want
these are my lines of code that I want to execute. Then I want to simply do
to execute. Then I want to simply do this x= x + 1. So that it would become
this x= x + 1. So that it would become two. It would become two and then three
two. It would become two and then three then four then five like this.
then four then five like this. And here in this case if we just perform
And here in this case if we just perform x= to x + 1 it will simply stop the
x= to x + 1 it will simply stop the loop. Why? My x is 10. The moment I have
loop. Why? My x is 10. The moment I have done my work it becomes 11 and this
done my work it becomes 11 and this condition is
condition is false. Make sense? Make sense? So how we
false. Make sense? Make sense? So how we actually run the loop? Let me just show
actually run the loop? Let me just show you in the real life. So let's say x= to
you in the real life. So let's say x= to 1 that is my starting point. Okay. I
1 that is my starting point. Okay. I will simply write
will simply write while x less than 11. That is my ending
while x less than 11. That is my ending point. Okay. This is starting point and
point. Okay. This is starting point and this is ending point. Simply do this
this is ending point. Simply do this print
print x. Now I cannot run this because the
x. Now I cannot run this because the moment I will run this, it will go in
moment I will run this, it will go in the infinite loop. Why? Just tell me one
the infinite loop. Why? Just tell me one thing. This is the loop. Okay, this is
thing. This is the loop. Okay, this is x. This is the value of x. What's the
x. This is the value of x. What's the value of x? One. This condition is true.
value of x? One. This condition is true. Yes. Print x. It will print one. Next
Yes. Print x. It will print one. Next time it will check the condition again.
time it will check the condition again. What's the value of x? one what it will
What's the value of x? one what it will print one third time, fourth time, fifth
print one third time, fourth time, fifth time, sixth time, all the times it is
time, sixth time, all the times it is true. So that means it will keep on keep
true. So that means it will keep on keep on running the same stuff and it will
on running the same stuff and it will simply give me like so many ones. Let me
simply give me like so many ones. Let me let me run this and you will see. Wow.
let me run this and you will see. Wow. And you can see how many ones I have. I
And you can see how many ones I have. I cannot even count because it is now an
cannot even count because it is now an infinite loop. You can say execution
infinite loop. You can say execution halted. Why? because it cannot handle
halted. Why? because it cannot handle this much of memory. So we need to say
this much of memory. So we need to say once our work is done once we have
once our work is done once we have printed the value simply say x= x + 1.
printed the value simply say x= x + 1. Now what is the value of x? It's 2. Is
Now what is the value of x? It's 2. Is it less than 11? Yes. Then 3 then 4 then
it less than 11? Yes. Then 3 then 4 then 5. It will go until 10. Let me just show
5. It will go until 10. Let me just show you. See 1 2 3 4 5 6 7 8 9 10. Simple.
you. See 1 2 3 4 5 6 7 8 9 10. Simple. Then the moment it becomes 11. This
Then the moment it becomes 11. This condition is false. It will stop
condition is false. It will stop here. Make sense? That's how your while
here. Make sense? That's how your while loop works. The only thing is you need
loop works. The only thing is you need to handle the iteration on your own.
to handle the iteration on your own. Okay? That's the only stress. And in for
Okay? That's the only stress. And in for loop, you do not need to do that. But
loop, you do not need to do that. But yes, while loop is also very handy.
yes, while loop is also very handy. Okay, while loop is also very handy. I
Okay, while loop is also very handy. I personally use while loop with break
personally use while loop with break statements. Let's say
statements. Let's say um even if I do not perform this one
um even if I do not perform this one like let's say I'm performing this. So
like let's say I'm performing this. So what I will do? I will simply apply an
what I will do? I will simply apply an if condition here. If
if condition here. If um let's say let's say I'm just running
um let's say let's say I'm just running an infinite loop. Let's say I will
an infinite loop. Let's say I will simply say while true or let's say 1= 2=
simply say while true or let's say 1= 2= to 1 because this is always true. Okay,
to 1 because this is always true. Okay, forget about this.
forget about this. So I'm just simply running this while 1=
So I'm just simply running this while 1= to equals to 1. Okay. And print hello.
to equals to 1. Okay. And print hello. Let's say I want to print hello. Okay.
Let's say I want to print hello. Okay. So how many times it will print hello?
So how many times it will print hello? Infinite times. Right? Infinite times.
Infinite times. Right? Infinite times. What I will do? I will simply
What I will do? I will simply say if or let's say anything, right?
say if or let's say anything, right? Anything.
Anything. uh let's say
uh let's say here here let's say x= 10 or let's say x
here here let's say x= 10 or let's say x equals to 100 100 is a good number I am
equals to 100 100 is a good number I am not checking my condition here because
not checking my condition here because it is always true but I'm saying x= x +
it is always true but I'm saying x= x + 1 okay so every time it is just
1 okay so every time it is just increasing the number here okay x = 101
increasing the number here okay x = 101 102 103 or let's say start with 1 okay
102 103 or let's say start with 1 okay it will become 2 3 4 5 6 7 8 9 10 I'll
it will become 2 3 4 5 6 7 8 9 10 I'll simply say
simply say if x
if x uh greater than 100 simply break it
uh greater than 100 simply break it simply break the loop now it will not go
simply break the loop now it will not go to the infinite number let's make a
to the infinite number let's make a number smaller so that so that you can
number smaller so that so that you can actually see so it will simply say hello
actually see so it will simply say hello 1 0 1 2 3 4 5 6 7 8 9 that means total
1 0 1 2 3 4 5 6 7 8 9 that means total 10 make sense so what it did we simply
10 make sense so what it did we simply break the loop we personally use while
break the loop we personally use while loop with break statements where we know
loop with break statements where we know that our loop can go to the infinite
that our loop can go to the infinite loop. We simply break it based on a
loop. We simply break it based on a condition. Make sense? Now I hope you
condition. Make sense? Now I hope you understood loops very much in detail.
understood loops very much in detail. The next thing that we going to cover is
The next thing that we going to cover is functions. Functions are like your
functions. Functions are like your non-negotiables. And I think before
non-negotiables. And I think before functions, we should master list. List
functions, we should master list. List data types. Then you will switch to
data types. Then you will switch to functions. Okay, let's first master list
functions. Okay, let's first master list because list is non-negotiable for data
because list is non-negotiable for data engineers. You have to be wellvered with
engineers. You have to be wellvered with list because list is you can say
list because list is you can say everything for you. All your data, all
everything for you. All your data, all the things everything is list. So, so
the things everything is list. So, so now let's try to master data structures
now let's try to master data structures and first of all like what are data
and first of all like what are data structures? So, basically data
structures? So, basically data structures are you can say the efficient
structures are you can say the efficient way to store and organize your data. So
way to store and organize your data. So let's say you have a data how you want
let's say you have a data how you want to store it and how you want to organize
to store it and how you want to organize it while storing the data that's where
it while storing the data that's where data structures come into the picture
data structures come into the picture because they help you to store your data
because they help you to store your data and organize it as well at the same
and organize it as well at the same time. Very popular data structure is
time. Very popular data structure is list in Python and being a data engineer
list in Python and being a data engineer there are some like data structures very
there are some like data structures very popular ones by the way all the data
popular ones by the way all the data structures are important but there are
structures are important but there are two to three which are the most
two to three which are the most important okay and list is one of those.
important okay and list is one of those. So basically what is a list? List as we
So basically what is a list? List as we all know list behaves similar to the
all know list behaves similar to the array or you can say 1D array and you
array or you can say 1D array and you have already worked with array in the
have already worked with array in the strings. Let's say you have data
strings. Let's say you have data something called as ids 1 2 3 4 5 where
something called as ids 1 2 3 4 5 where you actually do not have a specific kind
you actually do not have a specific kind of key assigned to it. You directly want
of key assigned to it. You directly want to store the values. See 1 2 3 4 5 6. It
to store the values. See 1 2 3 4 5 6. It can be table names as well as we have
can be table names as well as we have just seen right. So let's say you want
just seen right. So let's say you want to store this data. So in this
to store this data. So in this particular scenario you can efficiently
particular scenario you can efficiently use list and you can store this data in
use list and you can store this data in a list. And what's the advantage of it?
a list. And what's the advantage of it? Obviously it is storing your data. The
Obviously it is storing your data. The second is you can actually perform a lot
second is you can actually perform a lot of operations on top of it using so many
of operations on top of it using so many methods and using so many you can say
methods and using so many you can say functions that we have within the list.
functions that we have within the list. Basically we call those like list
Basically we call those like list operations that we have. And without
operations that we have. And without delaying, let me just show you what do
delaying, let me just show you what do we have in. So we are back in our
we have in. So we are back in our compiler. So first of all, let's create
compiler. So first of all, let's create a list. Okay, let's create a list. And
a list. Okay, let's create a list. And let's say my list looks like this. 1 2.
let's say my list looks like this. 1 2. Now the best thing is within this list,
Now the best thing is within this list, you can store anything. Let's say
you can store anything. Let's say numbers and even
numbers and even string. Anything. You can just store
string. Anything. You can just store anything. Let's say lamba. Okay. You can
anything. Let's say lamba. Okay. You can even store a list within the list. let's
even store a list within the list. let's say
say zero or let's say a
zero or let's say a a
a bb
bb cc. So this is a list which is holding
cc. So this is a list which is holding so many different types of data
so many different types of data obviously integer string and a list
obviously integer string and a list itself that means you can store anything
itself that means you can store anything within a list and I will store it in a
within a list and I will store it in a variable and I will simply say my
variable and I will simply say my list. Make sense?
list. Make sense? Make sense? So this is our list. So
Make sense? So this is our list. So what's the advantage of list? Again, you
what's the advantage of list? Again, you can perform all those indexing. Let's
can perform all those indexing. Let's revise those indexing. And now you
revise those indexing. And now you should be much familiar with those.
should be much familiar with those. Let's say I want to just fetch the first
Let's say I want to just fetch the first element. So I'll simply say zero. And
element. So I'll simply say zero. And I'll simply apply print
I'll simply apply print here. And I should
here. And I should see only one. Very good. Let's say I
see only one. Very good. Let's say I want to fetch 0 1 2 3 4th element. I
want to fetch 0 1 2 3 4th element. I will simply see a list
will simply see a list right very good let's say within this
right very good let's say within this list I want to
list I want to fetch first element I will simply
fetch first element I will simply say
say one BB make sense so we are actually
one BB make sense so we are actually performing indexing within the list as
performing indexing within the list as well that's up to us now we already know
well that's up to us now we already know these things we have already seen this
these things we have already seen this and we can also like perform slicing
and we can also like perform slicing similar to this one let's say I want to
similar to this one let's say I want to fetch only zero
fetch only zero tell three. So it will simply give me 0
tell three. So it will simply give me 0 1 and two. Right? So all these stuff you
1 and two. Right? So all these stuff you already know. Let's talk about something
already know. Let's talk about something new in your code. Let's say if you're
new in your code. Let's say if you're working in an organization, you will see
working in an organization, you will see that people use something called as
that people use something called as minus sign here. Let's say they are
minus sign here. Let's say they are using something like this minus 3 and
using something like this minus 3 and then column. Do you know what it will
then column. Do you know what it will do? It will simply give
do? It will simply give you 1 2 and three last three elements.
you 1 2 and three last three elements. Really? Yes, let's run this. See an
Really? Yes, let's run this. See an lamba and this list last three elements.
lamba and this list last three elements. Let me just replace this with a normal
Let me just replace this with a normal function like normal number so that you
function like normal number so that you will not be confused. So see these three
will not be confused. So see these three elements. What does it mean? What does
elements. What does it mean? What does it mean? Like when we say minus three,
it mean? Like when we say minus three, what does it actually mean? This is
what does it actually mean? This is fine. Okay, this is fine. This means
fine. Okay, this is fine. This means like n this means n because we already
like n this means n because we already know that it will be the length of the
know that it will be the length of the list which is length of my list. So
list which is length of my list. So whenever you write minus 3 do you know
whenever you write minus 3 do you know what python will do behind the scenes?
what python will do behind the scenes? Python will simply treat this thing like
Python will simply treat this thing like this my
this my list. Okay. And then within this it will
list. Okay. And then within this it will say length of my list.
say length of my list. length
length of my list. Okay. Then minus three. Oh,
of my list. Okay. Then minus three. Oh, then whatever number we have here, we
then whatever number we have here, we already know that it will simply perform
already know that it will simply perform length. So it will simply do like
length. So it will simply do like this. So this is the actual thing that
this. So this is the actual thing that it is performing under the hood. And you
it is performing under the hood. And you can even print it just to see it is
can even print it just to see it is exactly the same.
See, so whenever you see minus3 sign, okay, whenever you see minus three sign,
okay, whenever you see minus three sign, you can replace it with total length of
you can replace it with total length of the uh list minus that number like not
the uh list minus that number like not minus like exactly that number that is
minus like exactly that number that is minus 3. So it's up to you why do we use
minus 3. So it's up to you why do we use it? We use it a lot. Let's say you want
it? We use it a lot. Let's say you want to fetch last 10 digits of a mobile
to fetch last 10 digits of a mobile number. If you have if you are because
number. If you have if you are because in the real world you will be working
in the real world you will be working with data, right? And in that particular
with data, right? And in that particular data you have a column for mobile number
data you have a column for mobile number and within that you have different
and within that you have different different area codes. You have different
different area codes. You have different different country codes. But you just
different country codes. But you just need to fetch the 10 digits last 10
need to fetch the 10 digits last 10 digits. In that particular scenario you
digits. In that particular scenario you can simply perform like this like let's
can simply perform like this like let's say minus 10 and that's it. You will
say minus 10 and that's it. You will simply see minus 10. Obviously we do not
simply see minus 10. Obviously we do not have 10 elements. So you are seeing all
have 10 elements. So you are seeing all these elements. But in reality, in
these elements. But in reality, in reality, in that column, you will just
reality, in that column, you will just see last 10 items or you can say last 10
see last 10 items or you can say last 10 digits of that particular column. Make
digits of that particular column. Make sense? It's up to you uh if you just
sense? It's up to you uh if you just want to treat it like this. So how does
want to treat it like this. So how does it work behind the scenes? Like how we
it work behind the scenes? Like how we need to just use it. So let's say let's
need to just use it. So let's say let's perform like minus three so that you can
perform like minus three so that you can actually see the results. So what it
actually see the results. So what it will do? So this starts from behind. So
will do? So this starts from behind. So it will simply say minus one. Okay, this
it will simply say minus one. Okay, this is minus one. So if we are starting from
is minus one. So if we are starting from the beginning, we start from zero. So
the beginning, we start from zero. So this is zero. If we want to start from
this is zero. If we want to start from the behind, it is minus one. So this is
the behind, it is minus one. So this is minus1. This is -2. This is minus 3.
minus1. This is -2. This is minus 3. Okay. And this will go till the
Okay. And this will go till the beginning of the list. Like maybe like
beginning of the list. Like maybe like you can say the last number that it has.
you can say the last number that it has. So the last number is zero, right? So it
So the last number is zero, right? So it will not include zero. So it will simply
will not include zero. So it will simply cover minus3, minus2, minus1 and that's
cover minus3, minus2, minus1 and that's it. It is like a little bit confusing
it. It is like a little bit confusing but when you just use it you will love
but when you just use it you will love this method a lot because it is very
this method a lot because it is very easy. You need to simply find last three
easy. You need to simply find last three digits simply write minus three and
digits simply write minus three and that's it. It is really easy but yeah in
that's it. It is really easy but yeah in the beginning it seems a little
the beginning it seems a little confusing but it is not. It is not.
confusing but it is not. It is not. Okay. Let me just tell you one more
Okay. Let me just tell you one more thing. So let's say you have this list.
thing. So let's say you have this list. Let me add more numbers here. Let's say
Let me add more numbers here. Let's say four 5 6. Okay. Now I want to simply
four 5 6. Okay. Now I want to simply fetch the list but I want to skip the
fetch the list but I want to skip the number by two instead of by one. What do
number by two instead of by one. What do I mean? If we write something like
this my list colon what it will do? It will
list colon what it will do? It will simply return me the full list. Make
simply return me the full list. Make sense? And how it is doing that? It is
sense? And how it is doing that? It is simply starting from zero. It is going
simply starting from zero. It is going till uh n and it is simply iterating
till uh n and it is simply iterating through one number like only the gap of
through one number like only the gap of one. If I
one. If I say
say two like this obviously you do not need
two like this obviously you do not need to use comma for the simplicity I'm just
to use comma for the simplicity I'm just telling you. If you write something like
telling you. If you write something like two you need a kind of iteration. So for
two you need a kind of iteration. So for that particular purpose what it will do
that particular purpose what it will do it will simply start from one it will
it will simply start from one it will directly jump onto the second number not
directly jump onto the second number not to the next one. So it will simply say
to the next one. So it will simply say an then it will jump onto the third then
an then it will jump onto the third then it will jump onto the five. That's how
it will jump onto the five. That's how it works. So let's see in the code you
it works. So let's see in the code you simply need another colon and that's it.
simply need another colon and that's it. See 1 3 5 that's it. So that means you
See 1 3 5 that's it. So that means you can actually decide the iterated value
can actually decide the iterated value as well. You can actually decide the
as well. You can actually decide the gap. If I say three, it will simply jump
gap. If I say three, it will simply jump to lamba directly. See one lamba and
to lamba directly. See one lamba and then
then five. Make sense? Very good. So this is
five. Make sense? Very good. So this is the third one and this is optional. If
the third one and this is optional. If you do not define it, by default it is
you do not define it, by default it is one. If you want to define it, you can
one. If you want to define it, you can define it's up to you. So this is all
define it's up to you. So this is all about like slicing and indexing. Let's
about like slicing and indexing. Let's see some of the operations that we have
see some of the operations that we have because we need to see it. Let's say you
because we need to see it. Let's say you want to add something into your ex
want to add something into your ex existing list. Can you do that? Yes, you
existing list. Can you do that? Yes, you can do that using append method. I will
can do that using append method. I will simply say my
simply say my list dot append and I want to add let's
list dot append and I want to add let's say hero. So what it will do? It will
say hero. So what it will do? It will simply add that particular element at
simply add that particular element at the end of the script after six.
the end of the script after six. Let me print as
well. Oops. Oh yeah, because it appended it. We need to just say print my
it. We need to just say print my list. Uh uh uh. So this is done. So it
list. Uh uh uh. So this is done. So it has appended the
has appended the data. Okay. And now we are just checking
data. Okay. And now we are just checking the list like how does it look like now.
the list like how does it look like now. Okay. Perfect. It has added hero at the
Okay. Perfect. It has added hero at the end.
end. Why? Why? There is a very important
Why? Why? There is a very important concept here. Why? Because
mutable. H what are mutable? What are mutable? That means
mutable? What are mutable? That means the value can be changed.
the value can be changed. We can change the
We can change the value or values of a list. Here we
value or values of a list. Here we change the value of a list. How? Because
change the value of a list. How? Because we added the element. We do not need to
we added the element. We do not need to say something like this. My
say something like this. My list
list equals my
list.append something like this. Because we perform this thing when our list are
we perform this thing when our list are not mutable or you can say immutable but
not mutable or you can say immutable but our lists are mutable. That means the
our lists are mutable. That means the moment we perform
moment we perform this it will actually automatically add
this it will actually automatically add this thing here and we do not need to
this thing here and we do not need to say hey my list equals to this thing
say hey my list equals to this thing that means it will automatically perform
that means it will automatically perform this step here. Wow. Yes. So now one
this step here. Wow. Yes. So now one more thing if you want to add hero after
more thing if you want to add hero after one can we do that because append method
one can we do that because append method will like every time insert or you can
will like every time insert or you can say add the data at the end. So if you
say add the data at the end. So if you want to insert a data at a particular
want to insert a data at a particular location we have a function called
location we have a function called insert. So it is called my list
insert. So it is called my list dotinsert. Okay. And first you will
dotinsert. Okay. And first you will define the location. I will simply say 1
define the location. I will simply say 1 index because one is standing at zero
index because one is standing at zero index. I want to add it at the 1 index
index. I want to add it at the 1 index and currently at the 1 index we have two
and currently at the 1 index we have two right. So one comma
right. So one comma hero. So if I simply run this I should
hero. So if I simply run this I should see hero after one. And here we are
see hero after one. And here we are seeing at the end as well. Why? Because
seeing at the end as well. Why? Because it was added before. See very good.
it was added before. See very good. Now if we want to let's say delete a
Now if we want to let's say delete a delete an item. Can we do that? Yes. So
delete an item. Can we do that? Yes. So we have a function called pop. My list
we have a function called pop. My list dot pop. That's it. So what it will do?
dot pop. That's it. So what it will do? What element it will delete? First let's
What element it will delete? First let's see. You will get to
see. You will get to know. It deleted hero. But why? How does
know. It deleted hero. But why? How does it know it needs to delete hero? So the
it know it needs to delete hero? So the thing is dotpop method will
thing is dotpop method will automatically delete or you can say drop
automatically delete or you can say drop or you can say pop your data from
or you can say pop your data from the end of your list by default. Okay.
the end of your list by default. Okay. So if you just want to delete the data
So if you just want to delete the data from the last just use dot pop. That's
from the last just use dot pop. That's it. That's it. That's it. That's it. We
it. That's it. That's it. That's it. We rarely delete stuff from the list but
rarely delete stuff from the list but yeah you should know about this. So
yeah you should know about this. So these are some of the functions that we
these are some of the functions that we use a lot with the list and list are
use a lot with the list and list are like your bread and butter and let me
like your bread and butter and let me just talk about a
just talk about a very you can
very you can say oftenly used question or you can say
say oftenly used question or you can say scenario. Let's say you have this this
scenario. Let's say you have this this list. Let me remove this one. Okay.
list. Let me remove this one. Okay. Let's say you have this list. If you
Let's say you have this list. If you want to reverse this list, how you can
want to reverse this list, how you can just do that? How you can do that? If
just do that? How you can do that? If you just want to reverse this list, um,
you just want to reverse this list, um, one way like there are so many ways by
one way like there are so many ways by the way and we can obviously achieve
the way and we can obviously achieve this thing using loop. If you will use
this thing using loop. If you will use your brain, you can simply run a loop on
your brain, you can simply run a loop on this particular list and from the back
this particular list and from the back instead of from the starting. Can we do
instead of from the starting. Can we do that? Yeah, let's do that. So let's say
that? Yeah, let's do that. So let's say for i in my list. Okay. So this will
for i in my list. Okay. So this will simply run the loop on the list, right?
simply run the loop on the list, right? Yes, it will do that. But what you need
Yes, it will do that. But what you need to do here, you need to tell the loop
to do here, you need to tell the loop that you want to run the loop from the
that you want to run the loop from the end, not from the beginning. How you can
end, not from the beginning. How you can do that? You can simply use a function
do that? You can simply use a function called reversed. And then you can simply
called reversed. And then you can simply say run and you will simply see 6 5 4 3
say run and you will simply see 6 5 4 3 2 1. That means we have some functions
2 1. That means we have some functions available to reverse a list. We can even
available to reverse a list. We can even say like this. Let's
say like this. Let's say my list dot
say my list dot reverse and we can just comment it out.
reverse and we can just comment it out. And if I simply print the list, it will
And if I simply print the list, it will simply make changes in the existing
simply make changes in the existing list. Uh print my list. See 6 5 4 3 2 1.
list. Uh print my list. See 6 5 4 3 2 1. But this loop method is handy when you
But this loop method is handy when you do not want to make changes in the list
do not want to make changes in the list but you just want to use a kind of
but you just want to use a kind of reverse function during runtime so that
reverse function during runtime so that you can simply make the changes
you can simply make the changes temporarily. Okay. But if you just want
temporarily. Okay. But if you just want to permanently reverse this uh the list
to permanently reverse this uh the list you can simply use this method so that
you can simply use this method so that you can actually get the result like
you can actually get the result like this. So we have dot reverse method to
this. So we have dot reverse method to make the permanent changes. Reverse
make the permanent changes. Reverse method during runtime. That's it.
method during runtime. That's it. There's one more way to make the changes
There's one more way to make the changes like this. So what's the way? So
like this. So what's the way? So basically if you simply write something
basically if you simply write something like this my list. First of all let me
like this my list. First of all let me just show you. So this is a list. Okay.
just show you. So this is a list. Okay. 1 2 3 4 5 6. Let me clear this. If you
1 2 3 4 5 6. Let me clear this. If you say colon colon minus one, it will give
say colon colon minus one, it will give you the same results. And let me just
you the same results. And let me just show
show you. Print my
list. Wait what? print my list uh colon colon minus one. Oh yeah,
list uh colon colon minus one. Oh yeah, because we just need to do print here.
because we just need to do print here. We are just simply printing the same
We are just simply printing the same stuff here and we can simply comment it
stuff here and we can simply comment it out. Simply run this and yeah perfect.
out. Simply run this and yeah perfect. So what it is doing right now? So
So what it is doing right now? So basically it is simply putting it
basically it is simply putting it here length of list. But why? Every time
here length of list. But why? Every time it puts you can say
it puts you can say zero right it is still doing that so
zero right it is still doing that so what we going to achieve we going to
what we going to achieve we going to simply iterate our list by minus one so
simply iterate our list by minus one so every time it will simply perform minus
every time it will simply perform minus one so let's say it is starting from one
one so let's say it is starting from one okay so it will simply go to six because
okay so it will simply go to six because we are just simply performing and you
we are just simply performing and you can say starting from minus one it will
can say starting from minus one it will simply go to six okay then it will
simply go to six okay then it will simply uh put here one is two but it
simply uh put here one is two but it will simply perform minus one after six
will simply perform minus one after six not after one. So that is the confusion
not after one. So that is the confusion that you need to clear. So first of all
that you need to clear. So first of all it will start from six six and then it
it will start from six six and then it will go to five simple and then four 3 2
will go to five simple and then four 3 2 1. This way you can perform reverse
1. This way you can perform reverse operation on list using indexing as
operation on list using indexing as well. It's up to you. It's up to you. So
well. It's up to you. It's up to you. So this was all about your list basically
this was all about your list basically list operations. And now I think the
list operations. And now I think the next thing that we should know is list
next thing that we should know is list comprehension. List comprehension is
comprehension. List comprehension is really important and I will first show
really important and I will first show you working with loops and list and then
you working with loops and list and then I will just show you list comprehension.
I will just show you list comprehension. So basically it is very simple and
So basically it is very simple and before that let's summarize this
before that let's summarize this indexing. I know it is a little
indexing. I know it is a little confusing but it is very easy. So let's
confusing but it is very easy. So let's say this is your list. Okay let me clear
say this is your list. Okay let me clear all the clutter. So let's say this is
all the clutter. So let's say this is your list. If you perform especially
your list. If you perform especially like
like negative list slicing is like a little
negative list slicing is like a little bit confusing. So you can simply say my
bit confusing. So you can simply say my list. Okay. And if you simply say minus
list. Okay. And if you simply say minus 3 that means it is equivalent to
3 that means it is equivalent to total minus3 and this is the end. This
total minus3 and this is the end. This is the total length of the list. Okay.
is the total length of the list. Okay. Or for the simplicity you can simply say
Or for the simplicity you can simply say it as like start. This is a starting
it as like start. This is a starting point. Okay. This is the stopping point
point. Okay. This is the stopping point start and
start and stop. So the starting point is minus3
stop. So the starting point is minus3 and it is the second analogy that we use
and it is the second analogy that we use in the real life minus three. That means
in the real life minus three. That means it will start from the minus3 elements
it will start from the minus3 elements from the behind from the let's say from
from the behind from the let's say from the right hand side. So it will simply
the right hand side. So it will simply go here 1 2 3. So this is the starting
go here 1 2 3. So this is the starting point and it will go till the end of the
point and it will go till the end of the list. That's it. 4 5 6 and we should see
list. That's it. 4 5 6 and we should see that thing. Oops. So let me say
print. Perfect. That's it. And we also learned about that we can also perform
learned about that we can also perform skipping. So if we just say let's say
skipping. So if we just say let's say two, it will skip all the elements which
two, it will skip all the elements which are like you can say it will skip two,
are like you can say it will skip two, four and six. And we also learned about
four and six. And we also learned about if we just want to reverse a list, we
if we just want to reverse a list, we can simply say like this minus one.
can simply say like this minus one. Perfect. Quick revision. That's it. Very
Perfect. Quick revision. That's it. Very good. Now let's actually understand the
good. Now let's actually understand the list comprehension. It's really
list comprehension. It's really important. So let's say this is our
important. So let's say this is our list. Okay. Let's say this is our list.
list. Okay. Let's say this is our list. Now you need to create a new list. Okay.
Now you need to create a new list. Okay. This is right now empty. Okay. This is
This is right now empty. Okay. This is the new list. Now you just want to
the new list. Now you just want to create a new list and you want to
create a new list and you want to populate this new list with the square
populate this new list with the square of every number. square of every
of every number. square of every number. Obviously, you would need to use
number. Obviously, you would need to use a loop so that you can just use every
a loop so that you can just use every value and you can just actually perform
value and you can just actually perform square on each number. So, what's the
square on each number. So, what's the traditional approach? It's like this for
traditional approach? It's like this for i in my
i in my list. Okay. And then it will simply say
list. Okay. And then it will simply say because I is the number. So, I will
because I is the number. So, I will simply say uh new
simply say uh new list dot append. And what is the append
list dot append. And what is the append value? I hrix I. Why? Because it will
value? I hrix I. Why? Because it will simply perform square of every number
simply perform square of every number and it will append the data in this list
and it will append the data in this list for all the i value. Right? Let me just
for all the i value. Right? Let me just show you the results as well. New
show you the results as well. New list and we will have new list having
list and we will have new list having square of every number. So we
square of every number. So we write so many lines of code whenever you
write so many lines of code whenever you want to use right like like this thing.
want to use right like like this thing. So first we create the empty list then
So first we create the empty list then we create a loop then we perform append
we create a loop then we perform append function. What if I can just tell you
function. What if I can just tell you that all the three lines of code can be
that all the three lines of code can be replaced by just one line of code.
replaced by just one line of code. That's where your list comprehension
helps. So what does it mean? So basically let me just comment it out.
basically let me just comment it out. Okay. And let me just show you that I
Okay. And let me just show you that I can create a new list.
can create a new list. Same way I created it. So this is my
Same way I created it. So this is my empty list. I can directly fill the data
empty list. I can directly fill the data within this. That means I can literally
within this. That means I can literally write my code within this list. Wow.
write my code within this list. Wow. Really? Yes. What I can do? I can simply
Really? Yes. What I can do? I can simply write a loop for I in my list. Okay. And
write a loop for I in my list. Okay. And then in the starting. So this is
then in the starting. So this is basically the a kind of you can say
basically the a kind of you can say um itraable
um itraable function basically a loop that you are
function basically a loop that you are applying on an object which is holding a
applying on an object which is holding a kind of iterable items. So you can
kind of iterable items. So you can simply say for i in this blah blah
simply say for i in this blah blah this. So this is simply like running a
this. So this is simply like running a kind of loop. Whatever you want to
kind of loop. Whatever you want to return you will write in the beginning
return you will write in the beginning you will simply say I a str i. That's
you will simply say I a str i. That's it. If you just say
it. If you just say print new
print new list you will see the same stuff.
list you will see the same stuff. Wow. Let's say you want to also check if
Wow. Let's say you want to also check if the numbers are odd or even. If they are
the numbers are odd or even. If they are even then only fill the data in the list
even then only fill the data in the list otherwise
otherwise not. Wow. How can we do that? So you
not. Wow. How can we do that? So you have liberty to apply condition after
have liberty to apply condition after your iterable object. You can only apply
your iterable object. You can only apply condition after the loop. So I will
condition after the loop. So I will simply say if I
simply say if I mod 2 and it's a good practice to put it
mod 2 and it's a good practice to put it in the braces equals to equals to 0.
in the braces equals to equals to 0. That is the condition for even. That
That is the condition for even. That means if your number can be easily
means if your number can be easily divisible by two and the remainder will
divisible by two and the remainder will be zero. That means it's an even number.
be zero. That means it's an even number. That's basic mathematics that you should
That's basic mathematics that you should know. Let's see the results. So I will
know. Let's see the results. So I will simply see
simply see 4 16 and 36. That's it. Because only 2,
4 16 and 36. That's it. Because only 2, 4 and six are the even numbers and other
4 and six are the even numbers and other are not even numbers. Wow.
are not even numbers. Wow. Yes. This is the power of list
Yes. This is the power of list compilation. You can even add multiple
compilation. You can even add multiple conditions. Say you want to add one more
conditions. Say you want to add one more condition which is you do not want to
condition which is you do not want to just find the square of six. You do not
just find the square of six. You do not want to include this number. So you can
want to include this number. So you can simply say
simply say if I not equals to 6. Make sense? This
if I not equals to 6. Make sense? This is our second condition. We'll simply
is our second condition. We'll simply run it and we'll simply see four and 16
run it and we'll simply see four and 16 only because six is not included. So
only because six is not included. So this way you can add multiple
this way you can add multiple conditions. So this is your output that
conditions. So this is your output that you will add in your list. This is a
you will add in your list. This is a kind of iterator that you run and these
kind of iterator that you run and these are the conditions that if you want to
are the conditions that if you want to apply these conditions on top of it. So
apply these conditions on top of it. So can you see so many lines of code are
can you see so many lines of code are aggregated in just one line of code.
aggregated in just one line of code. That's it. Otherwise you would be
That's it. Otherwise you would be creating multiple if first of all you
creating multiple if first of all you would create a for loop. Then you would
would create a for loop. Then you would create if condition then another if
create if condition then another if condition and then you will be just
condition and then you will be just returning the value and appending it in
returning the value and appending it in the new list. So this is all done within
the new list. So this is all done within just like one single line of code.
just like one single line of code. That's the power of it. Make sense?
That's the power of it. Make sense? Makes sense. So this is your list and
Makes sense. So this is your list and definitely it is really handy and it's
definitely it is really handy and it's again personal choice. Okay. Both the
again personal choice. Okay. Both the ways are good and both the ways are used
ways are good and both the ways are used in your code. If you like this way, use
in your code. If you like this way, use it. If you like this way, use it. I know
it. If you like this way, use it. I know this is simple and beginners prefer
this is simple and beginners prefer this. Okay. But once you are like
this. Okay. But once you are like writing so many lines of code, you will
writing so many lines of code, you will simply say hey I can simply apply this
simply say hey I can simply apply this but if you are like code is already
but if you are like code is already really complex then you can simply use
really complex then you can simply use this just to avoid any confusion. So
this just to avoid any confusion. So both are really good. Okay. So that is
both are really good. Okay. So that is the power of list comprehension that
the power of list comprehension that this will actually aggregate your multi-
this will actually aggregate your multi- lines of code into just one or two. Make
lines of code into just one or two. Make sense? Yeah. I think we have covered
sense? Yeah. I think we have covered almost everything that we should know
almost everything that we should know about list. Now let's cover
about list. Now let's cover the second the most the most the most
the second the most the most the most important data structure which is which
important data structure which is which is dictionary. Let me just tell you
is dictionary. Let me just tell you about that. Dictionary is the second
about that. Dictionary is the second most or I can even say like it is
most or I can even say like it is equally
equally used data structure as we use like list
used data structure as we use like list dictionary is like very much handy for
dictionary is like very much handy for data engineers. Why? Because of its
data engineers. Why? Because of its unique data storage you can say
unique data storage you can say architecture. architecture not really
architecture. architecture not really architecture let me just tell you so
architecture let me just tell you so within the list we store the data within
within the list we store the data within you can say 1D array you can say within
you can say 1D array you can say within the list like 1 2 3 4 5 wow what I
the list like 1 2 3 4 5 wow what I handwriting 1 2 3 4 5 okay but we do not
handwriting 1 2 3 4 5 okay but we do not have any kind of meaning to these values
have any kind of meaning to these values we do not know like what is one like
we do not know like what is one like what is two what is three dictionary
what is two what is three dictionary helps us to add some context text to our
helps us to add some context text to our values. So let's say I want to say x =
values. So let's say I want to say x = to 1, y = 2, z = to 3 like this. I want
to 1, y = 2, z = to 3 like this. I want to store my data in the key value pairs.
to store my data in the key value pairs. That's where dictionary is very handy
That's where dictionary is very handy and it works really well with JSON
and it works really well with JSON objects as well like JavaScript object
objects as well like JavaScript object notation because whatever data you are
notation because whatever data you are working with in data engineering, if
working with in data engineering, if you're making API calls, don't worry,
you're making API calls, don't worry, we'll just talk about that as well. So
we'll just talk about that as well. So you will be just getting the response in
you will be just getting the response in the form of JSON that is a kind of
the form of JSON that is a kind of dictionary in which like data is stored.
dictionary in which like data is stored. So now let me just tell you how data
So now let me just tell you how data will be stored in dictionary. It will
will be stored in dictionary. It will look like this. It has curly braces.
look like this. It has curly braces. Okay, it has like curly braces instead
Okay, it has like curly braces instead of square brackets. It will simply say
of square brackets. It will simply say key. Key is let's say x and it has the
key. Key is let's say x and it has the value called one. then
value called one. then second
second y then two. So this way it holds all the
y then two. So this way it holds all the variables or you can say all the keys.
variables or you can say all the keys. If you want to store your data like
If you want to store your data like this, you should always go to dictionary
this, you should always go to dictionary and dictionary is like your go-to tool
and dictionary is like your go-to tool for this or you can say basically data
for this or you can say basically data structure. Let's see in the code like
structure. Let's see in the code like how we can just work with dictionary and
how we can just work with dictionary and what are those functions that we use or
what are those functions that we use or you can say what are those operations
you can say what are those operations that we should use with dictionary. So
that we should use with dictionary. So let's try to understand dictionary. I
let's try to understand dictionary. I will simply create dictionary called uh
will simply create dictionary called uh my
my dictionary.
My dictionary okay make sense? So now what I will do I
okay make sense? So now what I will do I will simply create curly braces and then
will simply create curly braces and then I will simply say x and the value of x
I will simply say x and the value of x is let's say one. If I want to store
is let's say one. If I want to store integer if string I can simply say like
integer if string I can simply say like this. Uh sorry like this. Okay, I want
this. Uh sorry like this. Okay, I want to store integer. Then I will simply say
to store integer. Then I will simply say comma that is the next value. I will
comma that is the next value. I will simply say y and then two then z and
simply say y and then two then z and then three. Okay. Now I can simply print
then three. Okay. Now I can simply print my
dictionary. Let's see what we get. So this is a dictionary. Okay, make sense.
this is a dictionary. Okay, make sense. It behaves almost similar to list. You
It behaves almost similar to list. You can perform all the operations that you
can perform all the operations that you perform on list and obviously with the
perform on list and obviously with the different style because this is not
different style because this is not exactly same as um this your list. So if
exactly same as um this your list. So if we just want basically dictionary are
we just want basically dictionary are also mutable. You can just make changes
also mutable. You can just make changes directly to the dictionary. It is it
directly to the dictionary. It is it behaves similar to your list. So let's
behaves similar to your list. So let's say I want to change the value of x. I
say I want to change the value of x. I can simply
can simply say my dictionary. Okay.
say my dictionary. Okay. And how to change the value? Here's the
And how to change the value? Here's the thing. So you can simply use something
thing. So you can simply use something called as square brackets. Here we do
called as square brackets. Here we do not use indexes. In the list we use
not use indexes. In the list we use indexes. Here we use keys because every
indexes. Here we use keys because every value is assigned to a key. Make sense?
value is assigned to a key. Make sense? Because here we are not relying on the
Because here we are not relying on the index. Here one is assigned to
index. Here one is assigned to X. Okay. We can even change the order.
X. Okay. We can even change the order. Still we can just perform all the things
Still we can just perform all the things using the keys because we are accessing
using the keys because we are accessing the keys. So I will simply say my
the keys. So I will simply say my dictionary and
dictionary and x equals to let's say 10. Okay, let's
x equals to let's say 10. Okay, let's see what it will do. Okay, we can see
see what it will do. Okay, we can see that the value is changed. Why? Because
that the value is changed. Why? Because these are
these are mutable H. Okay, now if you just want to
mutable H. Okay, now if you just want to remove or let's say um delete any kind
remove or let's say um delete any kind of key, you can simply do that
of key, you can simply do that using pop method my dictionary. Okay.
using pop method my dictionary. Okay. and then dotpop. But here's the thing,
and then dotpop. But here's the thing, you cannot say pop because this is not
you cannot say pop because this is not relying on the index. This will not
relying on the index. This will not automatically remove your data from the
automatically remove your data from the back. It will simply say remove the key
back. It will simply say remove the key which is called Z. Let's see what do we
which is called Z. Let's see what do we get. We will simply get only two things
get. We will simply get only two things X and Y. That's it. That's it. This is
X and Y. That's it. That's it. This is your dictionary. And this is so so so
your dictionary. And this is so so so handy. This is so cool. Some of the
handy. This is so cool. Some of the things that I want to show you, you can
things that I want to show you, you can even print all the keys. Let's say you
even print all the keys. Let's say you have a very big dictionary and you just
have a very big dictionary and you just want to make sure what are the keys
want to make sure what are the keys present in that dictionary. You can
present in that dictionary. You can simply say print dictionary dot
simply say print dictionary dot keys. You will only get keys. Okay. And
keys. You will only get keys. Okay. And let's not pop this. Let's see xyz. See
let's not pop this. Let's see xyz. See it is saying that you have dictionary
it is saying that you have dictionary keys x y z and it will simply return
keys x y z and it will simply return that in the form of list. Make sense?
that in the form of list. Make sense? Now if you just want to see the values
Now if you just want to see the values you can simply like this.
Perfect values are 10 2 3 but it doesn't make any sense to see the values because
make any sense to see the values because obviously we cannot understand like what
obviously we cannot understand like what values assigned for 10 or what is a key
values assigned for 10 or what is a key for 10. So instead we use something
for 10. So instead we use something called as keys or sorry items. So if you
called as keys or sorry items. So if you just run this you will actually see x is
just run this you will actually see x is assigned with 10 y with two z with
assigned with 10 y with two z with three. Make sense? This is the power of
three. Make sense? This is the power of items. This is the power of items. So
items. This is the power of items. So this is a dictionary nothing special but
this is a dictionary nothing special but yeah it becomes very handy when you are
yeah it becomes very handy when you are just working with data engineering stuff
just working with data engineering stuff and you will be working a lot with
and you will be working a lot with dictionary that's why it is easy to
dictionary that's why it is easy to master plus easy to work with and
master plus easy to work with and obviously it can have like multiple
obviously it can have like multiple inherited dictionaries as well. So let's
inherited dictionaries as well. So let's say I create a dictionary and add um
say I create a dictionary and add um demo and I will simply create a
demo and I will simply create a dictionary within this and how it will
dictionary within this and how it will behave. I will simply add XYZ let's say
behave. I will simply add XYZ let's say within this as well. Let's add it here.
within this as well. Let's add it here. And I will simply rename it
And I will simply rename it A then B then C. Okay, let's try to see
A then B then C. Okay, let's try to see this.
this. print my
dictionary. Okay, so it has this particular dictionary, right? Make
particular dictionary, right? Make sense? Now if you just want to access
sense? Now if you just want to access element B, how you will do that? So we
element B, how you will do that? So we know that if you just want to access any
know that if you just want to access any key, we access like this demo. So if you
key, we access like this demo. So if you just print this demo only, you will get
just print this demo only, you will get the output like this. Now within this
the output like this. Now within this demo you will simply say item D. That's
demo you will simply say item D. That's it. Similar to your list instead of just
it. Similar to your list instead of just passing it like uh a kind of index you
passing it like uh a kind of index you are passing the keys. That's it. That's
are passing the keys. That's it. That's it. Make sense? Make sense? This way you
it. Make sense? Make sense? This way you can actually fetch the data which is
can actually fetch the data which is having a hierarchy of the dictionary.
having a hierarchy of the dictionary. You can actually fetch the data and
You can actually fetch the data and that's what we do in data engineering.
that's what we do in data engineering. Okay, good, good, good. What do we have
Okay, good, good, good. What do we have next? Um, okay. Okay. I already told
next? Um, okay. Okay. I already told this. Okay. Oh, that's it. Very good.
this. Okay. Oh, that's it. Very good. Now, let's
Now, let's see the very important, not so
see the very important, not so important, but yeah, it becomes very
important, but yeah, it becomes very important sometimes. So, let's talk
important sometimes. So, let's talk about sets. Now, what is a set? Let me
about sets. Now, what is a set? Let me just tell you, it is very interesting.
just tell you, it is very interesting. It is very interesting. Now let's talk
It is very interesting. Now let's talk about the sets. Sets welcome to the
about the sets. Sets welcome to the mathematics area of Python. Okay. So if
mathematics area of Python. Okay. So if you have studied mathematics in
you have studied mathematics in school and if not you would have bro
school and if not you would have bro because I think sets were there until
because I think sets were there until class 10th but again yeah I know like
class 10th but again yeah I know like people love mathematics by the way I
people love mathematics by the way I have done my bachelor's in mathematics.
have done my bachelor's in mathematics. Okay but yeah I don't know about sets
Okay but yeah I don't know about sets much because I last studied sets in
much because I last studied sets in class 10th only. I think class 11th as
class 10th only. I think class 11th as well. I don't know what I did in
well. I don't know what I did in bachelor's in mathematics. They were
bachelor's in mathematics. They were just teaching some theories and how to
just teaching some theories and how to prove one is greater than zero. I was
prove one is greater than zero. I was like what? I already know
like what? I already know this. So by the way data structure sets
this. So by the way data structure sets sets is really really handy but it can
sets is really really handy but it can sometimes
sometimes um make you confused. Why? Because of
um make you confused. Why? Because of its structure like physical structure.
its structure like physical structure. We already know lists are like this.
We already know lists are like this. Okay, dictionaries are like this. Sets
Okay, dictionaries are like this. Sets are also like this. What? How can it be
are also like this. What? How can it be like how can we store the data and how
like how can we store the data and how we will distinguish like it is a
we will distinguish like it is a dictionary or it is a set. So
dictionary or it is a set. So basically we store the data which do not
basically we store the data which do not have any kind of keys and we simply use
have any kind of keys and we simply use set for that. you will simply say an if
set for that. you will simply say an if we just want to save or store the data
we just want to save or store the data without any keys we can simply use list
without any keys we can simply use list right yes but if you just want to
right yes but if you just want to perform some mathematical operations
perform some mathematical operations what are the mathematical operations
what are the mathematical operations that we use in sets let me just give you
that we use in sets let me just give you some nostalgic heads so basically you
some nostalgic heads so basically you would seen that A equals 1 2 3 B = 4 5 6
would seen that A equals 1 2 3 B = 4 5 6 right if I want to apply a union B we
right if I want to apply a union B we can do that. If I want to apply A
can do that. If I want to apply A intersection B we can do that. So all
intersection B we can do that. So all these things are possible with the help
these things are possible with the help of
of sets. The most amazing thing is you do
sets. The most amazing thing is you do not need to worry about duplicates
not need to worry about duplicates within sets. It will automatically
within sets. It will automatically remove duplicates from your
remove duplicates from your set. Really?
set. Really? Yes.
Yes. Automatically. Oh. And you can even just
Automatically. Oh. And you can even just perform so many other things as well
perform so many other things as well that I will just show you right now.
that I will just show you right now. Okay. So if you are not good at
Okay. So if you are not good at mathematics do not worry. Now you know
mathematics do not worry. Now you know Python you can perform all those things
Python you can perform all those things things using sets. Let me just show you.
things using sets. Let me just show you. So let's clear this stuff and let's
So let's clear this stuff and let's create a set. I will simply say my set
create a set. I will simply say my set equals 1 2 3 4 5. Okay. And you will say
equals 1 2 3 4 5. Okay. And you will say this is not a dictionary. No. Are you
this is not a dictionary. No. Are you sure? Yes. Can we validate it? Yes, I
sure? Yes. Can we validate it? Yes, I will simply say
will simply say print type of my
print type of my set and I will simply get a set. See
set and I will simply get a set. See this is a set. Okay, very good. If I
this is a set. Okay, very good. If I want to print it, I will simply say
want to print it, I will simply say print my
print my set. Okay, if I add five five five55 so
set. Okay, if I add five five five55 so many times. If I just print it, I will
many times. If I just print it, I will simply see it only one time because it
simply see it only one time because it will automatically remove the
will automatically remove the duplicates. Wow, this is amazing. This
duplicates. Wow, this is amazing. This feature is not available in list. This
feature is not available in list. This is only available in set. Wow, this is
is only available in set. Wow, this is amazing. Let's say this is my set or
amazing. Let's say this is my set or let's call it as a. Okay, let's create
let's call it as a. Okay, let's create another set and let's call it as let's
another set and let's call it as let's say 10
say 10 11
11 2 5.
2 5. Okay, if I want to perform union, how I
Okay, if I want to perform union, how I can just do that? It's very simple. I'll
can just do that? It's very simple. I'll simply say perform print A dot union B.
simply say perform print A dot union B. And you will see
And you will see uh wait did I oh I didn't close the
uh wait did I oh I didn't close the set. Perfect. So now what is A union B?
set. Perfect. So now what is A union B? Obviously I'm not going to teach you
Obviously I'm not going to teach you mathematics. So in union we
mathematics. So in union we get all the nonre repeating or you can
get all the nonre repeating or you can say
say non-duplicates plus the l. So wait wait
non-duplicates plus the l. So wait wait wait anala teach some mathematics. So
wait anala teach some mathematics. So basically it will first of all fetch the
basically it will first of all fetch the a it will simply say 1 2 3 4 5 sorted.
a it will simply say 1 2 3 4 5 sorted. It will bring it. Okay perfect. Then it
It will bring it. Okay perfect. Then it will go to B and it will bring only
will go to B and it will bring only those elements which are not present in
those elements which are not present in A plus which are already present in A
A plus which are already present in A because it is already there. So it will
because it is already there. So it will simply grab 10 11 that's it and 1 2 3 4
simply grab 10 11 that's it and 1 2 3 4 5 is coming from A. So if you just take
5 is coming from A. So if you just take the V diagram of it let's say this is
the V diagram of it let's say this is your A. Okay let's say this is your
your A. Okay let's say this is your B. Make sense? So this is your A union B
B. Make sense? So this is your A union B the whole
the whole part see and this is common part will
part see and this is common part will appear only
appear only once make sense very good now let's try
once make sense very good now let's try to apply intersection now what is
to apply intersection now what is intersection let me just tell you first
intersection let me just tell you first of
of all intersection is only those elements
all intersection is only those elements which are common in both okay so only
which are common in both okay so only this area will appear in the result and
this area will appear in the result and what is that Or you can say what what
what is that Or you can say what what are those items which are common in both
are those items which are common in both 2 3 55. So we will simply see 235. I
2 3 55. So we will simply see 235. I will simply say
will simply say intersection and I will simply see 235.
intersection and I will simply see 235. Perfect.
Perfect. Now if I want to let's say remove the
Now if I want to let's say remove the set item how I can just do that. I will
set item how I can just do that. I will simply say a dot remove and whatever I
simply say a dot remove and whatever I want to remove let's say I want to
want to remove let's say I want to remove a dot remove two. Okay. If I
remove a dot remove two. Okay. If I simply say print a, you will not see two
simply say print a, you will not see two in that because we have removed it. Make
in that because we have removed it. Make sense? Similarly, you can add as well.
sense? Similarly, you can add as well. If you just want to let's say add um 20,
If you just want to let's say add um 20, it will simply add
it will simply add 20 at the end. H makes sense. Now is the
20 at the end. H makes sense. Now is the tricky question. Let's say you created a
tricky question. Let's say you created a set. Okay, you created let there's a
set. Okay, you created let there's a variable and this is the code written.
variable and this is the code written. What is it? Is it an empty dictionary or
What is it? Is it an empty dictionary or is it an empty
is it an empty set? Boom. Just tell me. So the answer
set? Boom. Just tell me. So the answer is it is an empty dictionary. I can even
is it is an empty dictionary. I can even show
you type of f. See so anal how we can create an empty
See so anal how we can create an empty set. For that you simply need to use set
set. For that you simply need to use set function. Then only you will get the
function. Then only you will get the empty set. See. Oh wow. This was
empty set. See. Oh wow. This was amazing. Yeah. Yeah. Yeah. Yeah. So this
amazing. Yeah. Yeah. Yeah. Yeah. So this was all about your sets. Now let's talk
was all about your sets. Now let's talk about one more data structure that we
about one more data structure that we have. It is called tpple. Let's talk
have. It is called tpple. Let's talk about Now let's talk about tpple. Tupel
about Now let's talk about tpple. Tupel is another very useful data structure
is another very useful data structure but not actually very useful because the
but not actually very useful because the thing is first of all let me just show
thing is first of all let me just show you the physical structure of it. It is
you the physical structure of it. It is like curly uh not curly round braces
like curly uh not curly round braces like one 2 3. Now it behaves exactly
like one 2 3. Now it behaves exactly same as a list and we data engineers
same as a list and we data engineers work more with list. So what we do what
work more with list. So what we do what do we do? We simply convert a tpple into
do we do? We simply convert a tpple into a list and we perform all the things.
a list and we perform all the things. Yeah, that's that's how we work. You
Yeah, that's that's how we work. You will say, hey, okay, we can just apply
will say, hey, okay, we can just apply all the things. What if we just want to
all the things. What if we just want to return the result in the form of duple?
return the result in the form of duple? Yeah, you can just again convert a list
Yeah, you can just again convert a list into a duple. Oh, this way the advantage
into a duple. Oh, this way the advantage of this is you will not feel confused
of this is you will not feel confused whenever you just want to apply some
whenever you just want to apply some things. Let's say I want to add the data
things. Let's say I want to add the data in the list. I will simply remember
in the list. I will simply remember append mode. I do not need to remember
append mode. I do not need to remember the method that we use in tpple, right?
the method that we use in tpple, right? I want to remove the data. I will simply
I want to remove the data. I will simply remember pop method. I do not need to
remember pop method. I do not need to remember delete method. So these things
remember delete method. So these things will make you let's say work with Python
will make you let's say work with Python with more ease because you do not need
with more ease because you do not need to mug up your mind between different
to mug up your mind between different different data structures. But yeah, you
different data structures. But yeah, you can easily convert your TPLE into list.
can easily convert your TPLE into list. And that's it. That's it. Now let's see
And that's it. That's it. Now let's see with the help of code as well so that
with the help of code as well so that you can actually understand. Let's see.
you can actually understand. Let's see. Boom. Let's create our first list. Oh,
Boom. Let's create our first list. Oh, not list tpple my two. I will simply say
not list tpple my two. I will simply say my two and I will simply say 1 2 3 4 5.
my two and I will simply say 1 2 3 4 5. Okay, let's print
it. So my tpple. So 1 2 3 4 5. Now let's say I want to add one data like add one
say I want to add one data like add one item and blah blah blah. I want to do
item and blah blah blah. I want to do all those stuff. So what I will do? We
all those stuff. So what I will do? We have methods in tpple. We have like
have methods in tpple. We have like delete method and so many methods. But
delete method and so many methods. But what I will do? So I will simply say my
what I will do? So I will simply say my top list tpple list equals list of my
top list tpple list equals list of my top. So this will simply convert this
top. So this will simply convert this into a list and then I can simply say my
into a list and then I can simply say my T
T list dot
list dot append. Okay let's say I want to add
append. Okay let's say I want to add six. Perfect. I can simply print it my T
six. Perfect. I can simply print it my T list. And then I want to convert my T
list. And then I want to convert my T list into a tpple. Right? I will simply
list into a tpple. Right? I will simply say my tpple or let's say my
say my tpple or let's say my top equals tpple
top equals tpple of my list. Make sense? And then print
of my list. Make sense? And then print this as
well my top. Let's run this code.
top. Let's run this code. Uh name tupless is not
Uh name tupless is not defined.
defined. Really? What's wrong? Oh, wait, wait,
Really? What's wrong? Oh, wait, wait, wait,
wait, wait. Tup list is not defined. Uh, top.
wait. Tup list is not defined. Uh, top. Oh, it's my it's my not
Oh, it's my it's my not list. Okay. My list is not defined. Did
list. Okay. My list is not defined. Did you mean my top list? Yeah. Yeah. Yeah.
you mean my top list? Yeah. Yeah. Yeah. I mean my top
I mean my top list.
list. Print. Perfect. So now you can see we
Print. Perfect. So now you can see we first of all printed the same tpple.
first of all printed the same tpple. Okay. Then we added the item with the
Okay. Then we added the item with the help of list and then we again convert
help of list and then we again convert it into tpple and we return the result.
it into tpple and we return the result. In most of the scenarios you would not
In most of the scenarios you would not be required to convert it back to a
be required to convert it back to a tuple. Trust me. But if you have to have
tuple. Trust me. But if you have to have to convert it you have the method ready
to convert it you have the method ready you can easily convert your tpple into a
you can easily convert your tpple into a like list into a tpple back. Okay. So
like list into a tpple back. Okay. So that's how you work with tpple. H. So we
that's how you work with tpple. H. So we have covered almost all the important
have covered almost all the important data structures that we have for data
data structures that we have for data engineering. list and dictionary are
engineering. list and dictionary are your top
your top priorities that you have to master. Now
priorities that you have to master. Now let's try to master something very
let's try to master something very important functions. Okay,
important functions. Okay, functions are like non-negotiables for
functions are like non-negotiables for anyone not even like for data engineers
anyone not even like for data engineers anyone. Let's try to understand like
anyone. Let's try to understand like what are functions? How we can just
what are functions? How we can just create functions? Let's do that. Talk
create functions? Let's do that. Talk about the functions. Basically what is a
about the functions. Basically what is a function? function basically in like
function? function basically in like let's say in short I would say functions
let's say in short I would say functions help
help you from rewriting the code again and
you from rewriting the code again and again okay let's understand it with an
again okay let's understand it with an example so let's say you have written 50
example so let's say you have written 50 lines of code
lines of code okay 50 lines of
code now within your program within your program you need to reuse these 50 lines
program you need to reuse these 50 lines of code again. Okay. Okay. Now what you
of code again. Okay. Okay. Now what you will do? You will simply copy and paste.
will do? You will simply copy and paste. Okay. And you will simply just add these
Okay. And you will simply just add these lines of code in your program. Okay. One
lines of code in your program. Okay. One time is good. Okay. Just do that. Let's
time is good. Okay. Just do that. Let's do this. Then let's say again you need
do this. Then let's say again you need to do that. Okay. Then again, then
to do that. Okay. Then again, then again, then
again, then again let's say you need to use these 50
again let's say you need to use these 50 lines of code 10 times in your code. So
lines of code 10 times in your code. So you are literally adding 500 lines of
you are literally adding 500 lines of code in your program. 500 lines of code.
code in your program. 500 lines of code. Wow. What if I say that you can reduce
Wow. What if I say that you can reduce these numbers from 500 to 55 or let's
these numbers from 500 to 55 or let's say
say 260. How is this possible? Basically, it
260. How is this possible? Basically, it is possible because these 50 lines of
is possible because these 50 lines of code will
be registered under a function and you can call this function directly using
can call this function directly using one line of code. And if you just want
one line of code. And if you just want to use this 50 lines of code 10 times,
to use this 50 lines of code 10 times, you will just make 10 calls and each
you will just make 10 calls and each call will hardly take only one line. So
call will hardly take only one line. So that's why you will end up having only
that's why you will end up having only 60 co 60 lines of code. Plus, it will
60 co 60 lines of code. Plus, it will promote readability.
promote readability. Okay. So, An Lamba, what if I want to
Okay. So, An Lamba, what if I want to make some changes in these lines? Then
make some changes in these lines? Then is it possible? Yes. Because you add
is it possible? Yes. Because you add something called as parameters in the
something called as parameters in the functions. Oh, that's the whole concept
functions. Oh, that's the whole concept of function. Instead of rewriting the
of function. Instead of rewriting the code again and again, it will simply ask
code again and again, it will simply ask you, hey, you can simply reuse the code
you, hey, you can simply reuse the code using a function. I know you are really
using a function. I know you are really excited to see this in Python. So let me
excited to see this in Python. So let me actually show you everything using the
actually show you everything using the code because you will understand better
code because you will understand better using the code. Let me
using the code. Let me just so here we are. So first of all let
just so here we are. So first of all let me just take an example. Let's say you
me just take an example. Let's say you have written a code let's say similar to
have written a code let's say similar to this x= to 10 and you are saying
if greater than [Music]
[Music] 10
10 else print
um I don't know okay so if I Just run this. Okay, I got I don't know. Let's
this. Okay, I got I don't know. Let's say you want to reuse this code in your
say you want to reuse this code in your program. You will simply copy and paste
program. You will simply copy and paste it. This time you will simply say 12 and
it. This time you will simply say 12 and you will simply run it. Perfect. Then
you will simply run it. Perfect. Then let's say third time. This time it is 15
let's say third time. This time it is 15 or let's say
or let's say 20. Okay. Again. Let's
say five. So why I am adding these lines of code
So why I am adding these lines of code again and again? Because you want to use
again and again? Because you want to use it. Yeah. But I do not want to use it
it. Yeah. But I do not want to use it like this. So that's where you can use a
like this. So that's where you can use a function. So what I will do, I will
function. So what I will do, I will simply copy this code. Okay. And I will
simply copy this code. Okay. And I will remove everything. I will create a
remove everything. I will create a function from scratch. How you can
function from scratch. How you can create a function? You will simply say
create a function? You will simply say def that is the syntax. Okay. Defen
def that is the syntax. Okay. Defen function name. My function is my
function name. My function is my function.
function. Perfect. Then you simply need to write
Perfect. Then you simply need to write your logic. Whatever you want to do, the
your logic. Whatever you want to do, the same stuff. Whatever you want to do,
same stuff. Whatever you want to do, simply write the logic and that's it.
simply write the logic and that's it. That's it. If I run this, it will simply
That's it. If I run this, it will simply create the function for me. If I want to
create the function for me. If I want to call this function, I will use something
call this function, I will use something like this. My function and then that's
like this. My function and then that's it. You will see the output. Now, x is
it. You will see the output. Now, x is not defined. Obviously, we need to first
not defined. Obviously, we need to first define the x because x is not there.
define the x because x is not there. x equals to let's say 10. Let's call
x equals to let's say 10. Let's call this. Perfect. We got the output. Let's
this. Perfect. We got the output. Let's say I want to call this function for
say I want to call this function for different value of x. What I can do? I
different value of x. What I can do? I can simply do like this x= to 11 and
can simply do like this x= to 11 and then my
then my function. Perfect. See, very good. If I
function. Perfect. See, very good. If I just want to make this call for a
just want to make this call for a different value of x, I can do the same
different value of x, I can do the same stuff x= to 12 and do this. It is nice
stuff x= to 12 and do this. It is nice but we can optimize this by adding a
but we can optimize this by adding a parameter. Okay, let me just remove
parameter. Okay, let me just remove everything. Let's say I want to run this
everything. Let's say I want to run this function for a different value of X
function for a different value of X every time. Okay, so what I will do, I
every time. Okay, so what I will do, I will even remove X from here. I will
will even remove X from here. I will simply create a parameter inside this
simply create a parameter inside this function and I will simply name it as
function and I will simply name it as P_X. That means parameter X and then I
P_X. That means parameter X and then I will simply use that parameter inside
will simply use that parameter inside this function as well. And now you will
this function as well. And now you will say hey An lamba that is fine but how we
say hey An lamba that is fine but how we can provide the value of this parameter.
can provide the value of this parameter. We will provide this value during
We will provide this value during calling the function. I will simply say
calling the function. I will simply say 20 and it's good. Wow. Let's say you
20 and it's good. Wow. Let's say you want to run this function for a
want to run this function for a different value. You will simply
different value. You will simply say my function
say my function 30. Okay. Makes sense. Make sense. Now
30. Okay. Makes sense. Make sense. Now in real life you always return something
in real life you always return something from a function. Okay we know that we
from a function. Okay we know that we are printing the values that is fine but
are printing the values that is fine but in most of the cases in the real world
in most of the cases in the real world as well you will return something from a
as well you will return something from a function. Let's say you want to return
function. Let's say you want to return px just to check like what is the value
px just to check like what is the value of it. You can simply run it. You will
of it. You can simply run it. You will simply say let me first remove this as
simply say let me first remove this as well. You will simply say hey an nothing
well. You will simply say hey an nothing is returned.
is returned. Yeah, there's a difference
Yeah, there's a difference between
between print and return. Okay, print will
print and return. Okay, print will simply display the output. But return
simply display the output. But return can be stored. Oh, we cannot store this
can be stored. Oh, we cannot store this statement greater than 10. We can store
statement greater than 10. We can store this return statement. Let's say you
this return statement. Let's say you want to store the output of this
want to store the output of this function, not output basically the
function, not output basically the return value of this function in a
return value of this function in a variable. I will simply say
return value equals to this and I can even print it. let's say returned value
even print it. let's say returned value or even I can use it let's say in my
or even I can use it let's say in my upcoming code
upcoming code right perfect that's how we store the
right perfect that's how we store the value that's why we always say return
value that's why we always say return command is even more important than your
command is even more important than your print command because in the real world
print command because in the real world you do not need to display anything
you do not need to display anything using functions you actually return
using functions you actually return something make sense this was very basic
something make sense this was very basic example let's level up okay how how how
example let's level up okay how how how let's add multiple parameters okay let's
let's add multiple parameters okay let's say
say Let's
Let's say you are using multiple parameters
say you are using multiple parameters for any reason. Okay. And you are even
for any reason. Okay. And you are even returning it. Let me remove if else
returning it. Let me remove if else because that concept is clear for you.
because that concept is clear for you. And now we are just focusing on
And now we are just focusing on something critical. So I will simply say
something critical. So I will simply say py and I will simply add another
py and I will simply add another parameter here as well. Make sense? Now
parameter here as well. Make sense? Now if I just make a call to this function,
if I just make a call to this function, it will throw me an error. Why? Because
it will throw me an error. Why? Because it will say bro your function needs two
it will say bro your function needs two parameters. You are passing only one. So
parameters. You are passing only one. So it is not fair. Pass the second one as
it is not fair. Pass the second one as well. I will simply say 30. Now it is
well. I will simply say 30. Now it is good. Very good. Now the thing is let's
good. Very good. Now the thing is let's use print. Okay. Just to see the
use print. Okay. Just to see the results.
So perfect. Very good. Now can we do the reverse of it? Let's say
reverse of it? Let's say um even before reversing it. Let's say
um even before reversing it. Let's say you do not want to pass this value 30.
you do not want to pass this value 30. You will only pass the value for
You will only pass the value for px. Can we do this? Yes. That's where
px. Can we do this? Yes. That's where the use of default values come into the
the use of default values come into the picture. You can actually decide the
picture. You can actually decide the default values of these parameters so
default values of these parameters so that even if your user is missing any
that even if your user is missing any value, your code will not fail. You can
value, your code will not fail. You can simply say 30. So you will simply see 20
simply say 30. So you will simply see 20 30. Why? Because it will use the default
30. Why? Because it will use the default value if it is not being passed from
value if it is not being passed from here. But you cannot do the reverse of
here. But you cannot do the reverse of it. That means you cannot do like this.
it. That means you cannot do like this. Let's say this is py or or wait what if
Let's say this is py or or wait what if you pass the value here if your variable
you pass the value here if your variable is already given it will simply override
is already given it will simply override it see this will take the priority this
it see this will take the priority this 30 will only be used if this value is
30 will only be used if this value is not passed okay I hope like it was
not passed okay I hope like it was understood but still I wanted to discuss
understood but still I wanted to discuss okay now let's do that particular
okay now let's do that particular scenario
scenario where you do not
where you do not have the third variable parameter and
have the third variable parameter and you are passing that variable, what will
you are passing that variable, what will happen in this case? It will simply
happen in this case? It will simply throw an error. But in some
throw an error. But in some scenarios, in some scenarios, your user
scenarios, in some scenarios, your user can pass multiple you can say inputs or
can pass multiple you can say inputs or if you're just using a function to get
if you're just using a function to get the data as an input. You can get like
the data as an input. You can get like so many values, right? So in that
so many values, right? So in that scenario, what you do? You simply make
scenario, what you do? You simply make use of something called as ax and then
use of something called as ax and then you define only one parameter. So what
you define only one parameter. So what it will do? It
it will do? It will take so many values. You can pass
will take so many values. You can pass so many values now. There's no limit
so many values now. There's no limit because asterisk will take care of it.
because asterisk will take care of it. Asterisk will convert all these values
Asterisk will convert all these values in a
in a tuple. Wow. And I can even show you bro.
tuple. Wow. And I can even show you bro. Let me just run this. See this is a
Let me just run this. See this is a tpple. You can even show
tpple. You can even show the you can
the you can say data type of it. I will simply say
say data type of it. I will simply say type of
type of px and you will see tpple. Wow. So now
px and you will see tpple. Wow. So now there's no need to worry. You can pass
there's no need to worry. You can pass one 2 100,000 so many
one 2 100,000 so many parameters. Okay. That makes sense. That
parameters. Okay. That makes sense. That makes sense.
makes sense. Now I want to talk about something more
Now I want to talk about something more critical. Let's level up a little bit
critical. Let's level up a little bit more. Let's say so here you are simply
more. Let's say so here you are simply passing the values right? You are not
passing the values right? You are not passing the keys. So you are not
passing the keys. So you are not actually worrying about the keys. What
actually worrying about the keys. What if you want to assign the keys as well?
if you want to assign the keys as well? Let's say x= 20, y = to 60, z= to 70 and
Let's say x= 20, y = to 60, z= to 70 and so on. And you want to use these keys as
so on. And you want to use these keys as well. In that scenario, in that
well. In that scenario, in that scenario, let's say you are passing your
scenario, let's say you are passing your function like this. X= to 20, Y= to 60,
function like this. X= to 20, Y= to 60, Z= to 70. Like this. Now what it will
Z= to 70. Like this. Now what it will do? It will not obviously take it Y. If
do? It will not obviously take it Y. If you just run this, it will simply say,
you just run this, it will simply say, hey, what is this X= to 20? I don't know
hey, what is this X= to 20? I don't know X. I don't know these keys. Then you
X. I don't know these keys. Then you simply add one more axis. What it will
simply add one more axis. What it will do? It will convert this into a
do? It will convert this into a dictionary. It will convert it like
dictionary. It will convert it like this.
this. X 20 then
X 20 then Y 60 and so on. Wow. Let me run this and
Y 60 and so on. Wow. Let me run this and you will see this is a dictionary and
you will see this is a dictionary and type is dictionary. So if you even want
type is dictionary. So if you even want to print let's say keys of it, you can
to print let's say keys of it, you can even use it. It's not just you just want
even use it. It's not just you just want to use values, you can even use keys.
to use values, you can even use keys. See keys.
Boom. This is really helpful. This is really helpful. And I hope it makes
really helpful. And I hope it makes sense to use these
sense to use these things. This is the best way to work
things. This is the best way to work with a function. Okay, make sense? Very
with a function. Okay, make sense? Very good. Now it's time to discuss something
good. Now it's time to discuss something more important and those are called
more important and those are called lambda functions. Basically, there's a
lambda functions. Basically, there's a big debate because some people do like
big debate because some people do like functions like normal functions like
functions like normal functions like this. Some like lambda functions. I
this. Some like lambda functions. I personally like these functions more. It
personally like these functions more. It promotes readability and it gives you
promotes readability and it gives you flexibility to write your complex logics
flexibility to write your complex logics as well. Lambda functions are like mini
as well. Lambda functions are like mini functions, lightweight functions that
functions, lightweight functions that you should use if you do not have much
you should use if you do not have much stuff to do. Let's say you are writing a
stuff to do. Let's say you are writing a function and your function is doing an
function and your function is doing an addition. Okay, this is your function.
addition. Okay, this is your function. It takes two parameters XY and just
It takes two parameters XY and just print.
print. Okay, it just print or let's say return
Okay, it just print or let's say return x + y or let's say
x + y or let's say return x + y. Simple. If you just call
return x + y. Simple. If you just call it, you will simply say addition 1020
it, you will simply say addition 1020 and this is return. So, we need to save
and this is return. So, we need to save it in a variable. So, I'll simply say
it in a variable. So, I'll simply say variable and print
variable. Okay, makes sense. Makes sense. Makes sense. Makes
sense. Makes sense. Makes sense. Okay, 30. Makes sense. So this is
sense. Okay, 30. Makes sense. So this is one way of doing it. What is the other
one way of doing it. What is the other way of doing it? You can even create
way of doing it? You can even create lambda function. Now this is really
lambda function. Now this is really important and sometime it becomes really
important and sometime it becomes really useful because if you are doing
useful because if you are doing something like this that we just did, it
something like this that we just did, it doesn't make any sense to just create a
doesn't make any sense to just create a function and then just use it for just
function and then just use it for just basic stuff and if you are not reusing
basic stuff and if you are not reusing your code much. So in that scenario you
your code much. So in that scenario you can simply create a lambda function.
can simply create a lambda function. Okay. So what that function will do that
Okay. So what that function will do that function will not get actually stored.
function will not get actually stored. Okay, it will simply perform the
Okay, it will simply perform the operation and that's it. So you're not
operation and that's it. So you're not actually registering that function like
actually registering that function like you can register but you can simply
you can register but you can simply write the lambda function as well. I
write the lambda function as well. I know it doesn't make any sense to talk
know it doesn't make any sense to talk like this. Let me just show you. So
like this. Let me just show you. So let's say you want to create function
let's say you want to create function called addition but this time you want
called addition but this time you want to use
to use lambda. Okay, what it will do? This is
lambda. Okay, what it will do? This is the function name. This is the function
the function name. This is the function that is lambda. Like that is you can say
that is lambda. Like that is you can say kind of structure syntax that we need to
kind of structure syntax that we need to follow lambda. Then we need to define
follow lambda. Then we need to define the parameter. Parameter is let's say x
the parameter. Parameter is let's say x or y. Two parameters. Okay. Then we add
or y. Two parameters. Okay. Then we add colon. Then what we need to return? We
colon. Then what we need to return? We need to return x + y. That's it. So this
need to return x + y. That's it. So this whole thing this whole thing is replaced
whole thing this whole thing is replaced with this. You do not need to write any
with this. You do not need to write any syntax. You need do not need to write
syntax. You need do not need to write any perform any indentation. No, just
any perform any indentation. No, just one line. Just one line. Let me just
one line. Just one line. Let me just uncomment it so you so that you can see.
uncomment it so you so that you can see. So this code is equivalent to this
So this code is equivalent to this one. Make sense? Addition addition you
one. Make sense? Addition addition you do not need to write df equals to
do not need to write df equals to instead of def you will write lambda.
instead of def you will write lambda. These are the parameters here and this
These are the parameters here and this is a returning value. That's it. That's
is a returning value. That's it. That's it. Now you can even use it same way.
it. Now you can even use it same way. You can simply say addition
You can simply say addition um we already have the calling
um we already have the calling statement. I will simply copy it from
here and let me uncomment it. Let's run this. You will simply get 30 perfect
this. You will simply get 30 perfect using this lambda function. So if you
using this lambda function. So if you are using something lightweight like
are using something lightweight like this, it makes sense to use just like
this, it makes sense to use just like one line of code. Okay, if you are doing
one line of code. Okay, if you are doing something heavy complex logic then
something heavy complex logic then obviously go with this traditional
obviously go with this traditional function. Okay, this is just for like
function. Okay, this is just for like lightweight functions. Make sense? So
lightweight functions. Make sense? So these are your functions. Now let's see
these are your functions. Now let's see what do we have in combination with
what do we have in combination with these functions. We have three popular
these functions. We have three popular kinds of operations that we perform with
kinds of operations that we perform with function. One is map, second is filter,
function. One is map, second is filter, third is reduce. Map, filter and reduce.
third is reduce. Map, filter and reduce. Let's uncover those topics. What are
Let's uncover those topics. What are map, filter and reduce? What are these
map, filter and reduce? What are these things? So basically these are the
things? So basically these are the functions or you can say these are the
functions or you can say these are the special you can say capabilities that we
special you can say capabilities that we get within Python. So what it what it
get within Python. So what it what it does? Let's say you created your
does? Let's say you created your function using DF or let's say lambda.
function using DF or let's say lambda. The choice is yours. Now you want to
The choice is yours. Now you want to perform that part. So let's say your
perform that part. So let's say your function is like relying on
function is like relying on just few parameters or you can say
just few parameters or you can say independent par parameters but you want
independent par parameters but you want to just perform that particular function
to just perform that particular function on an iterable. Let's say you have a
on an iterable. Let's say you have a list 1 2 3 4 5. You want to perform this
list 1 2 3 4 5. You want to perform this function on top of this list. That means
function on top of this list. That means on each element of the list. Let's say 1
on each element of the list. Let's say 1 2 3 4 5 and then you want to just create
2 3 4 5 and then you want to just create a new list based on
a new list based on this. Make sense? One one possible
this. Make sense? One one possible scenario can be is list comprehension
scenario can be is list comprehension that we can simply apply that logic
that we can simply apply that logic again and again. But if you have a
again and again. But if you have a function you can reuse that logic right
function you can reuse that logic right we can reuse that logic. Now you will
we can reuse that logic. Now you will simply say hey um why do we need to use
simply say hey um why do we need to use map filter reduce? We can simply create
map filter reduce? We can simply create a function for a list. Right. Exactly.
a function for a list. Right. Exactly. We can we can we can simply create a
We can we can we can simply create a function which will take a list. We can
function which will take a list. We can but the thing
but the thing is by that way we cannot handle the
is by that way we cannot handle the operation or you can say logic of
operation or you can say logic of function for individual values or a
function for individual values or a list. We have to create separate
list. We have to create separate functions. But by using map filter and
functions. But by using map filter and reduce we can actually apply the
reduce we can actually apply the functions that are handling the
functions that are handling the individual values and we can actually um
individual values and we can actually um perform that particular function on each
perform that particular function on each item of the iterable. Let's say this is
item of the iterable. Let's say this is a list which is the most common iterable
a list which is the most common iterable for data
for data engineers. Make sense? Let me show you
engineers. Make sense? Let me show you with the help of code and let's try to
with the help of code and let's try to first of all understand map. Okay let's
first of all understand map. Okay let's see. So let's say you have a list. You
see. So let's say you have a list. You have a list called my list. 1 2 3 4
have a list called my list. 1 2 3 4 5. Okay. Now you want to perform a
5. Okay. Now you want to perform a square of each
square of each particular number within this. Okay. If
particular number within this. Okay. If you just rewrite the code using
you just rewrite the code using function, you will simply say def. Okay.
function, you will simply say def. Okay. Let's say my
Let's say my function or you can say
square. Okay. Now you will simply take the parameter x okay and you will simply
the parameter x okay and you will simply say
say return return
return return um let's say because you know that this
um let's say because you know that this is a list so you will simply
is a list so you will simply perform list like this so you will
perform list like this so you will simply take the list and you can simply
simply take the list and you can simply create your own list let's say return
create your own list let's say return list okay return list and you are simply
list okay return list and you are simply saying that for
saying that for inpx
inpx return i istic
return i istic I make sense. Okay. And then you will
I make sense. Okay. And then you will simply say
print return list. Make sense? Now this function will help you not to
Now this function will help you not to write this code again and again. This
write this code again and again. This particular comprehension you can simply
particular comprehension you can simply save it in the function. Okay. Then you
save it in the function. Okay. Then you will simply say
will simply say um you will call this function my list.
um you will call this function my list. Okay. And then you will simply pass the
Okay. And then you will simply pass the list. Let's say my
list. Let's say my list. And that's it. Let's see the
list. And that's it. Let's see the output. Uh error list is not callable.
output. Uh error list is not callable. Wait, let me see what's
Wait, let me see what's wrong. Oh, this is square,
wrong. Oh, this is square, bro. So, uh real list is not defined.
bro. So, uh real list is not defined. So, this is the function square. This is
So, this is the function square. This is my
my list. Red
list. Red list. Oh, typo.
list. Oh, typo. Perfect. So it returned this 1 4 9 16
Perfect. So it returned this 1 4 9 16 25. Makes sense. But we have created
25. Makes sense. But we have created this function which is just accepting
this function which is just accepting list. What if I want to create a
list. What if I want to create a function which is called def
function which is called def squared def square that will take the
squared def square that will take the individual number and it will simply
individual number and it will simply return x uh
return x uh px let's say px into px
px let's say px into px basically square of
basically square of it
simple make sense So you want to create this function. What is the advantage of
this function. What is the advantage of this function? Because this way you can
this function? Because this way you can even pass an individual number and you
even pass an individual number and you can even pass a list. We cannot even
can even pass a list. We cannot even pass a list. You can using map method.
pass a list. You can using map method. So what we going to do? We will simply
So what we going to do? We will simply create this function and it is running
create this function and it is running fine. Code execution successful. Very
fine. Code execution successful. Very good. So now what we will do? We will
good. So now what we will do? We will simply say that
simply say that map. Okay. We simply need to write map
map. Okay. We simply need to write map and then the function. Function is
and then the function. Function is square. Square spelling is right. S Q U
square. Square spelling is right. S Q U A R E. Yep. Square. Then you need to
A R E. Yep. Square. Then you need to pass the iterable. Itable is my
pass the iterable. Itable is my list. Oh, okay. Simple. And I will
list. Oh, okay. Simple. And I will simply create a variable on top of it
simply create a variable on top of it called result. And I will just show you.
called result. And I will just show you. Obviously, nothing will be in the output
Obviously, nothing will be in the output because I know that this is actually
because I know that this is actually what this is doing. This is simply
what this is doing. This is simply mapping this function to each item of
mapping this function to each item of this particular list. And what it is
this particular list. And what it is doing? It is simply returning px into
doing? It is simply returning px into px. Now we need to store this result of
px. Now we need to store this result of each item into a list. That's why we'll
each item into a list. That's why we'll simply say
simply say list. We'll simply convert this output
list. We'll simply convert this output into a list. And
into a list. And that's you can just do right now. print
that's you can just do right now. print result and you should see it here.
result and you should see it here. Perfect. 1 4 9 1625. Very good. If you
Perfect. 1 4 9 1625. Very good. If you do not do this, if you do not do this,
do not do this, if you do not do this, you will actually see just map object.
you will actually see just map object. That means it is actually mapping this
That means it is actually mapping this function to each item 1 2 3 4 5 UR. But
function to each item 1 2 3 4 5 UR. But you need to convert that mapped object
you need to convert that mapped object into a specific kind of data structure.
into a specific kind of data structure. It can be either tpple. It can be uh
It can be either tpple. It can be uh either you can say list. So if you just
either you can say list. So if you just write in a
tpple and then if you just run it, you should see a tpple. If you just want to
should see a tpple. If you just want to convert it into a list, you can just
convert it into a list, you can just write list. Most probably you will just
write list. Most probably you will just convert it into a list. That's the whole
convert it into a list. That's the whole point of creating this function and
point of creating this function and taking just only one value instead of a
taking just only one value instead of a list. Then map this function to iterate
list. Then map this function to iterate it through each item of this particular
it through each item of this particular list. That's the whole concept of map.
list. That's the whole concept of map. Okay. Now what is the filter? What is
Okay. Now what is the filter? What is filter? Let's say in your particular
filter? Let's say in your particular code you are only returning this value
code you are only returning this value if
if uh
uh px mod
px mod 2 equals to equals to zero that
means if this number is even only then you are returning it. So basically you
you are returning it. So basically you are taking a number and then what you
are taking a number and then what you are doing you are simply returning only
are doing you are simply returning only and only if that particular condition is
and only if that particular condition is met. So in that scenario you use
met. So in that scenario you use something called as filter. Why? Let's
something called as filter. Why? Let's let's not use filter. Let's see what
let's not use filter. Let's see what will happen here. Okay. So it will
will happen here. Okay. So it will simply say none because this condition
simply say none because this condition is not met. Then four then none then 16
is not met. Then four then none then 16 then none.
then none. Filter helps us to remove those none
Filter helps us to remove those none none none none none. It will simply
none none none none. It will simply first of all it will do exactly the same
first of all it will do exactly the same stuff that map is doing. It will simply
stuff that map is doing. It will simply apply the filter or not filter like
apply the filter or not filter like apply the function on each item 1 2 3 4
apply the function on each item 1 2 3 4 5 check it and it will return only and
5 check it and it will return only and only if condition is met. Okay, that's
only if condition is met. Okay, that's the uh you can say use of map, right? It
the uh you can say use of map, right? It will simply apply it and if yes it will
will simply apply it and if yes it will get the result and it will just convert
get the result and it will just convert it into a list. But we are seeing none
it into a list. But we are seeing none none none that we should not see. That
none none that we should not see. That means we need to filter our list. Then
means we need to filter our list. Then we can simply use
we can simply use filter. When we use
filter. When we use filter it will not return none. It will
filter it will not return none. It will simply return two and four. That's it.
simply return two and four. That's it. Make sense? Uh I do not use filter much.
Make sense? Uh I do not use filter much. Okay. I just use map. Um sometimes I use
Okay. I just use map. Um sometimes I use filter but not very often. Yeah. Yeah.
filter but not very often. Yeah. Yeah. Yeah. Yeah. So two things are covered.
Yeah. Yeah. So two things are covered. Now what is this reduce? Now what is
Now what is this reduce? Now what is this reduce? Let's
this reduce? Let's say let's say in this your list. Okay
say let's say in this your list. Okay you are taking let's say two variables
you are taking let's say two variables like two two parameters px and py and
like two two parameters px and py and you are actually
you are actually returning px +
returning px + py. Okay. So you are actually turning
py. Okay. So you are actually turning this. Okay, let me perform this. Okay,
this. Okay, let me perform this. Okay, and let's first of all try with map so
and let's first of all try with map so that you can actually see. So let's try
that you can actually see. So let's try it with map. So what it will do? Error.
it with map. So what it will do? Error. Why? Because it needs to apply this
Why? Because it needs to apply this function. Okay, this square function on
function. Okay, this square function on top of this each item. Map performs the
top of this each item. Map performs the like uh runs the function on each item.
like uh runs the function on each item. Filter runs the function on each item
Filter runs the function on each item but reduce works something different.
but reduce works something different. What reduce will
What reduce will do? Reduce will first take the first two
do? Reduce will first take the first two elements of your list. It will simply
elements of your list. It will simply apply that particular function on those
apply that particular function on those two elements. Make sense? It will become
two elements. Make sense? It will become three. 1 + 2 equals to three. So it
three. 1 + 2 equals to three. So it reduce the list. Then it will say 3 + 3
reduce the list. Then it will say 3 + 3 it will become 6. Then it will say 6 + 4
it will become 6. Then it will say 6 + 4 it becomes 10. Then 10 + 5 it becomes
it becomes 10. Then 10 + 5 it becomes five. So it will keep on reducing the
five. So it will keep on reducing the list. Let me run this and you will see
list. Let me run this and you will see error. Wow. Reduce is not defined. Wait
error. Wow. Reduce is not defined. Wait wait wait wait. List and reduce. Oh
wait wait wait. List and reduce. Oh obviously because this is not a list. So
obviously because this is not a list. So let me run this. Error. Wait wait wait
let me run this. Error. Wait wait wait wait. Result equals
wait. Result equals reduce. I think there's a typo. Hold on.
reduce. I think there's a typo. Hold on. I think we first need to import this
I think we first need to import this function. I'm not sure. Let me just see
function. I'm not sure. Let me just see from funk tools. import
uh reduce. Let's see if it works. Yeah, it works. So, basically
works. Yeah, it works. So, basically this is not a built-in function. We need
this is not a built-in function. We need to import it. So, that's why map and
to import it. So, that's why map and your filter both are like inbuilt. But
your filter both are like inbuilt. But yeah for for reduce you need to just
yeah for for reduce you need to just reduce uh not reduce like pull it from
reduce uh not reduce like pull it from funk tools. Make sense? Make sense?
funk tools. Make sense? Make sense? Makes sense. Makes sense. So this is
Makes sense. Makes sense. So this is your reduce function. Reduce is a
your reduce function. Reduce is a function that I have used like so so so
function that I have used like so so so rarely. I do not like use reduce
rarely. I do not like use reduce function. But yeah map function is your
function. But yeah map function is your go-to function when you have an iterable
go-to function when you have an iterable when you just want to perform your
when you just want to perform your function on each item of the um you can
function on each item of the um you can say list. Your go-to function. Filter I
say list. Your go-to function. Filter I sometimes use because in most of the
sometimes use because in most of the cases I simply need to apply my function
cases I simply need to apply my function on each element of the list. Map is your
on each element of the list. Map is your function. Map you should just master
function. Map you should just master map. Filter is fine. Reduce is like very
map. Filter is fine. Reduce is like very rare scenario but you should know about
rare scenario but you should know about this. You should know because in some
this. You should know because in some scenarios you can just tackle with some
scenarios you can just tackle with some use cases where you need to use reduce.
use cases where you need to use reduce. Okay. So this is all about your
Okay. So this is all about your functions and using those special forces
functions and using those special forces of Python map filter and reduce. Make
of Python map filter and reduce. Make sense? Makes sense. Makes sense. Make
sense? Makes sense. Makes sense. Make sense. Make some noise in the comments
sense. Make some noise in the comments right now if you liked it. Let me see
right now if you liked it. Let me see what do I have more in the checklist.
what do I have more in the checklist. Okay. Done.
Okay. Done. Done. Files we are not covering because
Done. Files we are not covering because it's fine because it's not very much
it's fine because it's not very much important from data engineing point of
important from data engineing point of view. Uh then functions are already
view. Uh then functions are already done. Oh, let's cover this. Let's cover
done. Oh, let's cover this. Let's cover this.
this. So, copy list. Uh this is fine.
Okay, basically before like recording this video, I was literally planning
this video, I was literally planning like what I need to cover and what I not
like what I need to cover and what I not need to cover because there's like so
need to cover because there's like so many things. Now let's talk about
many things. Now let's talk about exceptional handling in Python and this
exceptional handling in Python and this is
is your non-negotiable because whenever
your non-negotiable because whenever you're writing your code let's say in
you're writing your code let's say in pispark anything you have to handle
pispark anything you have to handle exceptions okay or you can say you can
exceptions okay or you can say you can you have to handle those things. So it
you have to handle those things. So it is very much popular in other
is very much popular in other programming languages called try catch
programming languages called try catch method but in Python we call it as try
method but in Python we call it as try except method not try catch method and I
except method not try catch method and I also call it as like try accept method.
also call it as like try accept method. So basically what why do we need try
So basically what why do we need try except or basically what is like try
except or basically what is like try except method. It's very handy. Let me
except method. It's very handy. Let me just tell you what's that. So let's talk
just tell you what's that. So let's talk about exception handling. What is
about exception handling. What is exception handling? Let's say you are
exception handling? Let's say you are writing your code. Okay let's say this
writing your code. Okay let's say this is you and you are writing your code.
is you and you are writing your code. You are a pro developers and you do not
You are a pro developers and you do not get any errors in your code. You are a
get any errors in your code. You are a pro pro developer. Okay, let's say this
pro pro developer. Okay, let's say this is your code. This is one block of code.
is your code. This is one block of code. There's a second block of code. This is
There's a second block of code. This is third block of code and so on. Okay, but
third block of code and so on. Okay, but let's say by chance by chance I know
let's say by chance by chance I know this cannot happen with you, right? But
this cannot happen with you, right? But by chance this block of code actually
by chance this block of code actually failed. Oh, okay. By by chance. Okay. So
failed. Oh, okay. By by chance. Okay. So in that particular scenario, rest of the
in that particular scenario, rest of the blocks will not be running because it
blocks will not be running because it faced an error. But you want to avoid
faced an error. But you want to avoid it. Okay, you may just need to receive
it. Okay, you may just need to receive the logs regarding that error and you
the logs regarding that error and you just need to just continue with the rest
just need to just continue with the rest of the code. It can be your use case as
of the code. It can be your use case as well. So in that particular scenario you
well. So in that particular scenario you need to handle exceptions you need to
need to handle exceptions you need to handle errors and we use something
handle errors and we use something called as try except method which is
called as try except method which is similar to try catch
similar to try catch method. Make sense? I know not 100% but
method. Make sense? I know not 100% but once I show you in the code it will make
once I show you in the code it will make sense. Let me just show you. So let's
sense. Let me just show you. So let's say you are writing your code something
say you are writing your code something like this. Um let's say x= 10. Okay.
like this. Um let's say x= 10. Okay. If x greater than
If x greater than 10 then you simply need to
10 then you simply need to print greater than
print greater than 10. Okay? Otherwise you need to simply
say print blah
blah. Okay. You need to simply do this. When you just run this, it will work
When you just run this, it will work fine. Right? Let's
fine. Right? Let's say I did something like
say I did something like this. I will see the error. Ooh. And
this. I will see the error. Ooh. And rest of the code, let's say I have
rest of the code, let's say I have this. Let's say I have this hello
this. Let's say I have this hello world. This will not run. Why? Because
world. This will not run. Why? Because it will stop here. And it is saying,
it will stop here. And it is saying, hey, this is a string. How you can just
hey, this is a string. How you can just compare the string with arithmetic
compare the string with arithmetic operation? see string and 10 and this
operation? see string and 10 and this code is not working. I want to do
code is not working. I want to do something in my code so that okay even
something in my code so that okay even if I get the error it's fine it should
if I get the error it's fine it should just tell me what is the issue that's it
just tell me what is the issue that's it should not block my code to execute rest
should not block my code to execute rest of the code okay so for that what I will
of the code okay so for that what I will do I will
do I will simply use try and then I will simply
simply use try and then I will simply write my logic okay this is my logic
write my logic okay this is my logic this is try so what it will do it will
this is try so what it will do it will try to run this if it throws an error in
try to run this if it throws an error in this particular code
this particular code block then it will jump to the next
block then it will jump to the next thing which is
thing which is accept which is accept and whatever I
accept which is accept and whatever I write this in this let's say I want to
write this in this let's say I want to say hey you have an
say hey you have an error and that's it will not block this
error and that's it will not block this code it will simply check this if it is
code it will simply check this if it is running fine okay it will skip this it
running fine okay it will skip this it will directly run this If it throws an
will directly run this If it throws an error then it will run this one and it
error then it will run this one and it will run this one as well. Let's run
will run this one as well. Let's run this and let's see. See this time it
this and let's see. See this time it didn't fail. He said hey you have an
didn't fail. He said hey you have an error and then it ran rest of the
error and then it ran rest of the code.
code. Oh this is really
Oh this is really nice. There is an advanced version of
nice. There is an advanced version of this. Let's say you do not need to write
this. Let's say you do not need to write print. You simply need to write the
print. You simply need to write the error. Like what is the error? You can
error. Like what is the error? You can simply say except
simply say except exception as E. Basically E is the error
exception as E. Basically E is the error and we are using exception method. Okay,
and we are using exception method. Okay, you will simply say E. And now this time
you will simply say E. And now this time you will see the error as well. Greater
you will see the error as well. Greater than not supported between instances of
than not supported between instances of string and end. Wow. You can even save
string and end. Wow. You can even save this as your log so that you can check
this as your log so that you can check hey what's wrong.
hey what's wrong. This is the way to handle errors or you
This is the way to handle errors or you can say error handling or exception
can say error handling or exception handling. Make sense? Make sense? Makes
handling. Make sense? Make sense? Makes sense. Makes sense. Now let me introduce
sense. Makes sense. Now let me introduce you to the frings because now this is
you to the frings because now this is the best time and you have the real
the best time and you have the real world example in front of you. First of
world example in front of you. First of all, what are frings? Basically, I will
all, what are frings? Basically, I will simply comment it out and I will just
simply comment it out and I will just show you what are franks. So this is a
show you what are franks. So this is a special kind of string that we use. So
special kind of string that we use. So let's say you have something like this
let's say you have something like this my string
my string equals hello my name is an this is fine
equals hello my name is an this is fine this will simply say print my
this will simply say print my string
string okay this is fine what if I want to
okay this is fine what if I want to create a variable let's say name
create a variable let's say name variable and I want to store that
variable and I want to store that information in this and every time I
information in this and every time I want to use this
want to use this variable. This
variable. This variable within this particular
variable within this particular statement. Let's make it more dynamic.
statement. Let's make it more dynamic. How are
How are you? Make sense? Now I want to print
you? Make sense? Now I want to print this
this name at this
name at this location by using this variable. How we
location by using this variable. How we can do that? This is where fringing
can do that? This is where fringing comes handy. So what you can do here?
comes handy. So what you can do here? You can simply
You can simply say f in the beginning of the string.
say f in the beginning of the string. Okay. Then what you will do? You will
Okay. Then what you will do? You will simply put the variable name in the
simply put the variable name in the curly braces. I will simply say name and
curly braces. I will simply say name and then curly braces close. Let me just
then curly braces close. Let me just show you the magic.
show you the magic. See hello my name is an how are you? If
See hello my name is an how are you? If I just change the name let's say
love. Hello my name is love. How are you? See that's how it works. You can
you? See that's how it works. You can actually combine variables and string
actually combine variables and string within the
within the string. And why this is handy? Let's say
string. And why this is handy? Let's say this is your realtime scenario. And here
this is your realtime scenario. And here you just want to say
you just want to say print
print hey first of all f then
hey first of all f then hey that's your error or let's say you
hey that's your error or let's say you got this
got this error and then you are
error and then you are simply saving this in the variable make
simply saving this in the variable make sense very good now all good let's run
sense very good now all good let's run And you will see hey you got this error
And you will see hey you got this error then you have the error and then hello
then you have the error and then hello world make sense. So this is a variable
world make sense. So this is a variable e see this is a
e see this is a variable franks remember this and now
variable franks remember this and now you know error handling very well and in
you know error handling very well and in the try except method we have something
the try except method we have something called as finally as well. Now what is
called as finally as well. Now what is this finally? So this I just highlighted
this finally? So this I just highlighted this thing finally because this is
this thing finally because this is really really important. So let's say
really really important. So let's say you are building a solution like
you are building a solution like this. We know that we know that if my
this. We know that we know that if my this logic is correct, this will not
this logic is correct, this will not run. Makes sense because this is right.
run. Makes sense because this is right. If my this logic fails, this logic will
If my this logic fails, this logic will run. Makes
run. Makes sense. We have a third member of this
sense. We have a third member of this group which is called finally.
group which is called finally. Whatever you write within the finally,
Whatever you write within the finally, it will execute no matter if you get the
it will execute no matter if you get the error or not. Let me just show you. I
error or not. Let me just show you. I will simply say I will always run. I
will simply say I will always run. I will always run. So let's say you have
will always run. So let's say you have the error. Let's see what will happen.
the error. Let's see what will happen. It will simply say, hey, you have the
It will simply say, hey, you have the error. I will always run and hello
error. I will always run and hello world. That means this block ran after
world. That means this block ran after this one.
this one. Okay. Okay. Sorry, this one. This block
Okay. Okay. Sorry, this one. This block ran after this one. Make sense? If my
ran after this one. Make sense? If my value is correct, then also it will run.
value is correct, then also it will run. It will simply say blah blah. I will
It will simply say blah blah. I will always run hello world. What's the use
always run hello world. What's the use case of it? What's the use case of it?
case of it? What's the use case of it? It makes sure that your code is
It makes sure that your code is executing these stuff and it is working
executing these stuff and it is working fine and it is running this only and
fine and it is running this only and only after this or this only after try
only after this or this only after try or
or accept. Make sense? This is I know like
accept. Make sense? This is I know like will not be very much used but yeah you
will not be very much used but yeah you should know about this
and let me see what do we have. Oh this is really important. Okay
have. Oh this is really important. Okay let's talk about this. This is basically
let's talk about this. This is basically this will actually build a strong base
this will actually build a strong base of your understanding in functions. So
of your understanding in functions. So in functions I told you that it always
in functions I told you that it always it always returns only one time. It
it always returns only one time. It always returns only one time. It cannot
always returns only one time. It cannot return multiple values because once it
return multiple values because once it returns something it will take the exit.
returns something it will take the exit. Okay. Okay. Okay. Okay. Okay. So now
Okay. Okay. Okay. Okay. Okay. So now let's say let's build a function because
let's say let's build a function because I want to share this thing with you. I
I want to share this thing with you. I also like spent a lot of time when I was
also like spent a lot of time when I was just learning this. So what what
just learning this. So what what happened? Let's create a function. Okay.
happened? Let's create a function. Okay. Let's create a function. Let's create a
Let's create a function. Let's create a function like this. My function. And
function like this. My function. And this will actually clear a lot of things
this will actually clear a lot of things for you. Okay. Let's say this is a
for you. Okay. Let's say this is a simple function. And within this
simple function. And within this function you are applying try except
function you are applying try except method. Hm. Make sense? So you will
method. Hm. Make sense? So you will simply say or let's take an example.
simply say or let's take an example. Um let's let's let's just do like like
Um let's let's let's just do like like this as well. So I will simply say
this as well. So I will simply say uh parameter because it will be easier
uh parameter because it will be easier for you just to use it px otherwise you
for you just to use it px otherwise you would need to use input function and
would need to use input function and all. So px. So this is my function.
all. So px. So this is my function. Okay. So now what will happen? I will
Okay. So now what will happen? I will simply say
simply say try and I will simply write my logic
try and I will simply write my logic if let's say
if let's say px okay mod
px okay mod 2 let's say I'm checking if it is even
2 let's say I'm checking if it is even or not okay equals to equal to0 then
or not okay equals to equal to0 then return 1 that means true else
return 1 that means true else uh you can simply
uh you can simply say zero
say zero else or I'm just checking for if I'm not
else or I'm just checking for if I'm not even checking for anything. Okay. If it
even checking for anything. Okay. If it is even, then only return one.
is even, then only return one. Otherwise, do not do anything. And at
Otherwise, do not do anything. And at the same time, if I have any errors, I
the same time, if I have any errors, I will simply say
will simply say except and return
error. Make sense? Error. Same same stuff. Or let's
sense? Error. Same same stuff. Or let's say except
say except exception as E. Okay. Or return E. Make
exception as E. Okay. Or return E. Make sense? Very good. So then I will simply
sense? Very good. So then I will simply say
say finally.
finally. If let's let's take an example without
If let's let's take an example without finally. If I write
finally. If I write print hello world, will it work? Will it
print hello world, will it work? Will it work? Let me show you. First of all,
work? Let me show you. First of all, let's execute this code and let's call
let's execute this code and let's call this function. My
this function. My function. Let's say I'm giving four.
function. Let's say I'm giving four. Four is an even number. So it will
Four is an even number. So it will simply
simply say one, right? Let's run this. Wow.
say one, right? Let's run this. Wow. This is it. It simply completed this and
This is it. It simply completed this and it returned one. Okay. And we know that
it returned one. Okay. And we know that it is saved in this particular function.
it is saved in this particular function. It didn't go here because it didn't
It didn't go here because it didn't throw any error. But why this command
throw any error. But why this command didn't run? Because we got return
didn't run? Because we got return function. Return function like return
function. Return function like return command. The moment we see return
command. The moment we see return command or you can say Python sees the
command or you can say Python sees the return command, it will simply take the
return command, it will simply take the exit from that function. it will not
exit from that function. it will not even go on the below quotes. But if we
even go on the below quotes. But if we write print hello world
write print hello world before before it will work. See hello
before before it will work. See hello world it will work. But if I write print
world it will work. But if I write print hello world after this print hello world
hello world after this print hello world will not be executed. Why? Because this
will not be executed. Why? Because this will not even go beyond this because
will not even go beyond this because this is
this is strictly pausing it.
strictly pausing it. It will simply say hey take exit just go
It will simply say hey take exit just go away. But if we just want to simply
away. But if we just want to simply print something after the execution even
print something after the execution even if we get the return value this is where
if we get the return value this is where your finally keyword comes handy. I will
your finally keyword comes handy. I will simply say
simply say finally. Okay. And I will simply write
finally. Okay. And I will simply write this. Now I will see hello world two
this. Now I will see hello world two times. Perfect. One is obviously at the
times. Perfect. One is obviously at the beginning which is the respective of try
beginning which is the respective of try accept method. But after having the
accept method. But after having the return value still I'm having print.
return value still I'm having print. Why? Because this command will always
Why? Because this command will always run. Always run. This is true for
run. Always run. This is true for functions as well. Can you imagine? This
functions as well. Can you imagine? This is true for functions as
is true for functions as well.
well. H okay this makes sense. So this is like
H okay this makes sense. So this is like one thing that you need to master for
one thing that you need to master for functions. Let me just share the other
functions. Let me just share the other one as well which is called global
one as well which is called global variables. Okay let's talk about global
variables. Okay let's talk about global variables in function. So let's say you
variables in function. So let's say you have a variable called x= to 10. This is
have a variable called x= to 10. This is very popular man. X= let's say 100 X
very popular man. X= let's say 100 X equals to 100 if and you do not even
equals to 100 if and you do not even have any parameter okay this is a simple
have any parameter okay this is a simple function let's say you want to print X
function let's say you want to print X can you do
can you do that can you do that let me just run
that can you do that let me just run this obviously 100
this obviously 100 why because it is taking the global
why because it is taking the global variable here which is outside of this
variable here which is outside of this function okay what if I define something
function okay what if I define something called as this x= to 5 inside the
called as this x= to 5 inside the function what I will get obviously five
function what I will get obviously five because this time it will give the
because this time it will give the priority to its own x value instead of
priority to its own x value instead of global value of x instead of global
global value of x instead of global value of
x okay but if I want to use or print global value can I just do something
global value can I just do something like
like this no we cannot say global here in a
this no we cannot say global here in a print command. Okay, makes sense. Can I
print command. Okay, makes sense. Can I do something like this? Let's say this
do something like this? Let's say this is x= to 5. Then I say global
is x= to 5. Then I say global x. No. Name x is
x. No. Name x is assigned to before global
assigned to before global declaration. That means it already
declaration. That means it already defined x. Now you cannot do this. But
defined x. Now you cannot do this. But if you define it before x, you can
if you define it before x, you can perform
perform this. Why? because it first took the
this. Why? because it first took the value of x. Okay, then it override that
value of x. Okay, then it override that value with five and then it printed that
value with five and then it printed that value. Okay, even if I do not write
value. Okay, even if I do not write this, I will still get 100 because I am
this, I will still get 100 because I am getting the global variable and this is
getting the global variable and this is by default there. Even if you do not
by default there. Even if you do not write global word, it will simply by
write global word, it will simply by default take this value of x. But if you
default take this value of x. But if you have defined something with the same
have defined something with the same variable name inside your function, it
variable name inside your function, it will take the priority. That's the whole
will take the priority. That's the whole point of discussion right now. Make
point of discussion right now. Make sense? That's the difference between
sense? That's the difference between global and local variable. Local
global and local variable. Local variable always takes the priority if
variable always takes the priority if you are just defining it within the
you are just defining it within the function. Make sense? Make sense? Make
function. Make sense? Make sense? Make sense? Now let's see if anything is left
sense? Now let's see if anything is left with this topic because I want to cover
with this topic because I want to cover all the things. Oh, there's one more
all the things. Oh, there's one more thing. I think I just I I remember I
thing. I think I just I I remember I noted down. Um I think there was
noted down. Um I think there was something a little error. I just Yeah,
something a little error. I just Yeah, perfect. I I knew it because this was my
perfect. I I knew it because this was my favorite topic at that time as well. So
favorite topic at that time as well. So basically, let's say you are writing
basically, let's say you are writing your code. Okay, you are writing your
your code. Okay, you are writing your code. You are writing your code and you
code. You are writing your code and you got the value x= 100. You need to apply
got the value x= 100. You need to apply if condition. If x less than 100 you
if condition. If x less than 100 you need to throw an error even if you do
need to throw an error even if you do not have an error. What? What? Yes, you
not have an error. What? What? Yes, you need to build or you can say create your
need to build or you can say create your custom error. That's called user error.
custom error. That's called user error. From here you will do something like
From here you will do something like this.
this. Raise value
Raise value error. Something like this. I'm just
error. Something like this. I'm just explaining you stop. Okay. Raise value
explaining you stop. Okay. Raise value error. Obviously it will not work
error. Obviously it will not work because there's a syntax for it. You
because there's a syntax for it. You need to raise something called as value
need to raise something called as value error because you want to say hey
error because you want to say hey there's something called as like value
there's something called as like value error something like this. You can even
error something like this. You can even raise the value errors or you can say
raise the value errors or you can say errors on your own because your program
errors on your own because your program is designed in such a way that that
is designed in such a way that that cannot take value less than 100 cannot.
cannot take value less than 100 cannot. So in that scenario you have to raise
So in that scenario you have to raise custom
custom errors. Make sense? This is very popular
errors. Make sense? This is very popular by the way. So in order to do this what
by the way. So in order to do this what you can do you can simply type value
you can do you can simply type value error and just make your own error.
error and just make your own error. Let's say um value less than 100 is not
Let's say um value less than 100 is not allowed. This is your own error. Okay.
allowed. This is your own error. Okay. So you will see the error but context
So you will see the error but context will be this whatever you will write
will be this whatever you will write here. Okay. Let's run this. Okay. This
here. Okay. Let's run this. Okay. This is successful because x is not less than
is successful because x is not less than 100. Let's say 99. So this will throw an
100. Let's say 99. So this will throw an error that value less than 100 is not
error that value less than 100 is not allowed. This is a value error because
allowed. This is a value error because this is a kind of value because this is
this is a kind of value because this is something related to value error, right?
something related to value error, right? There are so many errors. You can even
There are so many errors. You can even Google
Google uh
uh raise error in Python. There are so
raise error in Python. There are so many raise error in Python. Python raise
many raise error in Python. Python raise an
an exception. So you can say raise
exception. So you can say raise exception. You can even raise exception.
exception. You can even raise exception. Sorry no numbers below zero. So this is
Sorry no numbers below zero. So this is so similar, right? So this will simply
so similar, right? So this will simply throw an exception. What is the
throw an exception. What is the difference between like exception value
difference between like exception value error? So the difference is here when
error? So the difference is here when you will be just seeing the type of
you will be just seeing the type of error, you will see it value error. If I
error, you will see it value error. If I write
write exception, you will see the exception
exception, you will see the exception error. See exception error. So it's up
error. See exception error. So it's up to you. You can just pick any error as
to you. You can just pick any error as per your obviously convenience. There is
per your obviously convenience. There is a type error as well like maybe someone
a type error as well like maybe someone just did a typo. So you can simply say
just did a typo. So you can simply say raise type error. So it will simply show
raise type error. So it will simply show them that this is a kind of error and
them that this is a kind of error and this is the error value. So that means
this is the error value. So that means this is not actually an error in Python
this is not actually an error in Python world but this is an error for your
world but this is an error for your program. So that means you forcefully
program. So that means you forcefully want to throw an error. That's where you
want to throw an error. That's where you use your like raise error. Okay, make
use your like raise error. Okay, make sense? Very good. Very good. Very good.
sense? Very good. Very good. Very good. Very good. I hope now it is pretty much
Very good. I hope now it is pretty much clear to you like what are the things
clear to you like what are the things and I think I have covered all the
and I think I have covered all the things that I wanted to cover. One thing
things that I wanted to cover. One thing is left and I want to cover that because
is left and I want to cover that because that is really important. Okay, like
that is really important. Okay, like these are like small small things
these are like small small things because Python is so so so wide. So
because Python is so so so wide. So let's cover that as well. What is that?
let's cover that as well. What is that? Basically let me clear everything. We
Basically let me clear everything. We going to learn something about enumerate
going to learn something about enumerate function. Enumerate function. What is
function. Enumerate function. What is enumerate function? So let's say you
enumerate function? So let's say you have a list called my list equals 1 2 or
have a list called my list equals 1 2 or let's say
let's say 100 200 300 400 500. Now you want to run
100 200 300 400 500. Now you want to run a loop for I in my list. Okay, you need
a loop for I in my list. Okay, you need to simply say print I. You will say
to simply say print I. You will say Anlama this is so simple. I know. Can
Anlama this is so simple. I know. Can you just print
you just print the position as well? Oh, whoa, whoa,
the position as well? Oh, whoa, whoa, whoa, wait, wait, wait, wait, wait. Can
whoa, wait, wait, wait, wait, wait. Can you repeat? Let's say you want to just
you repeat? Let's say you want to just simply print the value of the position.
simply print the value of the position. This is zero. This is one, this is two,
This is zero. This is one, this is two, this is three, this is four. This is
this is three, this is four. This is doable. This is not a big deal because
doable. This is not a big deal because we can simply run a loop for like length
we can simply run a loop for like length of this list and we can start the list
of this list and we can start the list from zero and we can simply get this.
from zero and we can simply get this. But let's say you want to do both. You
But let's say you want to do both. You want to get the position value as well
want to get the position value as well plus you want to get the list value as
plus you want to get the list value as well. Obviously it is also doable but we
well. Obviously it is also doable but we have a very powerful function for it.
have a very powerful function for it. It's called enumerate. I can write
It's called enumerate. I can write something like this
something like this enumerate. Okay. When I write enumerate
enumerate. Okay. When I write enumerate then I cannot run this because it will
then I cannot run this because it will simply throw an basically like okay it
simply throw an basically like okay it will work but it will not give me the
will work but it will not give me the desired result. So basically what
desired result. So basically what happens for this what it will do it will
happens for this what it will do it will simply store the tpple for each
simply store the tpple for each iteration 0 100 1 200 2 300 3 400 4 500
iteration 0 100 1 200 2 300 3 400 4 500 but in the real world how we use it I
but in the real world how we use it I will simply create two you can say
will simply create two you can say variables one is I second is let's say x
variables one is I second is let's say x i stands for the position x stand for
i stands for the position x stand for the value so I will simply say print i
the value so I will simply say print i if I just want position. If I want
if I just want position. If I want value, I can simply say X. So that's how
value, I can simply say X. So that's how we simply fetch the records. And
we simply fetch the records. And obviously in order to understand it, you
obviously in order to understand it, you can simply run print I just to see like
can simply run print I just to see like what it will hold. It will hold the
what it will hold. It will hold the position and the value itself. Enumerate
position and the value itself. Enumerate is very handy and you will see in your
is very handy and you will see in your real life as well. It is very
real life as well. It is very handy. Okay, makes sense. Makes sense.
handy. Okay, makes sense. Makes sense. Makes sense. Makes sense. Okay, now it's
Makes sense. Makes sense. Okay, now it's time to just unpack a gift for you.
time to just unpack a gift for you. What's that? You will feel really
What's that? You will feel really excited after knowing about this. Let me
excited after knowing about this. Let me just tell you what's
just tell you what's that. So now let's try to talk about oop
that. So now let's try to talk about oop that is objectoriented programming in
that is objectoriented programming in Python. And let me just tell you in
Python. And let me just tell you in every programming language oop is one of
every programming language oop is one of the hottest topics because whenever you
the hottest topics because whenever you are just scaling your program whenever
are just scaling your program whenever you're building a big
you're building a big application you cannot survive without
application you cannot survive without oop really or you can say your
oop really or you can say your application cannot survive without oop
application cannot survive without oop trust me the reason is let me just tell
trust me the reason is let me just tell you what is oop and before even
you what is oop and before even explaining oop I will just explain
explaining oop I will just explain through an example let's say you are
through an example let's say you are building an application for online store
building an application for online store you have so many functions you have
you have so many functions you have defined like so many functions because
defined like so many functions because obviously functions promote reusability
obviously functions promote reusability of code I would say even functions are
of code I would say even functions are not capable enough to structure your
not capable enough to structure your data let's say you have one function
data let's say you have one function okay the red set so red boxes are your
okay the red set so red boxes are your functions okay so let's say you have
functions okay so let's say you have this function this function this
this function this function this function this function this function
function this function this function this function this function this
this function this function this function this function this function
function this function this function this function this function this
this function this function this function this function
function this function this function. This function there are
this function. This function there are so many functions scattered in your
so many functions scattered in your program. Not just functions. Let's talk
program. Not just functions. Let's talk about variables. So many variables. So
about variables. So many variables. So many so many so many so many so many. So
many so many so many so many so many. So many
many variables. So many
variables. Now just try to scale this program. Forget about scaling, bro.
program. Forget about scaling, bro. Forget about scaling. Forget about
Forget about scaling. Forget about scaling. How does it looking? How does
scaling. How does it looking? How does it look like? How does it looking? How
it look like? How does it looking? How is it
is it looking? It's a mess. It's a mess. You
looking? It's a mess. It's a mess. You have so many functions. You have so many
have so many functions. You have so many variables. You do not even remember like
variables. You do not even remember like what function is for what purpose. Yes,
what function is for what purpose. Yes, you will provide very good naming
you will provide very good naming convention for all the functions. Still
convention for all the functions. Still you will not be able to handle that
you will not be able to handle that mess. You will not be able to handle
mess. You will not be able to handle that mess. So what we can do? Let's say
that mess. So what we can do? Let's say I figured out this function, this
I figured out this function, this function, this function, this function
function, this function, this function actually belong to a specific use case.
actually belong to a specific use case. If you are building an online
If you are building an online application for stores, let's say online
application for stores, let's say online retail store, this particular function,
retail store, this particular function, these particular functions are related
these particular functions are related to your customers are related to your
to your customers are related to your customers. So these four functions plus
customers. So these four functions plus these variables. So what you can do, you
these variables. So what you can do, you can actually create a
can actually create a bundle using these functions and using
bundle using these functions and using these variables and you can just
these variables and you can just organize these things together and you
organize these things together and you can actually create a template. You can
can actually create a template. You can actually create a bundle that you can
actually create a bundle that you can reuse it whenever you want. So that
reuse it whenever you want. So that means you can even reuse these
means you can even reuse these functions. You can even reuse this
functions. You can even reuse this variables plus with better
variables plus with better management better you can say uh
management better you can say uh scalability because it it it it will be
scalability because it it it it will be so easy for you to manage all these
so easy for you to manage all these things. So we just create bundles. Let's
things. So we just create bundles. Let's say this is bundle number one. Then you
say this is bundle number one. Then you simply created a next bundle for these
simply created a next bundle for these functions and all these variables belong
functions and all these variables belong to this. So this will be b bundle number
to this. So this will be b bundle number two. Let's say bundle number three. So
two. Let's say bundle number three. So this is our bundle number three. That's
this is our bundle number three. That's it. Now the whole mess is actually
it. Now the whole mess is actually grouped together to three bundles.
grouped together to three bundles. Bundle number one, which is this one.
Bundle number one, which is this one. Bundle number two, which is this one.
Bundle number two, which is this one. Bundle number three. Now let's say I
Bundle number three. Now let's say I want to add something in my customers
want to add something in my customers bundle. I can simply add a function in
bundle. I can simply add a function in this particular bundle. And I can simply
this particular bundle. And I can simply add a variable in this bundle. There's
add a variable in this bundle. There's no need to just find, hey, where's my
no need to just find, hey, where's my code? Where's this? Where's
code? Where's this? Where's that? So this is called
that? So this is called class. This is the concept of class
class. This is the concept of class where it combines your functions and it
where it combines your functions and it will be called as methods. Methods are
will be called as methods. Methods are your functions. But when it got
your functions. But when it got inherited, not inherited, we are not
inherited, not inherited, we are not talking about inheritance. Like normally
talking about inheritance. Like normally when it got embedded within the bundle,
when it got embedded within the bundle, it becomes methods.
it becomes methods. And these are your
And these are your variables. These are your
variables. These are your variables. So this is a concept of
variables. So this is a concept of class. Okay. Now we just talked about
class. Okay. Now we just talked about that we can even reuse these function
that we can even reuse these function and these
and these variables
variables using objects. So I can create object
using objects. So I can create object number one from this bundle. I can even
number one from this bundle. I can even create object number two from this
create object number two from this bundle. I can even create object number
bundle. I can even create object number three from this bundle and so on just to
three from this bundle and so on just to reuse these functions and variables
reuse these functions and variables again and
again and again. Oh, so that is the concept of
again. Oh, so that is the concept of class and an object. We first create a
class and an object. We first create a bundle, then we create objects. Same way
bundle, then we create objects. Same way you create a function and then you just
you create a function and then you just call it, right? And if you just want to
call it, right? And if you just want to save that particular output, you create
save that particular output, you create a variable. Same way here you will
a variable. Same way here you will create the class then you will create an
create the class then you will create an object instead of a variable you will
object instead of a variable you will create an object and you will reuse
create an object and you will reuse it. Make sense? That is the concept of
it. Make sense? That is the concept of objectoriented programming. That means
objectoriented programming. That means we focus on creating more and more
we focus on creating more and more objects. Make sense? This is the highle
objects. Make sense? This is the highle overview. Why do we need oop? Why do we
overview. Why do we need oop? Why do we need object- oriented
need object- oriented programming? Why do we need these
programming? Why do we need these things? Obviously there are like so many
things? Obviously there are like so many use cases. Reusability, polymorphism,
use cases. Reusability, polymorphism, inheritance, so many things but this is
inheritance, so many things but this is the fundamental. This is the
the fundamental. This is the fundamental make sense. Don't worry you
fundamental make sense. Don't worry you will learn everything in classes as
will learn everything in classes as well. So let's try to build a simple
well. So let's try to build a simple class and let's see what happens when we
class and let's see what happens when we just build a class. Okay, just be with
just build a class. Okay, just be with me. You will enjoy this oop session.
me. You will enjoy this oop session. Trust me, you will enjoy. You just just
Trust me, you will enjoy. You just just just be happy. Let's see what do we have
just be happy. Let's see what do we have in oop concepts. So let's try to build
in oop concepts. So let's try to build our first class. First class. First
our first class. First class. First class. Okay. Let me just close
class. Okay. Let me just close unnecessary tabs that are not required
unnecessary tabs that are not required now. So perfect. Let's create our class.
now. So perfect. Let's create our class. And trust me, class is very simple. It
And trust me, class is very simple. It looks like complex but it is very
looks like complex but it is very simple. Let's say we want to create a
simple. Let's say we want to create a class. And we just talked about classes.
class. And we just talked about classes. Class is just like a bundle. Let's say
Class is just like a bundle. Let's say within your company you have an
within your company you have an application for your whole organization
application for your whole organization and within that you want to bundle all
and within that you want to bundle all the functions and variables related to
the functions and variables related to employees. Make sense? What you will do?
employees. Make sense? What you will do? You will simply say class uh
You will simply say class uh employee. So you will simply create a
employee. So you will simply create a class called employee and how you create
class called employee and how you create that you simply write the keyword called
that you simply write the keyword called class and then the class
class and then the class name. Make sense? You will simply use
name. Make sense? You will simply use column and then just hit enter. This is
column and then just hit enter. This is the
the class. This is the class H. Okay. Okay.
class. This is the class H. Okay. Okay. Makes sense. Makes sense. Okay. Now, now
Makes sense. Makes sense. Okay. Now, now you will define the variables. Okay.
you will define the variables. Okay. Because you will simply group the
Because you will simply group the variables. I will simply say uh emp
variables. I will simply say uh emp name. Okay. EMP name. Let's say for now
name. Okay. EMP name. Let's say for now I'm just saying your name. Whatever. We
I'm just saying your name. Whatever. We can just pick any any any any loyal data
can just pick any any any any loyal data fam. So let's pick a random name.
fam. So let's pick a random name. Um Rahul Rahul is very popular name.
Um Rahul Rahul is very popular name. So okay let's pick this name. Now the
So okay let's pick this name. Now the company the company is obviously same.
company the company is obviously same. Let's say department. Okay department is
Let's say department. Okay department is let's say he works for IT. Okay do not
let's say he works for IT. Okay do not feel sad. We will just take your
feel sad. We will just take your examples as well. Okay makes sense.
examples as well. Okay makes sense. Okay. So employee name equals Rahul.
Okay. So employee name equals Rahul. employee department equals it. These are
employee department equals it. These are the variables. Now I want to create a
the variables. Now I want to create a function. Now you know how to create the
function. Now you know how to create the function. I will simply say df. I will
function. I will simply say df. I will say info which does nothing special. It
say info which does nothing special. It simply
simply returns the employee name and department
returns the employee name and department name. We will simply use fring. Now you
name. We will simply use fring. Now you know fring as well. I will simply say
know fring as well. I will simply say employee employee.
employee employee. employee emp
name. Okay. Works
for works for EMP department. Make sense? Whatever we will get in here.
sense? Whatever we will get in here. Whatever we will get in here. Can we
Whatever we will get in here. Can we just make it a little bit towards right?
just make it a little bit towards right? Can we? Can we? Can we? Can we?
Can we? Can we? Can we? Can we? Uh there should be a way. No h let me
Uh there should be a way. No h let me just decrease the size then. Okay, makes
just decrease the size then. Okay, makes sense. So this is the function okay that
sense. So this is the function okay that I created. Makes sense.
I created. Makes sense. Now this class is created obviously. But
Now this class is created obviously. But now when I will be running this, it will
now when I will be running this, it will throw an error. Why? Because you need to
throw an error. Why? Because you need to consider some things. Whenever you
consider some things. Whenever you create a function within the class, you
create a function within the class, you need to use a default parameter. Or you
need to use a default parameter. Or you can say mandatory parameter which is
can say mandatory parameter which is self. Self. Yes, self. We will just talk
self. Self. Yes, self. We will just talk about self as well as as well. Don't
about self as well as as well. Don't worry. So this is the thing that you
worry. So this is the thing that you have to use. Okay. Second thing. Second
have to use. Okay. Second thing. Second thing. This is the employee name. Okay.
thing. This is the employee name. Okay. And employee department. Obviously we
And employee department. Obviously we are
are using attributes. You will say no we are
using attributes. You will say no we are not using attributes. We are using
not using attributes. We are using variables. No. Whenever you are working
variables. No. Whenever you are working inside the class, your variables will be
inside the class, your variables will be called as
attributes. Okay? And your functions will be called as methods. So you need
will be called as methods. So you need to remember these things. Whenever I'm
to remember these things. Whenever I'm using words something called as methods
using words something called as methods and attributes, that means I'm referring
and attributes, that means I'm referring to function and variables. Make sense?
to function and variables. Make sense? Very good. These are some naming
Very good. These are some naming conventions that you need to use. This
conventions that you need to use. This is done. Let me just run this. Perfect.
is done. Let me just run this. Perfect. So this is done.
So this is done. Make sense? Makes sense. This is done.
Make sense? Makes sense. This is done. Like this is actually created. Okay. So
Like this is actually created. Okay. So now what we need to do? What we need to
now what we need to do? What we need to do? We will simply create an object. How
do? We will simply create an object. How we can just create object? Let's say
we can just create object? Let's say emp one or let's say emp1 is the object
emp one or let's say emp1 is the object of this particular class. Okay. I will
of this particular class. Okay. I will simply say
simply say employee. And that's it. That's it. I
employee. And that's it. That's it. I can simply run it. And this is all
can simply run it. And this is all obviously right. I will now access
obviously right. I will now access anything within this class. Let's say I
anything within this class. Let's say I want to access this variable or even if
want to access this variable or even if I want to access this variable or if I
I want to access this variable or if I just want to call this function, I can
just want to call this function, I can do anything using this
do anything using this template. Basically object of the
template. Basically object of the template because template is this one.
template because template is this one. This is the object. Okay. So now I can
This is the object. Okay. So now I can actually use anything. I will simply
actually use anything. I will simply write something like this.
write something like this. emp1 dot name and I can even print it. I
emp1 dot name and I can even print it. I will simply say print emp1.name name run
will simply say print emp1.name name run it error very good because I wanted to
it error very good because I wanted to see this it will simply say hey what are
see this it will simply say hey what are you doing man so here's the thing you
you doing man so here's the thing you need to use the same variable name okay
need to use the same variable name okay do not say like
do not say like name emp name very good it will simply
name emp name very good it will simply return Rahul makes sense I can even say
return Rahul makes sense I can even say emp
emp department okay I will simply see it
department okay I will simply see it very good if I just want to call the
very good if I just want to call the function I can do that. I will simply
function I can do that. I will simply say emp1 dot info and I will run this
say emp1 dot info and I will run this and it will
and it will work. No, it is saying hey emp name is
work. No, it is saying hey emp name is not
not defined. Here's the thing.
defined. Here's the thing. So whenever we are working with methods
So whenever we are working with methods what are methods functions we need to
what are methods functions we need to make sure that whatever we are using
make sure that whatever we are using here again I'm repeating we are using
here again I'm repeating we are using attributes what we are using attributes
attributes what we are using attributes what are attributes the variables that
what are attributes the variables that live inside the class very good so
live inside the class very good so whenever we want to use attributes we
whenever we want to use attributes we have to use a keyword called self we
have to use a keyword called self we have to write something like this 12 dot
have to write something like this 12 dot empame. Why? Because it tells that this
empame. Why? Because it tells that this particular employee name is coming from
particular employee name is coming from your
your class. It is not a normal variable or
class. It is not a normal variable or parameter of this function. No, it is
parameter of this function. No, it is coming from this class
coming from this class attributes. Make sense? Make sense? Make
attributes. Make sense? Make sense? Make sense? Very good. So I have to use
sense? Very good. So I have to use something like
something like this self dot and here as well self dot.
this self dot and here as well self dot. Okay I want to shift it but I cannot.
Okay I want to shift it but I cannot. Let's reduce the text size.
Let's reduce the text size. So
So yeah so this is the thing. Okay let's
yeah so this is the thing. Okay let's try to run now. It will simply say
try to run now. It will simply say employee Rahul works for it. Okay.
employee Rahul works for it. Okay. Employee Rahul works for it. Very good.
Employee Rahul works for it. Very good. Now what if I have what if I have a
Now what if I have what if I have a parameter here of the same name. Let's
parameter here of the same name. Let's say I have a parameter called employee
say I have a parameter called employee name and employee
name and employee department. Okay. Now you can use it
department. Okay. Now you can use it without self because you will pass these
without self because you will pass these parameters from here. You will simply
parameters from here. You will simply say let's
say let's say
say rohul or do not like use bad words love.
rohul or do not like use bad words love. Let let me use my word my my my name.
Let let me use my word my my my name. Okay. And you are passing let's say it.
Okay. And you are passing let's say it. Okay. If you just run this you will see
Okay. If you just run this you will see it will work. Why? Because this time
it will work. Why? Because this time this employee name is not this one. It
this employee name is not this one. It is coming from
is coming from here. That is why to distinguish between
here. That is why to distinguish between the
the parameters with the ones that are
parameters with the ones that are attributes we use self keyword. So even
attributes we use self keyword. So even if if I just take this variable and if I
if if I just take this variable and if I do not want to use that particular name
do not want to use that particular name I do not want to use love I can simply
I do not want to use love I can simply write here
write here self that's it and it will work and it
self that's it and it will work and it will simply say Rahul so we are saying
will simply say Rahul so we are saying that whenever I'm using self I'm using
that whenever I'm using self I'm using inner variables inner things and if I'm
inner variables inner things and if I'm just passing the normal parameters I'm
just passing the normal parameters I'm using the external
using the external ones make
ones make sense very good now you can ask me one
sense very good now you can ask me one thing if you haven't asked me this.
thing if you haven't asked me this. Okay, you will simply say an in this
Okay, you will simply say an in this parameter like in this list of
parameter like in this list of parameters we actually have three
parameters we actually have three parameters, right? Self, employee name
parameters, right? Self, employee name and employee department. But we are
and employee department. But we are passing only two or let's say even if we
passing only two or let's say even if we do not have these list, if we just have
do not have these list, if we just have self and if we just call this like
self and if we just call this like this, it still works. But actually you
this, it still works. But actually you are not passing any parameter. Why you
are not passing any parameter. Why you are not passing self parameter? I am
are not passing self parameter? I am passing the parameter but I'm not
passing the parameter but I'm not showing you an
showing you an Lamba do
Lamba do not do this. So the thing is actually I
not do this. So the thing is actually I am not passing the parameters. Python is
am not passing the parameters. Python is passing the parameters for me. So I
passing the parameters for me. So I created this object right and I am
created this object right and I am calling this function like this. But
calling this function like this. But actually behind the scenes what Python
actually behind the scenes what Python is doing? Python is making this function
is doing? Python is making this function call like this.
call like this. employee dot info then employee 1
employee dot info then employee 1 and then this will make the call. So if
and then this will make the call. So if I just run this you will see the same
I just run this you will see the same stuff. So this command is actually
stuff. So this command is actually equivalent to this one. But just to make
equivalent to this one. But just to make things easy because it doesn't make any
things easy because it doesn't make any sense to pass the object again and again
sense to pass the object again and again because this self keyword that means we
because this self keyword that means we are passing the object itself. You will
are passing the object itself. You will say what is the big deal? Why do we need
say what is the big deal? Why do we need to pass the object? You will get to know
to pass the object? You will get to know bro when I will just discuss the
bro when I will just discuss the constructors. Okay. So basically
constructors. Okay. So basically employee one is
employee one is different. Employee two will be
different. Employee two will be different. Employee three will be
different. Employee three will be different. employee four will be
different. employee four will be different. So that means every object
emp right. That means this function should behave different for different
should behave different for different objects. That is why we pass self as the
objects. That is why we pass self as the parameter. That means each object will
parameter. That means each object will act
act differently. Make sense? Make sense?
differently. Make sense? Make sense? That is why we pass self. Now we know
That is why we pass self. Now we know that we always need to pass the self
that we always need to pass the self command. So that is why we prefer using
command. So that is why we prefer using this one. Okay? Because this is handy
this one. Okay? Because this is handy and this is like quick. But actually
and this is like quick. But actually this command is doing like this. Class
this command is doing like this. Class name then function name and then passing
name then function name and then passing that particular object. So you should
that particular object. So you should know this right. Just take notes. Take
know this right. Just take notes. Take notes. Okay. Perfect. Now let's try to
notes. Okay. Perfect. Now let's try to understand the constructors. Okay. Now
understand the constructors. Okay. Now just tell me one thing. Just telling you
just tell me one thing. Just telling you one thing we are building this class,
one thing we are building this class, right? Let's say we have some fixed
right? Let's say we have some fixed attributes because these are the default
attributes because these are the default attributes of the employee class. So we
attributes of the employee class. So we know that all the employees will belong
know that all the employees will belong to the same company. Let's say company
to the same company. Let's say company name
name is company name is um
is company name is um XYZ. Okay. Let's say the company name is
XYZ. Okay. Let's say the company name is XYZ. This will be the constant. This
XYZ. This will be the constant. This will be constant thing. But now comes
will be constant thing. But now comes the dynamic thing. Let's say employee
the dynamic thing. Let's say employee name and employee department cannot be
name and employee department cannot be fixed because it will be different for
fixed because it will be different for each employee. So that's where we create
each employee. So that's where we create something called as constructor. What
something called as constructor. What constructor will do? Let me just show
constructor will do? Let me just show you. So in order to define the
you. So in order to define the constructor, we simply write this
def_init then simply braces for the function and then we simply write self.
function and then we simply write self. That's it.
That's it. That's it.
That's it. Now,
Now, whatever variables or you can say
whatever variables or you can say attributes you want to create
attributes you want to create dynamically, you will simply define
dynamically, you will simply define inside this. That means let's say you
inside this. That means let's say you want to define um employee name. You
want to define um employee name. You will simply write it here. Employee
will simply write it here. Employee name. Let's say you want to define um
name. Let's say you want to define um employee department. You will simply say
employee department. You will simply say employee department. Make sense? Now
employee department. Make sense? Now this function this function this is
this function this function this is called constructor by the way whenever
called constructor by the way whenever you will be calling this function like
you will be calling this function like calling this object let's say you are
calling this object let's say you are creating this object it will
creating this object it will automatically call this function let me
automatically call this function let me repeat let's say I'm writing it here
repeat let's say I'm writing it here pass okay and I'm not taking any kind
pass okay and I'm not taking any kind of parameters when we write pass means
of parameters when we write pass means um we just need to define the function
um we just need to define the function but we do not need to do anything
but we do not need to do anything otherwise it will throw error. So pass
otherwise it will throw error. So pass is very handy in that case. Okay, so
is very handy in that case. Okay, so this is fine. So what it actually did
this is fine. So what it actually did behind the scenes, let me show you. Let
behind the scenes, let me show you. Let me show you. Let's not use pass this
me show you. Let's not use pass this time. Let me just write print hello
time. Let me just write print hello baby. Let's run this. What? What? Why?
baby. Let's run this. What? What? Why? Why? Why are we seeing hello baby? Why?
Why? Why are we seeing hello baby? Why? Because I simply created this object. I
Because I simply created this object. I didn't call this function. I didn't
didn't call this function. I didn't write it like this. employee one then
write it like this. employee one then dot
dot init then like this I didn't do that why
init then like this I didn't do that why it simply return this function or
it simply return this function or basically why it executed this function
basically why it executed this function this is the power of constructor it will
this is the power of constructor it will every time the moment you create the
every time the moment you create the object it will simply run this function
object it will simply run this function which is def init like init cell or it
which is def init like init cell or it will simply you can say take this object
will simply you can say take this object as the parameter and run this. Wow, we
as the parameter and run this. Wow, we take the advantage of this opportunity.
take the advantage of this opportunity. What we do now? We know that we need to
What we do now? We know that we need to simply create two more parameters. It
simply create two more parameters. It says employee name equals let's say your
says employee name equals let's say your name. Let's take a girl's name this
name. Let's take a girl's name this time. Otherwise, you will say, "Hey,
time. Otherwise, you will say, "Hey, where's
so I don't know girl's name. Let's say Priya. Let's say okay I do not
Let's say Priya. Let's say okay I do not know any Priya just a hypothetical word.
know any Priya just a hypothetical word. Okay.
Okay. Employee department. Now you will say I
Employee department. Now you will say I want to hardcode it. Okay like not
want to hardcode it. Okay like not hardcode I want to define these
hardcode I want to define these variables but I want these two variables
variables but I want these two variables should come from a different object.
should come from a different object. That means employee one will have its
That means employee one will have its own employee name and department
own employee name and department employee two will have its own employee
employee two will have its own employee three will have its own. So I want these
three will have its own. So I want these names these attributes coming from
names these attributes coming from different objects. So what we can do
different objects. So what we can do obviously we
obviously we cannot we cannot create like this
cannot we cannot create like this because otherwise it will simply be same
because otherwise it will simply be same for every object. What we will do we
for every object. What we will do we will simply move these from here and I
will simply move these from here and I will put it under here. Make sense? Make
will put it under here. Make sense? Make sense? If not it will make sense very
sense? If not it will make sense very soon. Wait. Okay. And what I will do I
soon. Wait. Okay. And what I will do I will get these parameters from here.
will get these parameters from here. Employee
Employee name. Okay. And then employee
name. Okay. And then employee department. And this name will be what?
department. And this name will be what? It will become self dot employee
It will become self dot employee name. Okay. And it will become self dot
name. Okay. And it will become self dot employee department. So now what we
employee department. So now what we going to do like what what's what's
going to do like what what's what's happening here basically oh sorry uh not
happening here basically oh sorry uh not here
self self dot employee name and self dot this so what is happening here let me
this so what is happening here let me just tell you we know that when we'll be
just tell you we know that when we'll be creating this object this function will
creating this object this function will be triggered automatically so now it's
be triggered automatically so now it's our duty or you can say it's now
our duty or you can say it's now mandatory thing to pass these these two
mandatory thing to pass these these two parameters from the class. So this time
parameters from the class. So this time I will simply say let's say Priya and
I will simply say let's say Priya and then it so what it will do it will
then it so what it will do it will simply trigger this function like this
simply trigger this function like this one in it through this particular class
one in it through this particular class and these parameters Priya and it will
and these parameters Priya and it will go here. Okay. Then what we will do? We
go here. Okay. Then what we will do? We will simply define the class attribute.
will simply define the class attribute. Self dot employee name will become
Self dot employee name will become equals to this. And self dot employee
equals to this. And self dot employee department will be equals to
department will be equals to this.
this. H makes sense. Makes sense because if
H makes sense. Makes sense because if you remember this is the same stuff,
you remember this is the same stuff, right? Whatever we write here, it
right? Whatever we write here, it becomes self dot something. Because
becomes self dot something. Because whenever I want to use this variable at
whenever I want to use this variable at the end of the day, I will be using use
the end of the day, I will be using use I will be using it with the help of self
I will be using it with the help of self keyword. Right? So what we did we simply
keyword. Right? So what we did we simply defined self dot employee name equals to
defined self dot employee name equals to this word and self domply employee uh
this word and self domply employee uh department will become equals to this
department will become equals to this word. Make sense? Let me just run this
word. Make sense? Let me just run this then it will make sense. Okay. Perfect.
then it will make sense. Okay. Perfect. So now this is created. I will simply
So now this is created. I will simply call the function employee
call the function employee 1.info and I should
1.info and I should see perfect employee Priya works for it.
see perfect employee Priya works for it. So now you know what happened. We
So now you know what happened. We created dynamic attributes which are
created dynamic attributes which are coming from the
coming from the object H. So basically there are two
object H. So basically there are two types of attributes class attributes and
types of attributes class attributes and instance attributes. This is a class
instance attributes. This is a class attribute which is constant. These are
attribute which is constant. These are instance attributes which are subject to
instance attributes which are subject to the
the objects. Make sense? So again let me
objects. Make sense? So again let me just tell you the flow. This will
just tell you the flow. This will trigger this function in it. And now
trigger this function in it. And now this function has parameters. That means
this function has parameters. That means we have to define the parameters. Okay.
we have to define the parameters. Okay. So we defined it with prian. Now we
So we defined it with prian. Now we defined self dot employment name and
defined self dot employment name and self dot
self dot department using these two parameters
department using these two parameters that we got from the object. Now we can
that we got from the object. Now we can use these variables anywhere inside this
use these variables anywhere inside this class because now these are class
class because now these are class attributes. Now these are class
attributes. Now these are class attributes. Okay. Let's say I'm creating
attributes. Okay. Let's say I'm creating employee 2. Employee 2
employee 2. Employee 2 equals employee let's say
priu. Priyanchu he works for let's say HR. So now employee 1.info will return
HR. So now employee 1.info will return different results. Employee 2.info info
different results. Employee 2.info info will return different results and we
will return different results and we will see it here. See employee Priya
will see it here. See employee Priya works for IT. Employee Priyanka works
works for IT. Employee Priyanka works for HR. This is your basic example of a
for HR. This is your basic example of a class. This is the
class. This is the example. I hope it makes sense. I hope
example. I hope it makes sense. I hope now you have built a strong base with
now you have built a strong base with class like what is a class and what
class like what is a class and what things we need to just focus on and how
things we need to just focus on and how we just talk about classes. I know I
we just talk about classes. I know I know it looks really easy now because I
know it looks really easy now because I know how to just make you aware the
know how to just make you aware the things there's a flow that we need to
things there's a flow that we need to follow. Okay, make sense. So let me just
follow. Okay, make sense. So let me just see what we have discussed. Okay,
see what we have discussed. Okay, constructors are done because I do not
constructors are done because I do not want to compromise with this section.
want to compromise with this section. Classes are must and I have to cover all
Classes are must and I have to cover all the topics. Okay, very good.
the topics. Okay, very good. Now let's also talk about something.
Now let's also talk about something. Let's say you want to change
Let's say you want to change the value which is class class attribute
the value which is class class attribute for a kind of object. Can you do that?
for a kind of object. Can you do that? Yes. Let's say employee 2. Okay.
Yes. Let's say employee 2. Okay. Employee 2 actually works for a
Employee 2 actually works for a different company. Let's say so it will
different company. Let's say so it will simply say employee
simply say employee 2 dot company
2 dot company name company name equals
name company name equals ABC. So
ABC. So now
now if employee 2 says dot info we should
if employee 2 says dot info we should see something called as obviously it is
see something called as obviously it is not used anywhere. So that's why we are
not used anywhere. So that's why we are not seeing but you can actually see it
not seeing but you can actually see it using this as well.
using this as well. print emp2 dot company
print emp2 dot company name make sense it will return ABC
name make sense it will return ABC perfect now it is no more it is no more
perfect now it is no more it is no more xyz for employee two for employee two
xyz for employee two for employee two let me just minimize the screen yeah now
let me just minimize the screen yeah now it is no more employee two like no more
it is no more employee two like no more xyz for employee two now it is ABC and
xyz for employee two now it is ABC and it is evident print we can even print
it is evident print we can even print it. So we can even change these values
it. So we can even change these values as well using the objects because this
as well using the objects because this is just a template right this is just a
is just a template right this is just a template we can change it we can change
template we can change it we can change it but ideally we do not change the
it but ideally we do not change the values like this because what will
values like this because what will happen with this so let's
happen with this so let's say now a quick question can be before
say now a quick question can be before discussing the next thing um what will
discussing the next thing um what will be the value for employee one will that
be the value for employee one will that be changed as well
be changed as well no let's see employee 1 dot company
no let's see employee 1 dot company name let's see it's still XYZ so it is
name let's see it's still XYZ so it is just changed for employee 2 not for
just changed for employee 2 not for employee one that's the power of
employee one that's the power of objectoriented programming it is not
objectoriented programming it is not being changed for anything else you will
being changed for anything else you will say what if what if we want to change
say what if what if we want to change company name let's say you will say
company name let's say you will say hypothetical situation we want to change
hypothetical situation we want to change company name for all the objects you
company name for all the objects you will simply say one one option is like
will simply say one one option is like simply you can do it here which is not
simply you can do it here which is not recommended. Okay, this time you will
recommended. Okay, this time you will see ABC this is not recommended. There
see ABC this is not recommended. There are other ways as well how you can
are other ways as well how you can simply change the class attributes for
simply change the class attributes for the you can say all the objects you can
the you can say all the objects you can do that we will just discuss that as
do that we will just discuss that as well don't worry I know when you just
well don't worry I know when you just learn object-oriented programming you
learn object-oriented programming you get a lot of doubts but you need to hold
get a lot of doubts but you need to hold your emotions because everything will be
your emotions because everything will be discussed slowly slowly slowly okay okay
discussed slowly slowly slowly okay okay very good so now let's talk about how we
very good so now let's talk about how we can just change the class attribute or
can just change the class attribute or you can say class variable Because you
you can say class variable Because you know because so far you would have the
know because so far you would have the understanding that that you cannot
understanding that that you cannot change the default or you can say class
change the default or you can say class variable using object because that is
variable using object because that is specific to object only but even if you
specific to object only but even if you just want to change it obviously you
just want to change it obviously you should not change it from here like ABC
should not change it from here like ABC no that's not a good choice or you can
no that's not a good choice or you can say recommended approach so how we can
say recommended approach so how we can just do that so basically for that what
just do that so basically for that what we do we simply use the class name let's
we do we simply use the class name let's say employee so employee is class name
say employee so employee is class name we will simply say employee dot company
we will simply say employee dot company name
name equals let's say ABC okay now you can do
equals let's say ABC okay now you can do that and let me simply run it and now
that and let me simply run it and now you can even use
you can even use it let's say you want to create employee
it let's say you want to create employee one that is E1 or let's say oh employee
one that is E1 or let's say oh employee 1 is already there so employee 1 dot um
1 is already there so employee 1 dot um info so now it will simply give me okay
info so now it will simply give me okay it let's add one more thing here let's
it let's add one more thing here let's add works for department in company name
add works for department in company name self
okay perfect let's see uh what's wrong I forgot to close it
uh what's wrong I forgot to close it okay perfect so it is saying employee
okay perfect so it is saying employee Priya works for IT in
Priya works for IT in ABC make sense in or add whatever you
ABC make sense in or add whatever you want to say. So it is saying in ABC. So
want to say. So it is saying in ABC. So actual value was XYZ but we change this
actual value was XYZ but we change this value.
value. Wow.
Wow. Wow. So
Wow. So basically we also do not prefer this
basically we also do not prefer this way. This was just a de demonstration so
way. This was just a de demonstration so that you would understand how we can
that you would understand how we can actually change the value. We cannot use
actually change the value. We cannot use objects. We have to use employee name
objects. We have to use employee name that is class name. But this is also not
that is class name. But this is also not recommended because you cannot keep a
recommended because you cannot keep a track of it, right? Because this is just
track of it, right? Because this is just a piece of code which is referred
a piece of code which is referred outside the class. You should always
outside the class. You should always manage these changes through inside the
manage these changes through inside the class. Really? Yes. Always you should
class. Really? Yes. Always you should always do this. So how how we can just
always do this. So how how we can just do that?
do that? Basically there are so many ways to do
Basically there are so many ways to do that. So let's say you can create a
that. So let's say you can create a different function. Let's
different function. Let's say and we will just talk about that as
say and we will just talk about that as well in the getters and setters but
well in the getters and setters but ideally let me just give you a hint so
ideally let me just give you a hint so that you will hold your excitement. We
that you will hold your excitement. We can simply create a function okay let's
can simply create a function okay let's say changes and you can
say changes and you can actually change the values and you can
actually change the values and you can take the parameter let's say new
take the parameter let's say new company okay and then you can simply say
company okay and then you can simply say employee which is the class name okay
employee which is the class name okay then company
then company name okay
name okay equals new company make
equals new company make sense make sense make sense makes sense
sense make sense make sense makes sense makes sense if you just try to do do
makes sense if you just try to do do this if you just try to do this let's
this if you just try to do this let's try to run this and you will see like
try to run this and you will see like what will happen so let's say you are
what will happen so let's say you are running this
running this particular function okay you are running
particular function okay you are running this particular function so I can simply
this particular function so I can simply say um
say um emp1 dot changes and then I'm simply
emp1 dot changes and then I'm simply saying new company let's say company
saying new company let's say company name is new company okay and then we are
name is new company okay and then we are simply trying to see employee one not
simply trying to see employee one not employee one let's say employee two
employee one let's say employee two because it will be changed for everyone,
because it will be changed for everyone, right? Employee
right? Employee 2.info. Let's see what happened. So, it
2.info. Let's see what happened. So, it has successfully changed this thing.
has successfully changed this thing. Why? Because we have a dedicated
Why? Because we have a dedicated function called changes which can
function called changes which can actually
actually change which can actually change
change which can actually change the class variable or you can say class
the class variable or you can say class attributes. This is a better way of
attributes. This is a better way of doing it. Instead of just changing it
doing it. Instead of just changing it from outside the class, you should
from outside the class, you should always change it within the class. Look
always change it within the class. Look like from inside the class using
like from inside the class using obviously the function like this DF
obviously the function like this DF changes. Now obviously we should not
changes. Now obviously we should not allow to use this function to anyone
allow to use this function to anyone because any object can change anything.
because any object can change anything. Obviously that's a different story.
Obviously that's a different story. We'll just talk about that as well. But
We'll just talk about that as well. But I'm just showing you that this is
I'm just showing you that this is possible and this is the way that we
possible and this is the way that we should make the changes instead of from
should make the changes instead of from outside the
outside the class. Make sense? Make sense? Makes
class. Make sense? Make sense? Makes sense. Very good. Let's try to
sense. Very good. Let's try to understand, static
understand, static method, class method and instance
method, class method and instance methods. So
methods. So basically we already know that these are
basically we already know that these are all methods, right? These are all
all methods, right? These are all methods. Method method method. So
methods. Method method method. So basically these methods have a kind of
basically these methods have a kind of different different categories. So far
different different categories. So far we were only working with instance
we were only working with instance methods. Okay, these were instance
methods. Okay, these were instance methods which are specific to an
methods which are specific to an instance, right? Employee one will
instance, right? Employee one will behave differently like these methods
behave differently like these methods will behave differently for employee
will behave differently for employee one, same for employee two and so on. So
one, same for employee two and so on. So these are your employee like of the
these are your employee like of the employee class. These are
employee class. These are your instance methods. Okay, we have two
your instance methods. Okay, we have two more methods. We have something called
more methods. We have something called as let's say static methods. First of
as let's say static methods. First of all, let's talk about this. What are
all, let's talk about this. What are static methods? Okay, so we have
static methods? Okay, so we have something called as static methods and
something called as static methods and then we have class methods. We'll just
then we have class methods. We'll just talk about after that. So static
talk about after that. So static methods, these methods are you can say
methods, these methods are you can say junk methods. Why? Why junk? because
junk methods. Why? Why junk? because they are not directly related to your
they are not directly related to your class. They are not directly related to
class. They are not directly related to the logic but they are still there
the logic but they are still there because they just need to be shifted
because they just need to be shifted when you are just let's say migrating
when you are just let's say migrating your code or you just want to perform
your code or you just want to perform something within this class. For
something within this class. For example, let's say you have a function
example, let's say you have a function called addition. Okay, addition or you
called addition. Okay, addition or you can say a kind
can say a kind of yeah
of yeah addition. Okay, now you will simply get
addition. Okay, now you will simply get two parameters. Let's say x and
two parameters. Let's say x and y. That's it. And you will simply return
y. That's it. And you will simply return or print let's
or print let's say x + y. That's it. You will say an
say x + y. That's it. You will say an lamba anala just just put um self. You
lamba anala just just put um self. You forgot to add self. No. When you just
forgot to add self. No. When you just create static
create static method, you do not need any kind of self
method, you do not need any kind of self method because it is not related to any
method because it is not related to any object. It is not related to any kind of
object. It is not related to any kind of you can say these attributes, these
you can say these attributes, these class attributes, instance attributes,
class attributes, instance attributes, nothing. These are like not related to
nothing. These are like not related to these things. So why do we use that?
these things. So why do we use that? Let's say within your class you just
Let's say within your class you just want to keep this function to just
want to keep this function to just perform some basic stuff which are
perform some basic stuff which are irrelevant or indirectly linked to other
irrelevant or indirectly linked to other things within the same class. So let's
things within the same class. So let's say I have this employee one. Okay, I
say I have this employee one. Okay, I have created this object. I just want to
have created this object. I just want to perform um basic mathematics of
perform um basic mathematics of addition. I will simply say emp1 dot
addition. I will simply say emp1 dot addition and I will simply get one and
addition and I will simply get one and two. Okay, one and two. Let me comment
two. Okay, one and two. Let me comment it out other things and let's see what
it out other things and let's see what it will return. it will return very
it will return. it will return very good. So by the way this error
good. So by the way this error was intentional. So this by the way if
was intentional. So this by the way if you're just working with classes for
you're just working with classes for let's say if it is your first time you
let's say if it is your first time you will actually see this error a lot. It
will actually see this error a lot. It will simply say employee. Okay takes two
will simply say employee. Okay takes two positional arguments but three were
positional arguments but three were given. You will simply say hey I have
given. You will simply say hey I have just given two parameters who gave
just given two parameters who gave three. Remember whenever you make the
three. Remember whenever you make the call like this? Whenever you make the
call like this? Whenever you make the call like this it will automatically
call like this it will automatically pass the employee one as well. remember
pass the employee one as well. remember because behind the scenes it is running
because behind the scenes it is running something like
something like this
this employee dot
employee dot addition then 1 comma
addition then 1 comma 2 and before 1 comma 2 you can simply
2 and before 1 comma 2 you can simply add emp1 as well but I'm writing it here
add emp1 as well but I'm writing it here okay so in total you are passing three
okay so in total you are passing three parameters so what's the solution of it
parameters so what's the solution of it what's the solution of it so the
what's the solution of it so the solution
solution is we need to tell Python that this is
is we need to tell Python that this is not your regular instance method. This
not your regular instance method. This is a static method. You simply need to
is a static method. You simply need to write
write static method. Now you can simply try
static method. Now you can simply try running this because otherwise it will
running this because otherwise it will treat it as like your normal method
treat it as like your normal method which is your instance method. So we
which is your instance method. So we need to tell hey this is a static
need to tell hey this is a static method.
method. Okay. Wow this was amazing. So it is
Okay. Wow this was amazing. So it is just a kind of you can say function
just a kind of you can say function which we need to just use within the
which we need to just use within the class. That's it. It is not directly
class. That's it. It is not directly linked to your attributes or anything.
linked to your attributes or anything. Make sense? Very good. Now let's try to
Make sense? Very good. Now let's try to discuss what are class methods. What are
discuss what are class methods. What are class
class methods? Class methods are originally
methods? Class methods are originally used to interact with your class
used to interact with your class attributes. Let's say you have your
attributes. Let's say you have your class attribute here company name. So
class attribute here company name. So class methods should be used to interact
class methods should be used to interact directly to your class attributes. You
directly to your class attributes. You will simply say an we are already
will simply say an we are already communicating it here. But let's say you
communicating it here. But let's say you have 100 functions inside this class.
have 100 functions inside this class. Can you just understand like will this
Can you just understand like will this function be directly linked to a class
function be directly linked to a class variable or let's say sorry class
variable or let's say sorry class method? Can you just predict that? No.
method? Can you just predict that? No. So that is why we have a special
So that is why we have a special decorator. It's
decorator. It's called class method. When we write class
called class method. When we write class method now we know that hey this
method now we know that hey this function is specifically built to
function is specifically built to interact with
interact with the class attributes make sense using
the class attributes make sense using this using this you get the special
this using this you get the special power what's that you can actually
power what's that you can actually change the value same way so you now do
change the value same way so you now do not need to write this thing okay
not need to write this thing okay because it is let me just create a new
because it is let me just create a new one so that you can actually compare it
one so that you can actually compare it so this particular function if you just
so this particular function if you just want to achieve the same results using
want to achieve the same results using class method. You will build like this
class method. You will build like this class
class method. Okay. Then you will simply
method. Okay. Then you will simply create a function. It's called let's say
create a function. It's called let's say changes in class. Okay. I will simply
changes in class. Okay. I will simply say self. Then I will simply say new
say self. Then I will simply say new company. Okay. Now I will simply say
company. Okay. Now I will simply say self dot company
self dot company name equals new
name equals new company. Because this is a class method,
company. Because this is a class method, it understands that this self keyword is
it understands that this self keyword is not for the object. This is for the
not for the object. This is for the class itself. This is for the class
class itself. This is for the class itself. Let me just run this. So
itself. Let me just run this. So everything is fine because there's no
everything is fine because there's no error. But you will say an we are still
error. But you will say an we are still feeling that we can feel confused
feeling that we can feel confused because self keyword we use for objects.
because self keyword we use for objects. Yes. Um if we will be using it with
Yes. Um if we will be using it with class it can become confusing and we
class it can become confusing and we know that we have a decorator called
know that we have a decorator called class method but still it can be
class method but still it can be confusing. Exactly. That is why whenever
confusing. Exactly. That is why whenever you define a class method you have the
you define a class method you have the liberty to change this name. You can
liberty to change this name. You can give any name and as per the industry we
give any name and as per the industry we give name called cls class that means we
give name called cls class that means we are referring to the class attributes
are referring to the class attributes this is a like industry standard we use
this is a like industry standard we use cls you can just use anything you can
cls you can just use anything you can use like let's
use like let's say anything let's say protein let's say
say anything let's say protein let's say anything okay you can just put
anything okay you can just put anything so it's up to you even if you
anything so it's up to you even if you use self it will work but just for the
use self it will work but just for the readability and as per the industry
readability and as per the industry standards it will work. Let me just show
standards it will work. Let me just show you. Let's say I want to make this call
you. Let's say I want to make this call with any object I will simply
with any object I will simply say
say changes in class. I'll simply say new
changes in class. I'll simply say new new
new company. Okay. And then I will simply
company. Okay. And then I will simply say emp1
dot print of emp1 dot company name okay let's
name okay let's see new new company see so it is just a
see new new company see so it is just a naming convention but you should always
naming convention but you should always use cls because it will be easy to
use cls because it will be easy to interpret okay this is for cls class now
interpret okay this is for cls class now the same stuff can be achieved using
the same stuff can be achieved using this function as well but it is not
this function as well but it is not recommended Ed because it is not good
recommended Ed because it is not good when you have so many functions. Okay,
when you have so many functions. Okay, it is literally doesn't make any sense.
it is literally doesn't make any sense. That's why we have decorators. We should
That's why we have decorators. We should always use decorators. Plus, it promotes
always use decorators. Plus, it promotes you can say standard approach. Why?
you can say standard approach. Why? Because see all the other functions are
Because see all the other functions are similar like company name dot company
similar like company name dot company name blah blah blah. Here it is using
name blah blah blah. Here it is using the class name. So it it doesn't make
the class name. So it it doesn't make any sense. So that is why instead of
any sense. So that is why instead of using this one, you can use this. Again,
using this one, you can use this. Again, it is just a programming. It's up to
it is just a programming. It's up to developer what code they want to just
developer what code they want to just prefer. Okay. So it's up to you. So it
prefer. Okay. So it's up to you. So it is the same thing. I can simply write
alternative alternative to class method. I know it
alternative to class method. I know it is not visible so can't help. So so so
is not visible so can't help. So so so make sense. Let me just use white light.
make sense. Let me just use white light. Oh wow. Wow. Good
Oh wow. Wow. Good morning. Let's use this one. This is
morning. Let's use this one. This is also good. Okay. Perfect. So as you can
also good. Okay. Perfect. So as you can see now comments now you can see the
see now comments now you can see the comments. I know developers like this
comments. I know developers like this thing this thing. Wow. Yellow color
thing this thing. Wow. Yellow color white color. Okay. But this is also
white color. Okay. But this is also nice. This is also nice. Okay. Perfect.
nice. This is also nice. Okay. Perfect. So this was all about your instance
So this was all about your instance methods class methods and static
methods class methods and static methods. I hope now it is very much
methods. I hope now it is very much clear. I hope. Now let's see what do we
clear. I hope. Now let's see what do we have next. Let's talk about getters and
have next. Let's talk about getters and setters. So basically as the name
setters. So basically as the name suggest getters and setters getter
suggest getters and setters getter function or you can say getter method is
function or you can say getter method is used to return the values basically to
used to return the values basically to get the values get the
get the values get the values whereas on the other hand setter
values whereas on the other hand setter is used to set the values to set the
is used to set the values to set the values basically to let's say um set the
values basically to let's say um set the um
um instance attributes
instance attributes So this behaves exactly similar but
So this behaves exactly similar but syntax is a little bit complex but the
syntax is a little bit complex but the concept is very easy. So first of all
concept is very easy. So first of all we'll try to get like have the concepts
we'll try to get like have the concepts clear in our mind. Once the concepts are
clear in our mind. Once the concepts are clear then we will just switch to
clear then we will just switch to getters and setters because getters and
getters and setters because getters and setters can be achieved through your
setters can be achieved through your normal functions normal methods as well.
normal functions normal methods as well. But once you grab the concept getters
But once you grab the concept getters and setters are like your go-to buddy
and setters are like your go-to buddy for all those things. So let me first
for all those things. So let me first you make you understand like what are
you make you understand like what are the getters and setters concepts and
the getters and setters concepts and then we will simply try to shift our
then we will simply try to shift our code to getters and setters. Let me just
code to getters and setters. Let me just so first of all let me just turn off the
so first of all let me just turn off the lights. Woohoo. Perfect. So basically
lights. Woohoo. Perfect. So basically let's say let's say let me first first
let's say let's say let me first first of all remove this class method. We do
of all remove this class method. We do not need it. Or maybe let's keep it. No
not need it. Or maybe let's keep it. No worries. So let's say we are trying to
worries. So let's say we are trying to create one method which is called show
create one method which is called show me. Okay. Show
me. Okay. Show me. Make sense? And obviously we need to
me. Make sense? And obviously we need to use self because it's just an uh just an
use self because it's just an uh just an instance method. Okay. Within this it
instance method. Okay. Within this it will simply show us all the details. All
will simply show us all the details. All the details. Okay. Or I think we already
the details. Okay. Or I think we already have a function which is similar to show
have a function which is similar to show me because it is just showing the
me because it is just showing the information. Let's use this one. Let's
information. Let's use this one. Let's use this
use this one. Okay. Perfect. So we are using this
one. Okay. Perfect. So we are using this info function and let me just cut and
info function and let me just cut and paste at the top so that you can
paste at the top so that you can actually focus on this.
actually focus on this. Okay, perfect. Uh perfect. So basically
Okay, perfect. Uh perfect. So basically what this function is doing this
what this function is doing this function is returning all the things
function is returning all the things employee name, employee department and
employee name, employee department and company name. Make sense? That's what a
company name. Make sense? That's what a getter function does. Makes sense. Now
getter function does. Makes sense. Now let's say I want to change the value for
let's say I want to change the value for this particular object or basically
this particular object or basically object is employee one. Let's say the
object is employee one. Let's say the values before
values before were Priya and ID. Okay. So I can simply
were Priya and ID. Okay. So I can simply say employee 1 dot info and I should see
say employee 1 dot info and I should see those stuff. Okay. Perfect. Now let's
those stuff. Okay. Perfect. Now let's say I want to change the value. How I
say I want to change the value. How I can just do that? I can even use like
can just do that? I can even use like this. If you think you can use this,
this. If you think you can use this, let's say employee 1 dot
let's say employee 1 dot empame equals let's say Priya, she needs
empame equals let's say Priya, she needs to add one more a. Okay. And employee 1
to add one more a. Okay. And employee 1 dot employee department equals let's say
dot employee department equals let's say HR let's say now if I just call this
HR let's say now if I just call this function what will
function what will happen? Let's see what will happen. It
happen? Let's see what will happen. It will work. Okay. So this is the basic
will work. Okay. So this is the basic way to update
way to update the instance attributes. Makes sense?
the instance attributes. Makes sense? But we just talked about that we should
But we just talked about that we should not do this from outside the class. We
not do this from outside the class. We should have a function for it. So what
should have a function for it. So what we will do now? We will simply create a
we will do now? We will simply create a function
function called
called def change info. Okay. And within this
def change info. Okay. And within this we'll simply get employee name or
we'll simply get employee name or basically new employee
basically new employee name. Okay. And then new employee
name. Okay. And then new employee department. Make sense? Within this what
department. Make sense? Within this what we will do? We'll simply say self dot
we will do? We'll simply say self dot employee name equals new employee name.
employee name equals new employee name. self dot employee
department equals new employee department make sense. So if we just run
department make sense. So if we just run this what will happen? We can even
this what will happen? We can even change our info from this function
change our info from this function because we will simply call this
because we will simply call this function and this will simply change
function and this will simply change employee name and employee department
employee name and employee department for that particular instance which is
for that particular instance which is employee one. Let's do this. I will
employee one. Let's do this. I will simply say employee.info. Then I will
simply say employee.info. Then I will call this function employee 1 dot change
call this function employee 1 dot change info. I will simply
info. I will simply say priya and HR. So we should see this
say priya and HR. So we should see this difference. Perfect. It worked. It
difference. Perfect. It worked. It worked very well. So this function is
worked very well. So this function is called getter and I'm just talking about
called getter and I'm just talking about the concept. Okay. This is your getter
the concept. Okay. This is your getter and this is your setter. If you just
and this is your setter. If you just want to use traditional approach like
want to use traditional approach like achieving the same results without using
achieving the same results without using getter and setter. Okay. So this is your
getter and setter. Okay. So this is your getter. This is your setter. Now if you
getter. This is your setter. Now if you just want to use getter and setter
just want to use getter and setter method the way that we use within a
method the way that we use within a class let me just tell you now this is
class let me just tell you now this is really gamechanging. Let me just comment
really gamechanging. Let me just comment it out. So we know that this is our
it out. So we know that this is our getter function. Make sense? This will
getter function. Make sense? This will be our getter function. We will simply
be our getter function. We will simply add a decorator here. We will simply say
add a decorator here. We will simply say property. That means this is our
property. That means this is our getter. Make sense? This is our getter
getter. Make sense? This is our getter function. Now we need to create a setter
function. Now we need to create a setter function. Setter function is very
function. Setter function is very special. How? In order to create setter
special. How? In order to create setter function, you simply need to write at
function, you simply need to write at the rate info that is the same name.
the rate info that is the same name. Okay. info dot setter
Okay. info dot setter because because this is the setter for
because because this is the setter for this particular function of getter.
this particular function of getter. Okay, info dot setter and then you
Okay, info dot setter and then you simply need to have the parameters
simply need to have the parameters self, employee name that is new employee
self, employee name that is new employee name and new employee department. Make
name and new employee department. Make sense? Very good. Now within this you
sense? Very good. Now within this you will create another function with the
will create another function with the same name info. Oh wow this is amazing.
same name info. Oh wow this is amazing. Yes. So basically these things will go
Yes. So basically these things will go here. Okay. These things will go
here. Okay. These things will go here. Perfect. So this way you will
here. Perfect. So this way you will create the same function with the same
create the same function with the same name and this will be your setter. This
name and this will be your setter. This will be your getter. Don't worry you
will be your getter. Don't worry you will not be confused while calling it.
will not be confused while calling it. Don't worry. I will just show you how to
Don't worry. I will just show you how to call these functions. So basically this
call these functions. So basically this will perform the same stuff like self
will perform the same stuff like self dot something like we are doing here. I
dot something like we are doing here. I can simply copy and paste
can simply copy and paste it. Perfect. So what it will do? It will
it. Perfect. So what it will do? It will simply make the changes in my
simply make the changes in my particular attributes. Make sense? Okay.
particular attributes. Make sense? Okay. This is my setup. So now in order
This is my setup. So now in order to use this there's a different way.
to use this there's a different way. First of all, let's make sure like
First of all, let's make sure like everything is fine. Let's run this.
everything is fine. Let's run this. Okay, error. Where's the error?
Okay, error. Where's the error? Unexpected indent. Oh man, this
Unexpected indent. Oh man, this indentation. Um. Oh, we may need to use
indentation. Um. Oh, we may need to use this. Noops. Wait, wait, wait. Uh, this.
this. Noops. Wait, wait, wait. Uh, this. Oh,
Oh, no. What's the What's the What's the
no. What's the What's the What's the Wait, am I using the same name? info.
Wait, am I using the same name? info. Info. Okay. Dot setter. Yes. Oh, silly
Info. Okay. Dot setter. Yes. Oh, silly mistake. You do not need to indent your
mistake. You do not need to indent your function within the setter. I was like,
function within the setter. I was like, what's wrong with this syntax? So, let's
what's wrong with this syntax? So, let's see if it is fine. Yeah, it is fine.
see if it is fine. Yeah, it is fine. Now, you will say this function is also
Now, you will say this function is also info. This function is also info. How we
info. This function is also info. How we will call these functions? There's a
will call these functions? There's a special trick to call these functions.
special trick to call these functions. Now, this time if you want to call this
Now, this time if you want to call this function, obviously you will first of
function, obviously you will first of all create the object. Now you will not
all create the object. Now you will not call this functions like this like this.
call this functions like this like this. No, you will simply say
No, you will simply say print employee 1.info. You will treat
print employee 1.info. You will treat this function as your attribute. See
this function as your attribute. See perfect. You will treat this function as
perfect. You will treat this function as your
your attribute. Now if you just want to call
attribute. Now if you just want to call this function now, so you will do
this function now, so you will do something like this. employee
something like this. employee 1 dot info equals to because you have
1 dot info equals to because you have two parameters so you simply need to
two parameters so you simply need to provide two parameters you will simply
provide two parameters you will simply say simply pass a list and we will
say simply pass a list and we will simply say priya and then HR now this
simply say priya and then HR now this list will go here in this particular
list will go here in this particular parameter so I have removed this
parameter so I have removed this parameter with the earlier parameters
parameter with the earlier parameters earlier parameters were looking like
earlier parameters were looking like this new employee new employee name and
this new employee new employee name and new employee department. So the thing is
new employee department. So the thing is we cannot pass like
we cannot pass like multiple parameters. We should always
multiple parameters. We should always pass like one parameter. So we will
pass like one parameter. So we will simply pass only one. I'll simply say
simply pass only one. I'll simply say new employee details. Make sense? So
new employee details. Make sense? So this will be a list. We will play smart.
this will be a list. We will play smart. What we will do? We will simply say new
What we will do? We will simply say new employee
employee name equals new employee
name equals new employee details of zero index because we know
details of zero index because we know there are like two entities within that.
there are like two entities within that. That's why fundamentals help you a lot
That's why fundamentals help you a lot to debug things. Employee name or let's
to debug things. Employee name or let's say employee department equals new
say employee department equals new employee
employee details of one index. That makes sense.
details of one index. That makes sense. That's sorted. Now we can simply say
That's sorted. Now we can simply say employee 1 dot
employee 1 dot um
um info and we can simply say
print. Makes sense. Let's see what do we get. Okay, perfect. Priya works for HR
get. Okay, perfect. Priya works for HR in XYZ. Perfect. So this is the
in XYZ. Perfect. So this is the setter. This is the
setter. This is the setter and this is the
setter and this is the getter. This is the getter. Make sense?
getter. This is the getter. Make sense? Setter and getter I hope are now clear.
Setter and getter I hope are now clear. So we simply first of all created our
So we simply first of all created our normal function which is getter. We
normal function which is getter. We created property. We added property
created property. We added property decorator on top of it. That will be
decorator on top of it. That will be acted as a getter. Then we simply used
acted as a getter. Then we simply used this function. Okay. Add the rate info
this function. Okay. Add the rate info setter. Then we created the same
setter. Then we created the same function of same name but obviously we
function of same name but obviously we are using a different code. We are just
are using a different code. We are just updating the values that is self dot
updating the values that is self dot employee name equals to this and this.
employee name equals to this and this. That's it. And how we can just call it?
That's it. And how we can just call it? We need to call it like a
We need to call it like a um attribute. And we need to call the
um attribute. And we need to call the setter like an attribute as well.
setter like an attribute as well. Simple. That's the concept of your like
Simple. That's the concept of your like getters and setters in Python. Make
getters and setters in Python. Make sense? Very good. Let's see what do we
sense? Very good. Let's see what do we have next. Let's talk about inheritance.
have next. Let's talk about inheritance. I know this is the most scared area and
I know this is the most scared area and trust me, trust me in just few minutes
trust me, trust me in just few minutes you will master it. Inheritance. So
you will master it. Inheritance. So basically why do we need inheritance and
basically why do we need inheritance and what does it mean actually? So let's say
what does it mean actually? So let's say inheritance is just like a kind of
inheritance is just like a kind of biological term in which we say there
biological term in which we say there will be a parent then there will be a
will be a parent then there will be a child let's say then its child then its
child let's say then its child then its child same concept is applied here as
child same concept is applied here as well in the python inheritance. So what
well in the python inheritance. So what will happen? Let's say you have a class.
will happen? Let's say you have a class. Okay, you have a class. You have a class
Okay, you have a class. You have a class called employ. Um company. Let's start
called employ. Um company. Let's start from here. Company.
from here. Company. Okay.
Okay. Then you have a class called employee,
Then you have a class called employee, right?
right? Then let's say you have a
Then let's say you have a class
called let's say hobbies. Hobbies let's say. So we know that we already have a
say. So we know that we already have a kind of inheritance. We have a kind of
kind of inheritance. We have a kind of hierarchy. Class company is the parent
hierarchy. Class company is the parent class. Right?
class. Right? And if we are creating a new class
And if we are creating a new class called
called employee, obviously we would need all
employee, obviously we would need all the functions, all the variables that
the functions, all the variables that would be there in this
would be there in this class. Make sense? Because obviously it
class. Make sense? Because obviously it is linked to employee as
is linked to employee as well. Then we do not need to recreate
well. Then we do not need to recreate all the functions that means all the
all the functions that means all the methods. We do not need to recreate all
methods. We do not need to recreate all the attributes. What we will simply do?
the attributes. What we will simply do? We will simply inherit this class while
We will simply inherit this class while creating the employee class. Within just
creating the employee class. Within just click, you will actually import
click, you will actually import everything from the class
everything from the class company. Make sense? This is the concept
company. Make sense? This is the concept of
of inheritance. Then let's say you are
inheritance. Then let's say you are creating a new class called hobbies.
creating a new class called hobbies. Obviously, obviously if you are just
Obviously, obviously if you are just trying to create a hobbies class, you
trying to create a hobbies class, you would just need to get all the
would just need to get all the information of the employees because
information of the employees because hobbies will belong to the employees.
hobbies will belong to the employees. Makes sense?
Makes sense? Then instead of creating all the
Then instead of creating all the methods, all the attributes, you will
methods, all the attributes, you will simply
simply import or if I just talk with technical
import or if I just talk with technical terms, you will simply inherit the class
terms, you will simply inherit the class employee. We have so many levels
employee. We have so many levels actually. We have single level. Okay. We
actually. We have single level. Okay. We have
have multi-level. we have multiple
multi-level. we have multiple level. So these are three
level. So these are three major inheritance levels that we're
major inheritance levels that we're going to talk today. Let's actually get
going to talk today. Let's actually get started with the single level
started with the single level inheritance and let's see how it
inheritance and let's see how it behaves. And for this inheritance topic,
behaves. And for this inheritance topic, I was first thinking to just touch up
I was first thinking to just touch up from the you can say top. Okay, but then
from the you can say top. Okay, but then I thought like let's actually dive
I thought like let's actually dive deeper inside this topic because this is
deeper inside this topic because this is really really helpful and let me just
really really helpful and let me just show you how you can just work with
show you how you can just work with inheritance. So let's start fresh. Let's
inheritance. So let's start fresh. Let's remove all the things. Let's say we are
remove all the things. Let's say we are first of all creating a class called
first of all creating a class called company.
company. Okay, perfect. Within this we will
Okay, perfect. Within this we will simply create a
simply create a constructor or let's not start with
constructor or let's not start with constructor. Let me just first show you
constructor. Let me just first show you the concept then you'll simply dive
the concept then you'll simply dive deeper with complex scenarios. So let's
deeper with complex scenarios. So let's say you have just a simple function
say you have just a simple function called
called company info.
company info. Okay, which simply turns company name
is now let's say XYZ. Okay, that's it. This is the class.
XYZ. Okay, that's it. This is the class. Then you created a new class called
Then you created a new class called employee. And within this you have a
employee. And within this you have a function called employee
function called employee info. Okay. Within
info. Okay. Within this you are simply saying employee
this you are simply saying employee name is
name is um let's say
um let's say um anything. Let's say Priya. Who is
um anything. Let's say Priya. Who is Priya man? Just say Rahul.
Priya man? Just say Rahul. So this is the second class.
So this is the second class. Now I want to also call this function
Now I want to also call this function from this class. So instead of let's say
from this class. So instead of let's say copy pasting it here and recreating all
copy pasting it here and recreating all the functions, I will simply say inherit
the functions, I will simply say inherit company class while creating the
company class while creating the employee class. That's it. Now what will
employee class. That's it. Now what will happen if I
happen if I create employee one object just for this
create employee one object just for this class? just for this class. Okay, I will
class? just for this class. Okay, I will simply say employee that's it. If I say
simply say employee that's it. If I say employee 1 dot employee info, you will
employee 1 dot employee info, you will say that makes sense because we know
say that makes sense because we know that we can just access that particular
that we can just access that particular function. Okay. Um what's wrong? Wait.
function. Okay. Um what's wrong? Wait. Oh,
self. Okay. Self. Let's run this. Perfect. Employee name is Rahul.
Perfect. Employee name is Rahul. This is like very basic stuff. Can I run
This is like very basic stuff. Can I run this function as well? Because there's a
this function as well? Because there's a separate class and there's no object for
separate class and there's no object for this class. Yes, you can do that.
this class. Yes, you can do that. Really?
Really? Yes, you can do that. Perfect. How it
Yes, you can do that. Perfect. How it was possible? How? Because you inherited
was possible? How? Because you inherited this class. You inherited this class.
this class. You inherited this class. That means all these functions are
That means all these functions are accessible from this class as well.
accessible from this class as well. This is your single level
This is your single level inheritance. Single
inheritance. Single level. Okay. Let's now make it complex
level. Okay. Let's now make it complex because now you understood the concept.
because now you understood the concept. Let's make it complex. So the thing
Let's make it complex. So the thing is this is very simple. If you just want
is this is very simple. If you just want to understand the concept but actually
to understand the concept but actually in the real
in the real world you will have constructors as
world you will have constructors as well. And when we have constructors it
well. And when we have constructors it becomes hard to work with inheritance.
becomes hard to work with inheritance. Let's say you have a constructor
Let's say you have a constructor called
called DF in it and then self obviously then
DF in it and then self obviously then company name. Okay, very good. And you
company name. Okay, very good. And you will simply say self dot company name
will simply say self dot company name equals company name. Make
equals company name. Make sense? Same thing here as well. You
sense? Same thing here as well. You have constructor here as well. You will
have constructor here as well. You will say what's the big deal? What wh why it
say what's the big deal? What wh why it is a big deal? I will just tell you wait
is a big deal? I will just tell you wait here it will be employee
here it will be employee name
okay employee name perfect makes sense now tell me one
name perfect makes sense now tell me one thing will it work it work will it work
thing will it work it work will it work no
no why because the answer is simple let's
why because the answer is simple let's say let's make this you can is a
say let's make this you can is a function a little bit
function a little bit complex. I am inheriting company class
complex. I am inheriting company class and there's a reason behind it. So if I
and there's a reason behind it. So if I want to use functions or you can say
want to use functions or you can say even the attributes. So let's first of
even the attributes. So let's first of all make it dynamic. We will simply
all make it dynamic. We will simply say f and
say f and then self dot company name. Right?
then self dot company name. Right? Okay, makes sense. This is perfect.
Okay, makes sense. This is perfect. Similarly, here as well, employee name
is self dot employee name. Okay, perfect.
perfect. So now what we need to do, what we need
So now what we need to do, what we need to do, you'll simply say, okay, this
to do, you'll simply say, okay, this should be fine. This should be fine. And
should be fine. This should be fine. And actually truly speaking when I will just
actually truly speaking when I will just try to run this, let's say I'm trying to
try to run this, let's say I'm trying to access
access um this function employee
um this function employee info. Okay, if I just try to run this, I
info. Okay, if I just try to run this, I will see the error. By the way, this is
will see the error. By the way, this is just due to the missing curly braces.
just due to the missing curly braces. And let's see if everything is fine.
And let's see if everything is fine. Okay. Oh, just indentation issue. Okay,
Okay. Oh, just indentation issue. Okay, perfect. I think rest of the stuffs are
perfect. I think rest of the stuffs are fine. Okay. And obviously we need to
fine. Okay. And obviously we need to assign the employee name because we are
assign the employee name because we are just creating this. Let's say
just creating this. Let's say Rahul let's say. Okay. Let's try to run
Rahul let's say. Okay. Let's try to run this. We simply got employee name is
this. We simply got employee name is Rahul. This was expected. But now if you
Rahul. This was expected. But now if you will try to run this function which is
will try to run this function which is company info, you cannot. Why? I will
company info, you cannot. Why? I will just tell you.
just tell you. It will simply say we do not have any
It will simply say we do not have any parameter assigned to it because when we
parameter assigned to it because when we created this class, yes, we inherited
created this class, yes, we inherited it. But we didn't mention its
it. But we didn't mention its attributes. That is why if we just want
attributes. That is why if we just want to explain classes
to explain classes without attributes and without uh you
without attributes and without uh you can say constructor, it is very easy.
can say constructor, it is very easy. But when we just want to define it with
But when we just want to define it with attributes and constructors, it is a
attributes and constructors, it is a task and I have taken the task. So it is
task and I have taken the task. So it is very easy. So basically the stuff is now
very easy. So basically the stuff is now you need to take care of the other
you need to take care of the other parameters as well. That means of your
parameters as well. That means of your parent class that means you will simply
parent class that means you will simply define it here company name. Let's say
define it here company name. Let's say company
company name. Okay. And here you will define the
name. Okay. And here you will define the self dot company name as well. Yes, you
self dot company name as well. Yes, you have to you have to make sense. Now you
have to you have to make sense. Now you will simply pass the company as well
will simply pass the company as well which is let's say
which is let's say um
um XYZ or let's say yeah
XYZ or let's say yeah XYZ. So did you get my point? Even if we
XYZ. So did you get my point? Even if we do not
do not have
have the employee name required but if we are
the employee name required but if we are inheriting the parent class if we have
inheriting the parent class if we have company name there we have to include it
company name there we have to include it in our constructor otherwise we cannot
in our constructor otherwise we cannot use their attributes. Does that make any
use their attributes. Does that make any sense? If you're inheriting it you have
sense? If you're inheriting it you have to provide the attributes right? So you
to provide the attributes right? So you have to do it. Very good. Very good. So
have to do it. Very good. Very good. So now if you just try to run this you will
now if you just try to run this you will simply see company name is XYZ
simply see company name is XYZ perfect an
perfect an Lamba we have a question simply ask is
Lamba we have a question simply ask is there any way to add this particular
there any way to add this particular function within
function within your class yes we have a function for it
your class yes we have a function for it so what's the way of doing it it's very
so what's the way of doing it it's very simple so what you will do you will
simple so what you will do you will create a normal regular function or you
create a normal regular function or you can say regular uh method you will
can say regular uh method you will simply say DF um company info. Okay. DF
simply say DF um company info. Okay. DF company info. Same name. Yes, you can
company info. Same name. Yes, you can keep the same name. And I will just show
keep the same name. And I will just show you the flow as well how it behaves. You
you the flow as well how it behaves. You will simply say self. And within this
will simply say self. And within this what you will do? You will simply call
what you will do? You will simply call the function which is this one. You can
the function which is this one. You can call the function or let's say let's
call the function or let's say let's start with the different name because
start with the different name because you will feel confused. Let's say
you will feel confused. Let's say company info child. That means it is
company info child. That means it is running from the child class or you can
running from the child class or you can say children classes. Okay. Then I will
say children classes. Okay. Then I will simply say I want to call this function.
simply say I want to call this function. Whenever I want to run this function, I
Whenever I want to run this function, I want to call this function. So how I can
want to call this function. So how I can just call this function? I will simply
just call this function? I will simply write
write um class name I guess. Yeah.
um class name I guess. Yeah. Company company dot company info. That
Company company dot company info. That means
means the function. Make sense? Make sense? So
the function. Make sense? Make sense? So now you are simply calling this function
now you are simply calling this function and there's no parameter required. So
and there's no parameter required. So you will simply run this. Now I can
you will simply run this. Now I can access this. I will simply say company
access this. I will simply say company info
info child. So what will happen? It will
child. So what will happen? It will simply give me this. And in order to
simply give me this. And in order to distinguish it, I will do one more
distinguish it, I will do one more thing. I will simply say
thing. I will simply say print this is
print this is running
running from employee. Okay. Let me run this. Oh
from employee. Okay. Let me run this. Oh wow. Error. What's wrong? What's wrong?
wow. Error. What's wrong? What's wrong? What's wrong? Um, company not
What's wrong? Um, company not encompassing one required position
encompassing one required position information. Oh, makes sense. So,
information. Oh, makes sense. So, basically it has the self, right? It has
basically it has the self, right? It has the self. So, you have to just provide
the self. So, you have to just provide the
the self. Perfect. This is running from
self. Perfect. This is running from employee and we are getting company name
employee and we are getting company name is XYZ. Wow. That means we have
is XYZ. Wow. That means we have literally called the parent function.
literally called the parent function. the function from the parent class into
the function from the parent class into the child class using this approach.
the child class using this approach. It's called company dot company info
It's called company dot company info that means employee that means basically
that means employee that means basically the class dot method simple and then
the class dot method simple and then self. You can even use something called
self. You can even use something called as super keyword. I do not recommend it.
as super keyword. I do not recommend it. Okay, you can use it if you want. Why
Okay, you can use it if you want. Why don't you recommend it? And what is this
don't you recommend it? And what is this function? Basically this particular
function? Basically this particular command is equivalent to this one. Super
command is equivalent to this one. Super keyword super
keyword super dot company
info. Okay, let me just comment it out and let me just run
and let me just run this. See same results. So what is a
this. See same results. So what is a super function? Super function means you
super function? Super function means you are actually accessing the function from
are actually accessing the function from the parent class which is just one level
the parent class which is just one level up. Which is just one level up. This is
up. Which is just one level up. This is handy when you are using single level
handy when you are using single level inheritance. This is a mess when you use
inheritance. This is a mess when you use multi-level inheritance. So why you want
multi-level inheritance. So why you want to add a mess? It is fine. You should
to add a mess? It is fine. You should know about it. But I would recommend you
know about it. But I would recommend you to stick to this approach. Which
to stick to this approach. Which one? The above one. Why? Because it will
one? The above one. Why? Because it will remain the same in multi-level in
remain the same in multi-level in multiple and in your single level as
multiple and in your single level as well. So just to make things clear, you
well. So just to make things clear, you should stick to this one. But yes, you
should stick to this one. But yes, you should know about super keyword as well.
should know about super keyword as well. Makes sense. I hope now it makes sense.
Makes sense. I hope now it makes sense. Now one real time approach. Let's say in
Now one real time approach. Let's say in this particular def
this particular def constructor I have so many attributes
constructor I have so many attributes and I do not want to pass those
and I do not want to pass those attributes because it is a
attributes because it is a task. It is literally a task. I do not
task. It is literally a task. I do not want to write self dot self dot self dot
want to write self dot self dot self dot self dot self dot I cannot let's imagine
self dot self dot I cannot let's imagine I have 100 u attributes so you can use
I have 100 u attributes so you can use this function here as well so what you
this function here as well so what you will do um we know that we have to use
will do um we know that we have to use this because this is the children or you
this because this is the children or you can say child class employee name but
can say child class employee name but for the other thing you can replace this
for the other thing you can replace this with like this company dot
with like this company dot init and then you simply can pass all
init and then you simply can pass all the variables let's say self then
the variables let's say self then obviously it needs company name right
obviously it needs company name right you will simply say company name that's
you will simply say company name that's it and from where it is getting company
it and from where it is getting company name it is getting company name from
name it is getting company name from here okay it is getting company name
here okay it is getting company name from here it will simply pick the
from here it will simply pick the company
company name oh so we can just comment it out
name oh so we can just comment it out then yes you can comment it out let's
then yes you can comment it out let's run
run this perfect it is running fine so this
this perfect it is running fine so this is another way of doing it. So that
is another way of doing it. So that means you are receiving company name.
means you are receiving company name. Okay. And within this you are passing
Okay. And within this you are passing this particular function, this
this particular function, this particular parameter here. And this way
particular parameter here. And this way you do not need to write self dot self
you do not need to write self dot self dot self dot because let's say I have
dot self dot because let's say I have one more
um attribute let's say country. Okay. And this is country name
country. Okay. And this is country name or let's say just country. Okay. So this
or let's say just country. Okay. So this is
country. Obviously I will receive the country from the object. Let's
country from the object. Let's say US let's say. So here I will simply
say US let's say. So here I will simply pass the country as well. And I need to
pass the country as well. And I need to include country in my constructor as
include country in my constructor as well. See that's how the chain works.
well. See that's how the chain works. You will see. And obviously we are not
You will see. And obviously we are not using country. So let's use it here.
using country. So let's use it here. Um company info company name is
Um company info company name is this in let's say country self dot
this in let's say country self dot country make
country make sense I hope so perfect in US very good
sense I hope so perfect in US very good this is the complex real world scenario
this is the complex real world scenario of inheritance this is the real
of inheritance this is the real inheritance okay make sense so this was
inheritance okay make sense so this was your single level inheritance Let's say
your single level inheritance Let's say you want to create multiple inheritance.
you want to create multiple inheritance. Before discussing about multi-level, we
Before discussing about multi-level, we will just talk about
will just talk about multiple multiple inheritance. So let's
multiple multiple inheritance. So let's say you have one more class. Okay, you
say you have one more class. Okay, you have one more class and this class name
have one more class and this class name is basically uh multiple inheritance
is basically uh multiple inheritance like this. Let's say you have one parent
like this. Let's say you have one parent class. It's called company.
class. It's called company. Okay. Then you have another
Okay. Then you have another um you can say parent class. And what
um you can say parent class. And what can be the parent
can be the parent class? Uh let's say department. Yep.
class? Uh let's say department. Yep. Department. No, department is not a good
Department. No, department is not a good example.
example. [Music]
[Music] Um let's say we
Um let's say we have
have class equals to region. Let's
class equals to region. Let's say region or let's say country. Let's
say region or let's say country. Let's create a separate one for country. Okay,
create a separate one for country. Okay, we have country. So the this is my
we have country. So the this is my parent class one. This is my parent
parent class one. This is my parent class two. Now I am creating my child
class two. Now I am creating my child class which is called employee. Now
class which is called employee. Now within this class I need
within this class I need to add this as my
to add this as my parent
parent and this as my parent as well. So now
and this as my parent as well. So now there are two parents. Make sense? There
there are two parents. Make sense? There are two parents. And this is very
are two parents. And this is very simple. This is very simple because now
simple. This is very simple because now you have a strong base ready. You can
you have a strong base ready. You can just use anything. So now let's say you
just use anything. So now let's say you have a class called country.
Okay. And let's remove country from here just to make it simple. Okay. Perfect.
just to make it simple. Okay. Perfect. Perfect.
Perfect. And perfect. And let's remove country
And perfect. And let's remove country from here because we'll be using it with
from here because we'll be using it with the different parent. Perfect. And
the different parent. Perfect. And there's no need to pass it here.
there's no need to pass it here. Perfect. And let me just check like
Perfect. And let me just check like everything is running fine because we
everything is running fine because we removed some stuff. Oops. Something is
removed some stuff. Oops. Something is missing.
missing. Um. Oh yeah, we need to remove it from
Um. Oh yeah, we need to remove it from here as well. Perfect. Now I think it
here as well. Perfect. Now I think it should be good. Perfect. Yes. Now let's
should be good. Perfect. Yes. Now let's create a new class. It's called
create a new class. It's called country, right?
country, right? So we will have a
So we will have a constructor df in it and then self and
constructor df in it and then self and this will be let's say country name or
this will be let's say country name or let's say just country or let's say
let's say just country or let's say country name. I will simply say self
country name. I will simply say self dot country
dot country name equals to country name. Okay, this
name equals to country name. Okay, this is simple. This is simple stuff. And
is simple. This is simple stuff. And within this we have def country info.
within this we have def country info. Okay, makes sense. I'll simply say self
Okay, makes sense. I'll simply say self and I will simply
print country name is self dot country name. Make sense? Very good.
dot country name. Make sense? Very good. So this is my second class. Now I want
So this is my second class. Now I want to include this class as well in my
to include this class as well in my employee class. Very simple. You simply
employee class. Very simple. You simply need to write country. That's it. This
need to write country. That's it. This is an edited. Wow. But just to check
is an edited. Wow. But just to check your fundamentals, what do we need to do
your fundamentals, what do we need to do next? What we need to include the
next? What we need to include the attributes of this class as well in
attributes of this class as well in order to use it. In order to use it,
order to use it. In order to use it, very good. And how we can do that? We
very good. And how we can do that? We will simply say, and what is a better
will simply say, and what is a better way of doing it? Basically, what's the
way of doing it? Basically, what's the better of way of doing it?
better of way of doing it? uh the better way of doing it
uh the better way of doing it is using this method company do this. So
is using this method company do this. So this way first of all we need to get the
this way first of all we need to get the value from the user for the country I
value from the user for the country I will simply say country name. Okay then
will simply say country name. Okay then I will call the second parent
I will call the second parent class it the name is country I guess.
class it the name is country I guess. Yeah, country
Yeah, country dot init and then self and country name.
dot init and then self and country name. Now you should actually feel why super
Now you should actually feel why super keyword is not actually handy. If I
keyword is not actually handy. If I would use super keyword here, it would
would use super keyword here, it would be confused. Should I just make a call
be confused. Should I just make a call on this one or this one? Ideally, it is
on this one or this one? Ideally, it is not confused. It will always give
not confused. It will always give priority to the first added parent. But
priority to the first added parent. But it doesn't make any sense. It creates
it doesn't make any sense. It creates confusion when you read code, right? So
confusion when you read code, right? So this is the best way to use
this is the best way to use the class name whenever you want to just
the class name whenever you want to just make a call. Okay, very good. So this is
make a call. Okay, very good. So this is also done. This will bring all the
also done. This will bring all the attribute. This will bring all the
attribute. This will bring all the attributes. Let's say we want to create
attributes. Let's say we want to create a nice info function. Let's recreate
a nice info function. Let's recreate this
this function. Let's create it like this def
function. Let's create it like this def full info. Okay, this is very special
full info. Okay, this is very special because what we will do? We will simply
because what we will do? We will simply say the
employee and then employee name which is self dot
Okay. Employee name lives
name lives in self dot country name.
in self dot country name. Oh, so we are actually
Oh, so we are actually accessing this keyword this basically
accessing this keyword this basically attribute as well. And how? Because now
attribute as well. And how? Because now this attribute is the part of this class
this attribute is the part of this class employee as well because this is
employee as well because this is inherited using the parent class. Plus
inherited using the parent class. Plus we have also assigned the attribute
we have also assigned the attribute within this class as well. So that we
within this class as well. So that we can actually inherit and use all the
can actually inherit and use all the things. Very good. Now you are getting
things. Very good. Now you are getting all the things. Very good. lives in
all the things. Very good. lives in country
country and works
and works for self dot company name. Company name
for self dot company name. Company name or com com name I guess com name. Yeah,
or com com name I guess com name. Yeah, com
com name. Makes sense. Very good.
name. Makes sense. Very good. Now let's maybe you can say add another
Now let's maybe you can say add another function here. Okay, let me say country
function here. Okay, let me say country dot country info. Let's call this
dot country info. Let's call this function as
function as well. Perfect. Our class is ready.
well. Perfect. Our class is ready. Multiple classes ready. Just to show
Multiple classes ready. Just to show you, this is our parent class one. This
you, this is our parent class one. This is our parent class two.
is our parent class two. Okay. This is parent
Okay. This is parent one. This
one. This is parent two. And this is our child
is parent two. And this is our child class which is inheriting both the
class which is inheriting both the class. Make sense? Very good. Let's
class. Make sense? Very good. Let's actually try to run it. Okay. Okay. And
actually try to run it. Okay. Okay. And obviously we need to just give us as
obviously we need to just give us as well here. And first of all we simply
well here. And first of all we simply run this just to see the errors.
run this just to see the errors. Um it is saying self dot country name
Um it is saying self dot country name equals to country name. Where? Where?
equals to country name. Where? Where? Where? Where? Oh we added a space. No
Where? Where? Oh we added a space. No worries. Perfect. This code is fine.
worries. Perfect. This code is fine. This code is fine. Let's try
This code is fine. Let's try to run this. I want to run emp1 dot full
to run this. I want to run emp1 dot full info. Okay, let's see.
info. Okay, let's see. Wow, very good. Very very very good. Now
Wow, very good. Very very very good. Now I want to run
I want to run empfo child. Basically not company info.
empfo child. Basically not company info. This is like your all info. Let's say
This is like your all info. Let's say all info.
all info. Okay. All info child because this is
Okay. All info child because this is running from the child. Very good. So,
running from the child. Very good. So, so, so good. This is your multiple
so, so good. This is your multiple inheritance. Bang on. Very good. Now,
inheritance. Bang on. Very good. Now, finally, let's talk about multilevel
finally, let's talk about multilevel inheritance. So, basically, it should be
inheritance. So, basically, it should be clear to you, I think, because you are
clear to you, I think, because you are already wellversed with inheritance. So,
already wellversed with inheritance. So, let's say this is your company class.
let's say this is your company class. Okay, this is your company class and
Okay, this is your company class and then you have a class called department
then you have a class called department because within company we have
because within company we have departments. Okay, so this will simply
departments. Okay, so this will simply inherit this company class as well here
inherit this company class as well here like this. Then you have an employee
like this. Then you have an employee class. Let's say an employee class. So
class. Let's say an employee class. So here this time you will simply
here this time you will simply Oops. Oh man. Oh man. Let me just
Oops. Oh man. Oh man. Let me just redraw. Hm. So basically let's say this
redraw. Hm. So basically let's say this is your employee class uh sorry company
is your employee class uh sorry company class.
class. Okay very good. Then you have department
Okay very good. Then you have department class
class with company class inherited. So far
with company class inherited. So far this is just single level. Now it
this is just single level. Now it becomes multi-level
becomes multi-level because it will
because it will simply be inherited by employee as well.
simply be inherited by employee as well. Now when employee will inherit this
Now when employee will inherit this department class, it will automatically
department class, it will automatically inherit this company class as well. Wow,
inherit this company class as well. Wow, this is multi-level. This is
this is multi-level. This is multi-level. And don't worry, this is
multi-level. And don't worry, this is also very simple. Very simple. Let me
also very simple. Very simple. Let me just try to explain you how it will work
just try to explain you how it will work and how you need to work with uh
and how you need to work with uh decorators, not decorators, basically
decorators, not decorators, basically constructors because that is the most
constructors because that is the most crucial thing. So let's say this is our
crucial thing. So let's say this is our company class. This is fine. Okay. And
company class. This is fine. Okay. And for now just forget about this employee
for now just forget about this employee class. Let's first create the department
class. Let's first create the department class
class department. Okay. And within this we
department. Okay. And within this we have
df init in it and let's say
it and let's say self and department name.
self and department name. Okay. Very good. I will simply say cell
Okay. Very good. I will simply say cell dot department name
dot department name equals department
equals department name. Make
name. Make sense? Okay, very good. This is the
sense? Okay, very good. This is the simple thing. And let's create a normal
simple thing. And let's create a normal function for company
function for company name. Uh not company, department
name. Uh not company, department info. Department info. Okay, very good.
info. Department info. Okay, very good. self it will simply say
self it will simply say print the
print the department
department info
info is let's say department name self dot
is let's say department name self dot department
name okay very good make sense will it work the answer is no why because we are
work the answer is no why because we are not inheriting all the things from here
not inheriting all the things from here that means if I inher inherited this
that means if I inher inherited this department class. I will not be able to
department class. I will not be able to access company class because I'm not
access company class because I'm not inheriting all the things within this
inheriting all the things within this department class. So it's my duty to
department class. So it's my duty to inherit all the things that is company
inherit all the things that is company name. Okay. And now I need to call this
name. Okay. And now I need to call this company function as well. So company
company function as well. So company dot init. Okay. And within the self then
dot init. Okay. And within the self then company name. Make sense? Now I'm good.
company name. Make sense? Now I'm good. Now I'm good. I can even show you let's
Now I'm good. I can even show you let's say department name or let's say oh yeah
say department name or let's say oh yeah this is very good. Let's let's try this.
this is very good. Let's let's try this. This is very good. Let's say I'm
This is very good. Let's say I'm creating a function called info. Okay
creating a function called info. Okay department info. Okay department info.
department info. Okay department info. So it will simply say department is this
So it will simply say department is this one
uh com name I guess uh self.com self do comn
self.com self do comn name perfect so this is my function and
name perfect so this is my function and it is already using this value because
it is already using this value because of inheritance now we will simply
of inheritance now we will simply inherit
inherit Perfect. This is done. Now I will simply
Perfect. This is done. Now I will simply use employee class and I will inherit
use employee class and I will inherit department.
department. Wow. I will simply inherit department.
Wow. I will simply inherit department. Very good. This time this time what I
Very good. This time this time what I need to do here I will simply say
need to do here I will simply say employee name. Obviously for employee I
employee name. Obviously for employee I will simply say department
will simply say department name.
name. Okay. And then I will simply say company
Okay. And then I will simply say company name or you can say com name. Make
name or you can say com name. Make sense? So this is fine. Self dot this.
sense? So this is fine. Self dot this. Now what this is the trickiest part. Now
Now what this is the trickiest part. Now I simply need to call this function
I simply need to call this function only. That's it. Why? Because this will
only. That's it. Why? Because this will automatically call this function. See it
automatically call this function. See it is already inherited. It is already
is already inherited. It is already inherited.
inherited. But but you need to make sure that you
But but you need to make sure that you provide all the parameters here. Make
provide all the parameters here. Make sense? So I will simply say
sense? So I will simply say department dot
department dot init
init okay self and department name is your
okay self and department name is your department
department name and then company name is
name and then company name is your company name. You can even write
your company name. You can even write something like this. Okay. So this will
something like this. Okay. So this will pass this will go to this will go to
pass this will go to this will go to here automatically. Okay. Then once it
here automatically. Okay. Then once it is done that means we have access to all
is done that means we have access to all the parameters. Let's create something
the parameters. Let's create something called like this which is
info. Okay. And we need to write it like this. Indentation is important. Very
this. Indentation is important. Very good. This is my all
good. This is my all info. Now let's see if we are able to
info. Now let's see if we are able to pull this information. Okay. And we'll
pull this information. Okay. And we'll simply
simply say
employee name is self dot emp name. This will be fun.
is self dot emp name. This will be fun. Let's test it. Let's let me remove all
Let's test it. Let's let me remove all the other code.
the other code. Okay, let me remove all the other
Okay, let me remove all the other code. So now now is the thing. Let's
code. So now now is the thing. Let's test it. Let's say this is my object.
test it. Let's say this is my object. Okay, this is my object. Rahul
Okay, this is my object. Rahul department is let's say HR and the
department is let's say HR and the country um not country uh company
country um not country uh company company is let's say ABC okay let's see
company is let's say ABC okay let's see if we have any errors no errors wow I
if we have any errors no errors wow I will simply say emp1 dot all
will simply say emp1 dot all info let's see what happens perfect man
info let's see what happens perfect man perfect department is HR ABC Rahul let
perfect department is HR ABC Rahul let me try to call department info let's see
me try to call department info let's see What
happens? Very good. So what will happen here? It will simply call department
here? It will simply call department info. Okay. Here it will simply call
info. Okay. Here it will simply call department info. And obviously this
department info. And obviously this object is for employee class. See this
object is for employee class. See this object is for employee class. But this
object is for employee class. But this function is inherited because we
function is inherited because we inherited department class. Makes sense.
inherited department class. Makes sense. and all the parameters that it needs
and all the parameters that it needs such as department name, com name, we
such as department name, com name, we already inherited it here as well. See,
already inherited it here as well. See, now is the fun part. Can we call this
now is the fun part. Can we call this function company info? Yes, let's test
function company info? Yes, let's test it. Okay, let's call this
function. Perfect. Yes, we can do that because this particular
because this particular object, let's this particular object is
object, let's this particular object is of this class. We are calling this
of this class. We are calling this function because this function is part
function because this function is part of this department class and this
of this department class and this department class in is inherited here
department class in is inherited here and
and whatever attributes it needs like com
whatever attributes it needs like com name we are already passing it in the
name we are already passing it in the department name. That's why it is
department name. That's why it is important to pass all the attributes
important to pass all the attributes every time. Every time. Every time.
every time. Every time. Every time. Every time. Wow. Let me just show you
Every time. Wow. Let me just show you something else. Let's say there's a
something else. Let's say there's a scenario where we have the function with
scenario where we have the function with same name in all the classes parent to
same name in all the classes parent to children whatever. So in this particular
children whatever. So in this particular scenario let me just show you what will
scenario let me just show you what will happen. Let's say we have a function
happen. Let's say we have a function called def um show
called def um show me. Okay. And this does nothing. This
me. Okay. And this does nothing. This will simply
will simply say I am grandfather. Okay. Because this
say I am grandfather. Okay. Because this is like child's father's father. So G
is like child's father's father. So G grandfather
grandfather okay it has same function it's called
okay it has same function it's called show me which same name okay same name
show me which same name okay same name it will simply
it will simply say I am
say I am father okay and here as well it will be
father okay and here as well it will be having a function called show me it will
having a function called show me it will simply
say I am a pro okay now Now if I call this function
this function emp1 dot show me which function will be
emp1 dot show me which function will be called just tell me in the comments
called just tell me in the comments right now with a heart with a lovely
right now with a heart with a lovely heart. So it will simply call this
heart. So it will simply call this function. You can see it. See why?
function. You can see it. See why? Because it takes the priority over its
Because it takes the priority over its inherited classes.
inherited classes. Okay, this makes sense because this is a
Okay, this makes sense because this is a local function and obviously local
local function and obviously local things get priority. Let's say I don't
things get priority. Let's say I don't even have any function like this. Now I
even have any function like this. Now I have the same function in the department
have the same function in the department and in the show me as well. Now what
and in the show me as well. Now what will happen?
will happen? Okay, it will simply say I am a father.
Okay, it will simply say I am a father. Okay, why? Because the second parent
Okay, why? Because the second parent will take the priority. Okay. Now if we
will take the priority. Okay. Now if we do not have a function here as well then
do not have a function here as well then only it will say I'm grandfather. Okay.
only it will say I'm grandfather. Okay. Make sense? Very good. So this is your
Make sense? Very good. So this is your multi-level
multi-level inheritance. I hope now you know all the
inheritance. I hope now you know all the things in inheritance. I hope that this
things in inheritance. I hope that this session was really really helpful for
session was really really helpful for inheritance especially because I
inheritance especially because I genuinely written so many things that I
genuinely written so many things that I will explain this I will explain that.
will explain this I will explain that. Let me just check that I covered all the
Let me just check that I covered all the things because I want you to know all
things because I want you to know all the things and just to mention all the
the things and just to mention all the things like let's say super keyword
things like let's say super keyword those functions calling and all the
those functions calling and all the things and I hope we did it very well.
things and I hope we did it very well. Wow. Wow. Wow. Wow. Multi level is also
Wow. Wow. Wow. Wow. Multi level is also done. Okay. Makes sense. Okay. Now we
done. Okay. Makes sense. Okay. Now we can say that yeah it was a good one
can say that yeah it was a good one because this is really important this
because this is really important this particular session like inheritance is
particular session like inheritance is really really important. Make sense?
really really important. Make sense? Okay. Now we going to cover something
Okay. Now we going to cover something called as multi-threading. What is
called as multi-threading. What is multi-threading?
multi-threading? Multi-threading is the most powerful
Multi-threading is the most powerful thing that you can learn right now
thing that you can learn right now because this goes really really well
because this goes really really well with data engineering development and
with data engineering development and you will get to know why it is so much
you will get to know why it is so much powerful because I will just show you
powerful because I will just show you the examples as well. Okay, let's master
the examples as well. Okay, let's master multi-threading and after
multi-threading and after multi-threading we going to cover some
multi-threading we going to cover some amazing modules in Python such as
amazing modules in Python such as request method to work with APIs. We
request method to work with APIs. We also going to work like we we will see a
also going to work like we we will see a lot of stuff like small small stuff that
lot of stuff like small small stuff that are like really really handy. Let me
are like really really handy. Let me just show you. Let's talk about
just show you. Let's talk about multi-threading. What is
multi-threading. What is multi-threading? What is
multi-threading? What is multi-threading? Basically, let's say
multi-threading? Basically, let's say you have your program. Let's say you
you have your program. Let's say you have a function. Okay, you have a
have a function. Okay, you have a function. Okay, now you want to run this
function. Okay, now you want to run this function multiple times. Let's say you
function multiple times. Let's say you want to run your function 10 times. You
want to run your function 10 times. You will simply say, hey, now I'm a pro. I
will simply say, hey, now I'm a pro. I know how to use loop. So I can simply
know how to use loop. So I can simply use a loop for loop and I can simply run
use a loop for loop and I can simply run this
this function through a loop. Yes, you are
function through a loop. Yes, you are right. But the issue is that loop will
right. But the issue is that loop will run in sequence. That means that loop
run in sequence. That means that loop will first complete your first iteration
will first complete your first iteration then it will go to the second then it
then it will go to the second then it will go to the third then it will go to
will go to the third then it will go to the fourth then so on till 10th. Yeah.
the fourth then so on till 10th. Yeah. So what's wrong with this? Nothing is
So what's wrong with this? Nothing is wrong in this. But what if you want to
wrong in this. But what if you want to process all the 10 iterations
process all the 10 iterations together parallelly? Yes, parallelly.
together parallelly? Yes, parallelly. What if you want to do something like
What if you want to do something like this? That's where multi-threading comes
this? That's where multi-threading comes into the picture. It actually creates
multi-threads so that you can process your data
your data simultaneously. So you can actually run
simultaneously. So you can actually run your data or let's say um let's not talk
your data or let's say um let's not talk about data like normally you can just
about data like normally you can just run your program parallelly. You do not
run your program parallelly. You do not need to wait for the previous one to
need to wait for the previous one to complete and then start the second one.
complete and then start the second one. This is the power of
This is the power of multi-threading. A good example in data
multi-threading. A good example in data engineing domain let's say you are just
engineing domain let's say you are just writing your spark application. Okay.
writing your spark application. Okay. Now you want to let's say you are just
Now you want to let's say you are just building a datab bricks notebook. Okay.
building a datab bricks notebook. Okay. in which you're writing your pispar
in which you're writing your pispar code, you want to perform the same
code, you want to perform the same things, all the same things for
things, all the same things for different different tables, all the same
different different tables, all the same things. So if you just want to let's say
things. So if you just want to let's say run it through loop. So first your first
run it through loop. So first your first data will be loaded then second then
data will be loaded then second then third then fourth let's say you have 100
third then fourth let's say you have 100 tables you'll be just waiting for your
tables you'll be just waiting for your all the 99 tables to be completed to
all the 99 tables to be completed to just complete the last one. What if I
just complete the last one. What if I say just run all the applications
say just run all the applications together? So just imagine the
together? So just imagine the speed almost 100 times faster right
speed almost 100 times faster right that's where multi-threading comes into
that's where multi-threading comes into the picture and it becomes really really
the picture and it becomes really really handy for data engineers. So now it's
handy for data engineers. So now it's time to look at the code so that you can
time to look at the code so that you can actually understand what we are going to
actually understand what we are going to do. So let me clear all these
do. So let me clear all these inheritance and all. Okay let's talk
inheritance and all. Okay let's talk about multi-threading. Okay makes sense.
about multi-threading. Okay makes sense. So basically let's create a function and
So basically let's create a function and even before creating a function we need
even before creating a function we need to import some modules just to show you
to import some modules just to show you the results. So I will simply import
the results. So I will simply import times. I will import um
uh random and then I need to import from
random and then I need to import from futures dotconcurrent I
guess. import thread pool
exeutor. Okay let's run this. Let's see if all the modules are right. No named
if all the modules are right. No named No module named called futures. Maybe
No module named called futures. Maybe from
from future. No module named called future.
future. No module named called future. Wow. So I think let me just see what is
Wow. So I think let me just see what is the exact module
name concurrent. Futures not future.concurrent. Okay. From
concurrent.futures import threadpool executor. Make sense? Now we are good to
executor. Make sense? Now we are good to go. Let's say first of all I will just
go. Let's say first of all I will just show you the traditional approach that
show you the traditional approach that you do without thread pool executor or
you do without thread pool executor or let's say without multi-threading.
let's say without multi-threading. Threadpool exeutor is the module that is
Threadpool exeutor is the module that is the best if you just want to perform
the best if you just want to perform multi-threading. Okay, there are many
multi-threading. Okay, there are many but this is the best one. So let's say
but this is the best one. So let's say you have a function df my function.
you have a function df my function. Okay. Then within this function
Okay. Then within this function obviously takes a parameter let's say
obviously takes a parameter let's say px.
px. Okay. Px. Okay. What it does? It will
Okay. Px. Okay. What it does? It will basically print
basically print um I am px just to see like what value
um I am px just to see like what value it is getting. Okay. I am
it is getting. Okay. I am px I
px I took how many seconds? I will just talk
took how many seconds? I will just talk about this. So basically we going to use
about this. So basically we going to use something called as time function
something called as time function because we will be using something
because we will be using something called as time dots
called as time dots sleep okay because we this function is
sleep okay because we this function is so quick that it will not actually show
so quick that it will not actually show you the difference. So that you can
you the difference. So that you can actually see the difference we will
actually see the difference we will simply use time dots sleep method and
simply use time dots sleep method and what we can just use in sleep method you
what we can just use in sleep method you can simply say 2 seconds 4 seconds 3
can simply say 2 seconds 4 seconds 3 seconds. So this is a very good module
seconds. So this is a very good module that you can just discover. You can
that you can just discover. You can simply say time module or let's say time
simply say time module or let's say time dot
sleep time do sleep method and in which you can simply say time dots sleep if
you can simply say time dots sleep if you just want your system or let's say
you just want your system or let's say program to sleep for 6 seconds you can
program to sleep for 6 seconds you can simply say time do sleep 6 that's it so
simply say time do sleep 6 that's it so now I don't want to give the fixed value
now I don't want to give the fixed value no I want to give random value I will
no I want to give random value I will simply say random
simply say random dotrandant and I will simply pick random
dotrandant and I will simply pick random value between 1 to 10. Okay, this is the
value between 1 to 10. Okay, this is the function that we use to provide random
function that we use to provide random value. Make sense? Very good. This is
value. Make sense? Very good. This is the function. That's it. If I want to
the function. That's it. If I want to run this function, okay, I will simply
run this function, okay, I will simply call
call it my function. Okay, and then I will
it my function. Okay, and then I will simply say let's say um 101. Okay, what
simply say let's say um 101. Okay, what it will do? It will throw an error. Uh
it will do? It will throw an error. Uh oh, it's
oh, it's rand. I just did a typo. So IM101 I
rand. I just did a typo. So IM101 I took I need to just write this as well.
took I need to just write this as well. I will simply make a variable called
I will simply make a variable called weight. I
weight. I took weight
seconds. Make sense? So why it is taking now long? Because it is performing sleep
now long? Because it is performing sleep operation. Okay. Let me just run for one
operation. Okay. Let me just run for one more time.
Okay. So what is happening here? It is simply performing some sleep. But if I
simply performing some sleep. But if I just want to get the value of sleep, if
just want to get the value of sleep, if I just want to see like how long it
I just want to see like how long it took, I need to just use something else
took, I need to just use something else so that I can show you how long it is
so that I can show you how long it is taking. So for that what you can do, you
taking. So for that what you can do, you can simply I will first store this value
can simply I will first store this value in the variable. Okay, like this.
in the variable. Okay, like this. Okay, then I will pass this value here
Okay, then I will pass this value here which is
which is weight because this way I can even store
weight because this way I can even store this value here. Let me just run this so
this value here. Let me just run this so you will actually see how long it is
you will actually see how long it is taking to sleep. So this time it is it
taking to sleep. So this time it is it took 5 seconds.
took 5 seconds. Okay, let me run it again. So this time
Okay, let me run it again. So this time it took 2 seconds. So basically what is
it took 2 seconds. So basically what is the purpose of this? Let's say you are
the purpose of this? Let's say you are processing your data. Okay, sometimes
processing your data. Okay, sometimes your data can take 5 seconds.
your data can take 5 seconds. Second table is taking 2 seconds. Third
Second table is taking 2 seconds. Third table is taking 10 seconds. Fourth table
table is taking 10 seconds. Fourth table is taking let's say 6 seconds. So this
is taking let's say 6 seconds. So this way every table's data size will be
way every table's data size will be different. Right? So I am just creating
different. Right? So I am just creating that environment so that you can
that environment so that you can actually feel that you are processing
actually feel that you are processing the data. Okay, make sense? Very good.
the data. Okay, make sense? Very good. Now let me just give you the table
Now let me just give you the table names. Okay, let's create a list. I will
names. Okay, let's create a list. I will simply say tables and let's create let's
simply say tables and let's create let's say
say orders
orders products okay
products okay customers then um let's say uh reviews
customers then um let's say uh reviews and then one more let's say
and then one more let's say cancellations or cancels okay make sense
cancellations or cancels okay make sense now if I want to process my data without
now if I want to process my data without multi-threading what I will do I will
multi-threading what I will do I will simply say for i in tables
simply say for i in tables Okay.
Okay. Then simply
Then simply oops. What is
oops. What is this? Yeah. So simply pass this
this? Yeah. So simply pass this particular parameter through loop.
particular parameter through loop. Through loop. So now what will happen?
Through loop. So now what will happen? Let me just show you what will happen.
Let me just show you what will happen. This time we need to simply run this
This time we need to simply run this function through a loop. Okay. So how we
function through a loop. Okay. So how we can just do that? Obviously first we
can just do that? Obviously first we need to define this function outside the
need to define this function outside the loop like this. Okay, like this. And
loop like this. Okay, like this. And simply we'll call this function one by
simply we'll call this function one by one. Okay, we'll simply say uh my
one. Okay, we'll simply say uh my function
function and one time it will take orders then
and one time it will take orders then products then customers then reviews can
products then customers then reviews can then cancels. Make sure that you are
then cancels. Make sure that you are having that wipe that in the real world
having that wipe that in the real world you will be having hundreds of tables.
you will be having hundreds of tables. Okay, very good. Now let's run this. Now
Okay, very good. Now let's run this. Now let's see what will happen. We do not
let's see what will happen. We do not know which table will process first.
know which table will process first. Okay, obviously it will be orders. But
Okay, obviously it will be orders. But yeah, I'm just telling you. So px is not
yeah, I'm just telling you. So px is not defined. Obviously this is not px. This
defined. Obviously this is not px. This is
is I. Okay, so now we are not using
I. Okay, so now we are not using multi-threading. What it will do? It
multi-threading. What it will do? It will simply first of all process orders.
will simply first of all process orders. It can take any much time. Then
It can take any much time. Then products, then customers. Oh sorry,
products, then customers. Oh sorry, orders, products, customers, reviews,
orders, products, customers, reviews, cancels. Let's run this. And it depends
cancels. Let's run this. And it depends upon the data size. Okay. Orders table
upon the data size. Okay. Orders table took 3 seconds. Now let's next table
took 3 seconds. Now let's next table took 3 seconds. Wow. Next table it
took 3 seconds. Wow. Next table it took it
took it took 8 seconds. Wow. Next
took 8 seconds. Wow. Next table it
took quick. It took 10 seconds. Wo. Now the
quick. It took 10 seconds. Wo. Now the last table
last table cancels
took 8 seconds. Perfect. So did you see what is the issue? Let's say I have
what is the issue? Let's say I have hundreds of tables. I need to wait for
hundreds of tables. I need to wait for first table to to complete then second
first table to to complete then second then third then fourth. I do not want to
then third then fourth. I do not want to do that. I cannot do that. It is not
do that. I cannot do that. It is not ideal. So instead what I want to do I
ideal. So instead what I want to do I want to process all the tables together
want to process all the tables together in parallel. Now what I will do this is
in parallel. Now what I will do this is my function. Okay this will be remaining
my function. Okay this will be remaining the same. This will remain the same. I
the same. This will remain the same. I will remove this loop because I do not
will remove this loop because I do not need loop. Loops are slow. We will use
need loop. Loops are slow. We will use multi-threading. How we can just use
multi-threading. How we can just use multi- threading? So we will use
multi- threading? So we will use something called as
something called as with thread pool executor. Okay. with
with thread pool executor. Okay. with thread pool executor. Now you need to
thread pool executor. Now you need to say maximum
say maximum executors. Let me just see the syntax so
executors. Let me just see the syntax so that I do not make any mistake. Um yeah
that I do not make any mistake. Um yeah so max
so max workers now this is critical max workers
workers now this is critical max workers you need to pick as per the length of
you need to pick as per the length of this particular list. Okay you can
this particular list. Okay you can simply say length of tables. Why?
simply say length of tables. Why? Because you
Because you need all the workers to working on the
need all the workers to working on the individual item, right? So this will
individual item, right? So this will basically create the workers for you. It
basically create the workers for you. It will create workers. How many workers do
will create workers. How many workers do you need? Simple. The number of tables
you need? Simple. The number of tables that you have so that you can
that you have so that you can individually individually run that and
individually individually run that and all will be running parallelly. Okay. So
all will be running parallelly. Okay. So max workers as this and then you can
max workers as this and then you can simply let me check the braces. Max
simply let me check the braces. Max workers this uh this as
workers this uh this as executor as executor if I am right. Yeah
executor as executor if I am right. Yeah perfect. So now you have created the
perfect. So now you have created the executors equals to five because we have
executors equals to five because we have five tables. If you have 100 it will it
five tables. If you have 100 it will it will create 100. Now what we need to do
will create 100. Now what we need to do we will simply create futures. We will
we will simply create futures. We will simply create futures.
information, ID, password, everything. Then it will simply bring back the data
Then it will simply bring back the data and you will receive the data back in
and you will receive the data back in the form of a response. That is the
the form of a response. That is the highle architecture of request module
highle architecture of request module that we get. Basically, we simply use
that we get. Basically, we simply use this API. API is the middleman between
this API. API is the middleman between you and the application from where
you and the application from where you're trying to fetch the data. Make
you're trying to fetch the data. Make sense? So we simply say hey API just go
sense? So we simply say hey API just go there and bring the data for us. It goes
there and bring the data for us. It goes there. It simply shares all the
there. It simply shares all the information with the application that
information with the application that you are the guy. These are your
you are the guy. These are your credentials. Can I take the data?
credentials. Can I take the data? Application will say yeah you can. Then
Application will say yeah you can. Then it will simply bring the data and it
it will simply bring the data and it will deliver the data to you. So that
will deliver the data to you. So that you cannot directly connect to the
you cannot directly connect to the application. You do it via API. You do
application. You do it via API. You do it via API. So request module is used
it via API. So request module is used for that particular purpose. Let's try
for that particular purpose. Let's try to make some API calls to the u publicly
to make some API calls to the u publicly available API endpoints. And let me just
available API endpoints. And let me just show you how you can just work with
show you how you can just work with APIs. Just a highle understanding
APIs. Just a highle understanding because it is totally a different
because it is totally a different concept when you work with APIs. In web
concept when you work with APIs. In web development, in app development, web
development, in app development, web development, you work more with APIs.
development, you work more with APIs. But being a data engineer, you should
But being a data engineer, you should know the some basic stuff of it. Okay,
know the some basic stuff of it. Okay, let me just show you because every API
let me just show you because every API is unique. It totally depends upon the
is unique. It totally depends upon the application developer or you can say the
application developer or you can say the team who has designed the API. So every
team who has designed the API. So every time you need to follow different
time you need to follow different different rules. So that is why it is
different rules. So that is why it is not a kind of generic rules for you as a
not a kind of generic rules for you as a data engineer. Every time you need to go
data engineer. Every time you need to go through the documentation that
through the documentation that application developers provide. Okay.
application developers provide. Okay. But let me show you how you can just
But let me show you how you can just perform some um you can say API calls,
perform some um you can say API calls, get API calls to simply fetch the data.
get API calls to simply fetch the data. Let me show you. So we going to use this
Let me show you. So we going to use this publicly available API and you can even
publicly available API and you can even just copy paste it. Let me just show
just copy paste it. Let me just show you. So it is saying like this. Okay.
you. So it is saying like this. Okay. And you can simply type it. It's not a
And you can simply type it. It's not a big URL. Okay. So let me just try to get
big URL. Okay. So let me just try to get this data. So basically this is a
this data. So basically this is a response when I hit this endpoint. So I
response when I hit this endpoint. So I need to get this data which is like user
need to get this data which is like user ID, ID, title and body. Okay, make
ID, ID, title and body. Okay, make sense? So obviously we can just use API
sense? So obviously we can just use API module which is request method. I will
module which is request method. I will simply import it. The thing is uh
simply import it. The thing is uh request module is not supportable by all
request module is not supportable by all the online compiler. So I'm not sure it
the online compiler. So I'm not sure it will work or not but we can simply test
will work or not but we can simply test it. We can simply run it. See no named
it. We can simply run it. See no named module request because sometime they
module request because sometime they have not updated the compilers. No
have not updated the compilers. No worries we can simply go to a different
worries we can simply go to a different compiler. I can simply say online python
compiler. I can simply say online python compiler and let's try this GDB one.
compiler and let's try this GDB one. Okay this GDB one. Okay makes sense. So
Okay this GDB one. Okay makes sense. So we can use this compiler for API calls.
we can use this compiler for API calls. No worries. I will simply say import
No worries. I will simply say import requests
requests requests. Okay, let me just run this
requests. Okay, let me just run this just to make sure it is running fine.
just to make sure it is running fine. Oh, it is running fine. Very good. We
Oh, it is running fine. Very good. We can use this. So now what we will do? We
can use this. So now what we will do? We will simply first of all fetch the URL.
will simply first of all fetch the URL. URL is this one. Okay, let me just copy
URL is this one. Okay, let me just copy and paste it. And here I will simply use
and paste it. And here I will simply use response equals
requests dot get requests dot get. So get method is the method that we use to
get method is the method that we use to fetch the data. Then I will simply pass
fetch the data. Then I will simply pass the URL. That's it. Let me just run
the URL. That's it. Let me just run this. Perfect. So we can easily make
this. Perfect. So we can easily make this API call to this particular URL.
this API call to this particular URL. Okay. Now we have some status codes
Okay. Now we have some status codes available in API. The success status
available in API. The success status code is popularly known as 200. If we
code is popularly known as 200. If we have any error we see 404. So similarly
have any error we see 404. So similarly we have so many status codes. Let's see
we have so many status codes. Let's see the status code for this one. I will
the status code for this one. I will simply say
simply say print response dot
status. Okay. We do not have any
Okay. We do not have any status. Response is not defined. Res
status. Response is not defined. Res response
response response response response
response response response response response object has no object
response response object has no object status. Maybe it will be having status
status. Maybe it will be having status code. Yep. Let's see. Okay, perfect. It
code. Yep. Let's see. Okay, perfect. It has status code 200. That means it is
has status code 200. That means it is successfully able to connect to that
successfully able to connect to that particular endpoint. Very good. That's
particular endpoint. Very good. That's what we want. Now I will just show you
what we want. Now I will just show you the data. What response did we get? We
the data. What response did we get? We resp we get response
resp we get response as print
as print response. So this is the response. This
response. So this is the response. This is the response. You will say there's
is the response. You will say there's nothing inside it. Yes, we will not get
nothing inside it. Yes, we will not get the data directly in response. Just to
the data directly in response. Just to convert or you can say just to fetch the
convert or you can say just to fetch the data from this response. We use
data from this response. We use something called as data variable equals
something called as data variable equals response dot JSON. If the result is in
response dot JSON. If the result is in the JSON format and we can see that it
the JSON format and we can see that it is in the JSON format, most of the API
is in the JSON format, most of the API calls will return the response in JSON
calls will return the response in JSON format. Now I can simply print this
format. Now I can simply print this data. Wow, this is the data that we got.
data. Wow, this is the data that we got. User ID, ID, title and everything. This
User ID, ID, title and everything. This is the way to make API calls to the API
is the way to make API calls to the API endpoint or basically to any URL using
endpoint or basically to any URL using requests.get get
requests.get get method. It is very handy. You can even
method. It is very handy. You can even work with status code. You can even work
work with status code. You can even work with data. You can even fetch directly
with data. You can even fetch directly the data. Once you have the data, you
the data. Once you have the data, you can even write the data as
can even write the data as well. You can even write the
well. You can even write the data. Make sense? Makes sense. Makes
data. Make sense? Makes sense. Makes sense. Okay. Very very very good. So
sense. Okay. Very very very good. So this was all about your request method.
this was all about your request method. Now I'm so sure that you are so so so
Now I'm so sure that you are so so so experienced and you have gained amazing
experienced and you have gained amazing skills in
skills in Python. Yes, there are so many other
Python. Yes, there are so many other things as well in Python that you can
things as well in Python that you can explore. Yes, there are so many modules
explore. Yes, there are so many modules in Python that that you can explore.
in Python that that you can explore. Yes, there are a lot of stuff because
Yes, there are a lot of stuff because Python is widely used. But I can say
Python is widely used. But I can say once you have completed this video, once
once you have completed this video, once you have completed all the areas that I
you have completed all the areas that I have mentioned in this video, you are
have mentioned in this video, you are wellversed with Python now you can
wellversed with Python now you can understand any new concept plus you can
understand any new concept plus you can even go deeper inside any existing
even go deeper inside any existing concept. Make sense? You can master any
concept. Make sense? You can master any module now because you have built a
module now because you have built a strong
strong base. Make sense? You are not a Python
base. Make sense? You are not a Python developer. You are not a web developer.
developer. You are not a web developer. You are a data engineer. You need to use
You are a data engineer. You need to use Python. Make sense? You need to
Python. Make sense? You need to selectively use modules. You need to
selectively use modules. You need to selectively combine your data with the
selectively combine your data with the modules. That's
modules. That's it. But yes, some things are common in
it. But yes, some things are common in all the things that are like classes,
all the things that are like classes, inheritance, um you can say functions,
inheritance, um you can say functions, all those things, multi-threading. Now
all those things, multi-threading. Now you are wellvered with all those things.
you are wellvered with all those things. Make
Make sense? So we
sense? So we have a very good module which is OS
have a very good module which is OS module. By the way, OS module will only
module. By the way, OS module will only be working with your local machine
be working with your local machine because obviously you need to just work
because obviously you need to just work with files. But we do not work much with
with files. But we do not work much with OS module as a data engineer. We work
OS module as a data engineer. We work with some alternatives such as DB utils
with some alternatives such as DB utils which is datab bricks utilities,
which is datab bricks utilities, notebook utils that are developed by
notebook utils that are developed by Azure notebook utils. But yes, you
Azure notebook utils. But yes, you should have some basic understanding of
should have some basic understanding of the OS module. Basically, let me just
the OS module. Basically, let me just talk a little bit about OS module. Okay,
talk a little bit about OS module. Okay, let's go here. I love this UI truly
let's go here. I love this UI truly speaking. Okay, let me just talk about
speaking. Okay, let me just talk about OS module a little bit and then I will
OS module a little bit and then I will just provide you some resources that you
just provide you some resources that you can explore because there's not any kind
can explore because there's not any kind of logic behind it. It's very simple. So
of logic behind it. It's very simple. So basically we can simply say import OS.
basically we can simply say import OS. Okay, let me simply run
Okay, let me simply run it. A module you have imported isn't
it. A module you have imported isn't available at the moment obviously
available at the moment obviously because this is just a online compiler
because this is just a online compiler you need like real machine, real
you need like real machine, real folders, real storage. Okay. But still I
folders, real storage. Okay. But still I will try my best to explain you some
will try my best to explain you some basic stuff that you can then you can
basic stuff that you can then you can just refer the documentation that I will
just refer the documentation that I will just show you. Basically OS module
just show you. Basically OS module stands for like operating system module
stands for like operating system module in which you can actually perform a lot
in which you can actually perform a lot of stuff. For example, you want to
of stuff. For example, you want to create a folder. You want to create a
create a folder. You want to create a folder. You can write things similar
folder. You can write things similar like OS dot make directories and then
like OS dot make directories and then you can simply provide the path any
you can simply provide the path any path. Okay. path of your local machine
path. Okay. path of your local machine like local C users your name and then
like local C users your name and then folder let's say you want to create um
folder let's say you want to create um or let's say remove the folders you can
or let's say remove the folders you can do that you can simply say rm diir s
do that you can simply say rm diir s there are like so many modules I will
there are like so many modules I will just show you there are so many
just show you there are so many functions then let's say you want to
functions then let's say you want to dynamically fetch the location or
dynamically fetch the location or basically absolute path of the python
basically absolute path of the python file that you are running you can simply
file that you are running you can simply perform something like this
perform something like this os.pathabs path and you can simply write
os.pathabs path and you can simply write something like
something like this.
this. Oops like this. So it will give you the
Oops like this. So it will give you the absolute path. Basically this module is
absolute path. Basically this module is used when you are making some file
used when you are making some file management but I know we data engineers
management but I know we data engineers work directly with the cloud storage
work directly with the cloud storage Azure AWS GCP that's why we use cloud
Azure AWS GCP that's why we use cloud utilities but yes you should also know
utilities but yes you should also know about operating system of Python as well
about operating system of Python as well because both are interlin if you
because both are interlin if you understand DB utils it will be a piece
understand DB utils it will be a piece of cake for you if you know OS DB utils
of cake for you if you know OS DB utils will be a piece of cake for you now it's
will be a piece of cake for you now it's the best time to just show you the OS
the best time to just show you the OS module. So it you can you can simply say
module. So it you can you can simply say Python OS
Python OS module. Okay. And let's try to see like
module. Okay. And let's try to see like Python OS module. So you can see there
Python OS module. So you can see there are so many functions and you can even
are so many functions and you can even go through this documentation. Okay. You
go through this documentation. Okay. You can see there are so many stuff OS
can see there are so many stuff OS objects OS things. You can even just
objects OS things. You can even just refer official documentation as well.
refer official documentation as well. So it is nothing but just a file
So it is nothing but just a file management. That's it. That's it. See it
management. That's it. That's it. See it has like so many classes fs.path so many
has like so many classes fs.path so many stuff. Get environment all these things.
stuff. Get environment all these things. If you have like environment variables.
If you have like environment variables. So these things are like much more used
So these things are like much more used at the time of
at the time of deployment. Okay. Make
deployment. Okay. Make sense? Makes sense. But still I will
sense? Makes sense. But still I will recommend you to just go through these
recommend you to just go through these documentation examples. See this is
documentation examples. See this is simply saying os.get cwd. This is
simply saying os.get cwd. This is basically the current working directory.
basically the current working directory. You will simply get like this. So this
You will simply get like this. So this is a very good example. Let me just give
is a very good example. Let me just give you a quick overview. Let's say you just
you a quick overview. Let's say you just want to get the current working
want to get the current working directory of your file. You will simply
directory of your file. You will simply run like this and you will get the
run like this and you will get the output like this. Wow. Let's say you
output like this. Wow. Let's say you want to
want to uh create the folder. So you can simply
uh create the folder. So you can simply use os.make directories. I just showed
use os.make directories. I just showed you. Okay. So you can simply create
you. Okay. So you can simply create directory like this. And this is the
directory like this. And this is the code for you. Nothing. You just need to
code for you. Nothing. You just need to define the parameters, paths. That's it.
define the parameters, paths. That's it. That's it. Then let's say you want to
That's it. Then let's say you want to list all the files and directories
list all the files and directories within the folder you are working with.
within the folder you are working with. You can simply say something called as
You can simply say something called as os.list directory. What it will do? It
os.list directory. What it will do? It will simply give all the folders all the
will simply give all the folders all the things within the folder. It is just a
things within the folder. It is just a file management thing that you can do as
file management thing that you can do as a data engineer. Make sense? So you can
a data engineer. Make sense? So you can simply go through the documentation.
simply go through the documentation. These are important. Yes, not very
These are important. Yes, not very important because you can get started
important because you can get started with these modules directly on the cloud
with these modules directly on the cloud as well. Okay. So, it's up to you how
as well. Okay. So, it's up to you how you want to get started. But I would
you want to get started. But I would recommend you to get started with this.
recommend you to get started with this. That is all about your Python for data
That is all about your Python for data engineering master class. I hope I
engineering master class. I hope I covered all those things which are very
covered all those things which are very very important because I wanted to make
very important because I wanted to make sure that I will cover all the
sure that I will cover all the non-negotiables.
non-negotiables. I know there are much more important
I know there are much more important stuff as well but these are your
stuff as well but these are your non-negotiables. That was the agenda of
non-negotiables. That was the agenda of this video as well so that you will
this video as well so that you will cover all the important stuff for data
cover all the important stuff for data engineers. Make sure that you are
engineers. Make sure that you are covering all the things with deep
covering all the things with deep knowledge. Okay, I hope you like this
knowledge. Okay, I hope you like this video. I hope you loved this video. On
video. I hope you loved this video. On my channel you have everything that you
my channel you have everything that you need to become a data engineer. So just
need to become a data engineer. So just go on my channel. Okay, just watch any
go on my channel. Okay, just watch any video because every video is covered
video because every video is covered from scratch. Just master any technology
from scratch. Just master any technology and you will become an efficient data
and you will become an efficient data engineer. Trust me. Okay. So just click
engineer. Trust me. Okay. So just click on the video that is appearing on the
on the video that is appearing on the screen and I will see you
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.