Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,070 --> 00:00:05,910
I'm going to talk about the focus of our course
mastering Python for beginners in data science.
2
00:00:05,910 --> 00:00:13,769
So let me explain what kind of areas in this
particular course we are focusing the most.
3
00:00:13,769 --> 00:00:20,420
In fact, because this is a course, for beginners,
that's a beginner level course, we are not
4
00:00:20,420 --> 00:00:29,580
assuming the the course taker to have any
experience whatsoever about any computer programming
5
00:00:29,580 --> 00:00:35,960
language before, not even not even the problem,
problem solving paradigm that lies in computer
6
00:00:35,960 --> 00:00:43,360
science. So, we will, we will focus on problem
solving for a bit. And we will actually start
7
00:00:43,360 --> 00:00:49,260
from the very beginning what problem solving
is, particularly in computer science. The
8
00:00:49,260 --> 00:00:55,890
second focus of this particular course, is
mainly telling you why we are choosing Python,
9
00:00:55,890 --> 00:01:02,059
why Python is so important, particularly for
data science problems. The third focus and
10
00:01:02,059 --> 00:01:10,040
the main core focus is to learn Python, obviously,
once we know what is what what are the techniques
11
00:01:10,040 --> 00:01:15,221
to solve a problem. And once we know that
Python might be a very good language to go
12
00:01:15,221 --> 00:01:21,650
with, then what is Python, how to learn it?
Well, the Python is the main core and main
13
00:01:21,650 --> 00:01:27,880
focus of this course, obviously, we will start
from the very beginning, very, very beginning,
14
00:01:27,880 --> 00:01:33,130
which means we will start from how to install
Python for example, we will start from there,
15
00:01:33,130 --> 00:01:39,829
and then we will see what are variables, I
mean, very, very beginning, and then progressively
16
00:01:39,829 --> 00:01:45,621
we will be moving on and on and on to data
structures to complex structures, but that
17
00:01:45,621 --> 00:01:52,210
transition from 02 onwards, that transition
will be very, very smooth. I mean, whatever
18
00:01:52,210 --> 00:01:57,070
you know, so far, in the course, that will
be helping you to gain more complex structures
19
00:01:57,070 --> 00:02:01,750
very, very easily getting the understanding
of a lot of structures very, very easily.
20
00:02:01,750 --> 00:02:11,850
So in this Python, we will include all concepts
of Python in general. And, and one more thing,
21
00:02:11,850 --> 00:02:17,420
after I mean learning, despite on the way
we the way we organize this course of learning
22
00:02:17,420 --> 00:02:23,550
this Python, you will be having an understanding
of other languages as well. I mean, the contents
23
00:02:23,550 --> 00:02:30,010
here are explained in so general way all over
the Python syntax, but the general but but
24
00:02:30,010 --> 00:02:34,540
but the concepts are expressed in so general
way, the problems that we picked to solve
25
00:02:34,540 --> 00:02:40,090
for practice are so generic that you will
after this particular Python course, you will
26
00:02:40,090 --> 00:02:47,470
be having understanding of programming languages
in general. So data science is one other focus
27
00:02:47,470 --> 00:02:56,690
of this course, actually, the whole course
is organized in a way that it teaches you
28
00:02:56,690 --> 00:03:02,800
about Python, it teaches you problem solving,
it teaches you something about overall programming
29
00:03:02,800 --> 00:03:08,350
languages and how computer can be used to
achieve the solution of different problems.
30
00:03:08,350 --> 00:03:14,040
And and using Python, of course, and then
we will be introducing the data science packages
31
00:03:14,040 --> 00:03:19,110
that are available in Python, because they
are really, really fast, really fundamental,
32
00:03:19,110 --> 00:03:24,380
very easy to use, and very, very powerful
to handle large amount of data very quickly
33
00:03:24,380 --> 00:03:30,430
for data understanding for visualization,
for cleaning, processing, and a lot of stuff,
34
00:03:30,430 --> 00:03:36,040
what we are not focusing at because that's
important. Knowing that what kind of things
35
00:03:36,040 --> 00:03:41,960
are are are the things that we are not covering,
for example, we are not covering object oriented
36
00:03:41,960 --> 00:03:47,250
programming, we are not covering exception
handling, we are not doing web development,
37
00:03:47,250 --> 00:03:54,460
or any general kind of tasks that are doable
in Python, we are not focusing on those things.
38
00:03:54,460 --> 00:04:01,100
Everybody solves different problems every
day. Some problems are easy to solve, and
39
00:04:01,100 --> 00:04:10,040
some are difficult. And yet some are impossible
to solve. They are called unsolvable problems.
40
00:04:10,040 --> 00:04:14,940
But think about different instances of the
same problem one needs to solve again and
41
00:04:14,940 --> 00:04:23,970
again. For example, sorting the sale records.
And let's say we are sorting the sale records
42
00:04:23,970 --> 00:04:31,120
with respect to the sale value. And we have
to do it after every eight hours. If the number
43
00:04:31,120 --> 00:04:38,720
of instances if that number is huge, the optimal
choice is to automate the solution if the
44
00:04:38,720 --> 00:04:46,930
automation is possible, but how how to come
up with the automated solution to come up
45
00:04:46,930 --> 00:04:54,170
with a general solution that works for every
instance of some problem. That is one thing.
46
00:04:54,170 --> 00:05:00,800
But to get that solution running on a computer
is yet another thing
47
00:05:00,800 --> 00:05:09,340
Problem Solving deals with formalizing a general
solution for that works for every instance.
48
00:05:09,340 --> 00:05:19,320
And programming languages, like Python deals
with the running of that solution on a computer.
49
00:05:19,320 --> 00:05:28,370
Python, as, as we will see, makes the transition
from problem solving to the running solution
50
00:05:28,370 --> 00:05:38,280
much easier and quicker. And that's one big
plus of Python. A lot of words, I know a lot
51
00:05:38,280 --> 00:05:45,990
of words. Let me take an example to clarify
what I said, Hold on till the end of this
52
00:05:45,990 --> 00:05:53,280
video. And I will make everything what I said
so far, crystal clear. So let's take an example.
53
00:05:53,280 --> 00:05:59,940
Let's dive into an example to see what I just
said. Let's say your a, and your friend is
54
00:05:59,940 --> 00:06:10,870
B. And your friend B is always willing to
help you. Let's say you found such a friend.
55
00:06:10,870 --> 00:06:22,930
And then a just said, I want off just for
some days. But be said, but what ghobadi enjoy.
56
00:06:22,930 --> 00:06:33,820
He said, someone have to do my job in my absence.
And then be said, That's it? Is that your
57
00:06:33,820 --> 00:06:39,840
problem? I'm available? As always go buddy,
enjoy. Man. He said, great. You're a true
58
00:06:39,840 --> 00:06:50,300
friend. Okay, I'm leaving, wow. And be just
said, Hey, wait, what do I have to do? What's
59
00:06:50,300 --> 00:06:55,150
your job? At the end of the day, I'm going
to do your job. What's your job? What do you
60
00:06:55,150 --> 00:07:03,710
do? And then he said, after every eight hours,
pick the email of the customer when the maximum
61
00:07:03,710 --> 00:07:11,330
sales. So that's what you have to do. He said,
Okay. But from there, I mean, I have to pick
62
00:07:11,330 --> 00:07:17,490
that email of the customer from where, where
are the records? He said, Well, there are
63
00:07:17,490 --> 00:07:22,460
sales records. I mean, at the job place, there
are sales records. And you have to pick the
64
00:07:22,460 --> 00:07:29,110
email of the customer with maximum sales.
We said, Oh, okay. But wait, what, what should
65
00:07:29,110 --> 00:07:36,830
I do with the email that I just picked? Then
he said, oh, there is an other record called
66
00:07:36,830 --> 00:07:42,790
priority records, just write that email after
eight hours, just write that email in purity
67
00:07:42,790 --> 00:07:50,790
records. And then be said, that's it. That's
all your job. And he said, after so relaxed,
68
00:07:50,790 --> 00:08:01,060
he said, Yes, that's my job. That's all. No,
think he leaves and later that day receives
69
00:08:01,060 --> 00:08:10,560
a call from B. And B said, I don't really
know what to do. Can you tell me step by step?
70
00:08:10,560 --> 00:08:19,500
What to do? Focus on again, I'm reading this
particular sentence again. Can you tell me
71
00:08:19,500 --> 00:08:27,870
step by step what to do? I have sales records
with me having all the records for the last
72
00:08:27,870 --> 00:08:34,940
eight hours, what to do, I just messed everything
up. I don't know what to do. And then at the
73
00:08:34,940 --> 00:08:46,190
call, he just described a procedure to be
for his job. That procedure or a general solution,
74
00:08:46,190 --> 00:08:53,140
let's see the solution. He said number one,
start from the first record, there may be
75
00:08:53,140 --> 00:08:58,750
several columns of the record, the customer
name, the customer phone number, the customer
76
00:08:58,750 --> 00:09:05,870
email, the customer products that he buys
and the total sales. And in the point one
77
00:09:05,870 --> 00:09:12,420
said, he said, start from the first record,
and focus just on the sales column. Okay,
78
00:09:12,420 --> 00:09:19,510
then, then after that, go to each next record
one by one, and find the record with a maximum
79
00:09:19,510 --> 00:09:26,100
sales. Obviously, once you have focused on
the sales column, you're just comparing sales
80
00:09:26,100 --> 00:09:30,710
of different records with each other and will
eventually come up with a record that have
81
00:09:30,710 --> 00:09:33,990
maximum sales. Number three.
82
00:09:33,990 --> 00:09:39,830
If there are more than one records with maximum
sales, it is possible that the maximum sales
83
00:09:39,830 --> 00:09:45,270
value let's say is 100, whatever the units
are, and there may be two or three or maybe
84
00:09:45,270 --> 00:09:51,960
five records with the maximum sales 100. Then
which one to pick, as described here in Step
85
00:09:51,960 --> 00:09:57,900
three, that if there are more than one records
with maximum sales, then pick the first one
86
00:09:57,900 --> 00:10:03,620
from top to bottom and ignore the rest I mean,
whichever is the sole. So let's say you have
87
00:10:03,620 --> 00:10:10,190
five records with maximum sale value, which
record appears first from top to down, just
88
00:10:10,190 --> 00:10:15,360
pick that one and ignore the rest. That might
be a policy that might might be a tie breaking
89
00:10:15,360 --> 00:10:23,861
policy, but just do that. And then the fourth
step is focus on the email column of the record
90
00:10:23,861 --> 00:10:32,620
you found in step three. In Step three, you
found a column with maximum sales. Step five,
91
00:10:32,620 --> 00:10:40,580
see the email address and write that address
in the priority records. So that's for the
92
00:10:40,580 --> 00:10:46,560
eight hours, then repeat this process, see
the step six, then repeat this procedure,
93
00:10:46,560 --> 00:10:52,230
after every eight hours, I'm gonna repeat
this procedure, I mean, you'll see the the
94
00:10:52,230 --> 00:11:00,210
solution a is communicating to be in in this
in these kind of steps. It it gives me It
95
00:11:00,210 --> 00:11:06,630
gives a precise idea of what to do. Still,
there may be some, there may be some questions
96
00:11:06,630 --> 00:11:13,000
to be is maybe asking, for example, B may
ask how to find out a maximum, B might be
97
00:11:13,000 --> 00:11:19,300
that person who don't know how to find out
the maximum. And third, for example, another
98
00:11:19,300 --> 00:11:24,779
question we might may ask is that when when
I'm going to write the email address in the
99
00:11:24,779 --> 00:11:30,520
priority rock records, where should I write
at the very top or at the end or somewhere
100
00:11:30,520 --> 00:11:39,110
or, but at the end of the day, a solution
a step by step solution is required for communication,
101
00:11:39,110 --> 00:11:44,570
this kind of if you see the solution, although
it has some it may be explained in there may
102
00:11:44,570 --> 00:11:51,209
be more steps that should be added, but if
you see the solution, the step by step solution,
103
00:11:51,209 --> 00:11:57,580
this is a general solution. This is a general
solution, much more general solution for every
104
00:11:57,580 --> 00:12:02,300
instance, but every instance I mean, after
every eight hours, you will be having some
105
00:12:02,300 --> 00:12:07,970
records, and you have to do this procedure
on the records for that eight hours. And then
106
00:12:07,970 --> 00:12:12,720
after that, that after that eight hours, you
will be having more records to work on. So
107
00:12:12,720 --> 00:12:17,990
after every eight hours, you have the same,
the problem is the same, but the instance
108
00:12:17,990 --> 00:12:22,890
is different, because the records after eight
hours are different. But but the but the solution
109
00:12:22,890 --> 00:12:28,660
says whatever the instance you are right,
right now, whatever the instance is that you're
110
00:12:28,660 --> 00:12:34,660
in, just perform these, these steps, a step
by step solution, coming up with a step by
111
00:12:34,660 --> 00:12:42,540
step solution is is one module of the one
module of the problem solving. And there's
112
00:12:42,540 --> 00:12:47,240
step by step solution is called algorithm.
113
00:12:47,240 --> 00:12:57,920
algorithm. Obviously, the step by step solution
is not always required to be communicated
114
00:12:57,920 --> 00:13:04,300
in plain English or in natural language, you
may come up with shorthands or shortcuts to
115
00:13:04,300 --> 00:13:14,740
explain these step by step solution. So, the
the more shortcuts the more precise and unique
116
00:13:14,740 --> 00:13:20,700
meaning keywords you use in your step by step
solution, the more better communication of
117
00:13:20,700 --> 00:13:27,001
your solution takes place. And going from
this step by step solution, which is just
118
00:13:27,001 --> 00:13:39,700
in plain English, going from this to a more
concise and unique kind of procedure, that
119
00:13:39,700 --> 00:13:44,291
that can that kind of work that one step that
will take us from there to there, that we
120
00:13:44,291 --> 00:13:49,620
will see in the next video will be called
a pseudocode. And from that pseudocode there
121
00:13:49,620 --> 00:13:55,339
will be few steps that will take us to the
second major problem that the problem problem
122
00:13:55,339 --> 00:14:02,209
languages will solve the get the solution
running on a computer. So I'm just just in
123
00:14:02,209 --> 00:14:09,241
this video i i wanted to explain you that
solving a problem may not be that hard, I
124
00:14:09,241 --> 00:14:13,120
mean, coming up with a coming with coming
up with a solution of a problem may not be
125
00:14:13,120 --> 00:14:19,680
that hard, but communicating that solution
or, or writing that solution in a form of
126
00:14:19,680 --> 00:14:27,680
procedure that can solve every instance of
that problem that that requires a step by
127
00:14:27,680 --> 00:14:34,240
step treatment of the procedure. And those
those steps they should be linked in a sequence
128
00:14:34,240 --> 00:14:41,120
and they should be unambiguous. And if a particular
step requires more elaboration, that step
129
00:14:41,120 --> 00:14:45,970
might be broken down to further steps. But
that step by step solution at the end of the
130
00:14:45,970 --> 00:14:52,180
day is called algorithm. Now that algorithm
might be in English, but we will see in the
131
00:14:52,180 --> 00:14:58,269
later video that there are better ways of
expressing algorithms better than English
132
00:14:58,269 --> 00:15:05,230
or better than natural languages. So, so,
if you have another problem come up with a
133
00:15:05,230 --> 00:15:09,100
step by step solution of that, though, every
instance of that problem should be solved
134
00:15:09,100 --> 00:15:14,130
by that step by step solution, which is called
algorithm. And in the next video, we will
135
00:15:14,130 --> 00:15:23,180
see how to actually how to actually eliminate
the need of having English with us and how
136
00:15:23,180 --> 00:15:31,260
to incorporate the uniqueness of understanding
of these steps or algorithm using using the
137
00:15:31,260 --> 00:15:36,910
concepts of pseudocode. And after the pseudocode,
we will see it will be very quick to jump
138
00:15:36,910 --> 00:15:43,340
to any programming language and we will see
that the Python is very close to what humans
139
00:15:43,340 --> 00:15:47,839
generally think, I mean, it's very easy, the
transition will be very, very easy. So, hope
140
00:15:47,839 --> 00:15:56,770
to see you in the next video and I'll be explaining
algorithms in in, in a in a more kind of keyword
141
00:15:56,770 --> 00:16:05,959
way. And, and in the same video we'll be focusing
on pseudo codes which are basically pre step
142
00:16:05,959 --> 00:16:12,580
off of the actual core of any programming
language. So, hope to see you in the next
143
00:16:12,580 --> 00:16:18,890
video. Okay, in in the last video, we were
talking about the algorithm what an algorithm
144
00:16:18,890 --> 00:16:25,490
is and how to express that any any algorithm
and we saw that algorithm is just a step by
145
00:16:25,490 --> 00:16:33,050
step procedure. But, but how to express an
algorithm may vary, I mean, you need not always
146
00:16:33,050 --> 00:16:40,410
to have plain English to or any natural language
to express algorithm. The reason is that the
147
00:16:40,410 --> 00:16:46,000
natural languages are normally so expressive,
and each and every sentence they may have
148
00:16:46,000 --> 00:16:51,690
multiple meaning. So, it is it is a good idea
to come up with a structured way to express
149
00:16:51,690 --> 00:16:57,800
an algorithm such that each and every statement
is completely unambiguous. And one such way
150
00:16:57,800 --> 00:17:04,369
is is to express algorithms using flowcharts
flowcharts are our graphical ways of expressing
151
00:17:04,369 --> 00:17:11,048
algorithms. Here we are taking. The problem
here we are discussing is is computing PE
152
00:17:11,049 --> 00:17:16,730
of different employees of some company. And
the procedure of I mean, if there are several
153
00:17:16,730 --> 00:17:22,849
employees, let's employ one employee to employ
three and so on. Let's say there are several
154
00:17:22,849 --> 00:17:31,289
employees in a company and having each employee
has name, phone number, email and all the
155
00:17:31,289 --> 00:17:37,619
credentials. And then let's say the pay is
computed on hourly basis, and each employee
156
00:17:37,619 --> 00:17:43,470
has worked certain hours for example, eight
hours and each employee has an hourly rate
157
00:17:43,470 --> 00:17:48,039
might be let's say 100 units, whatever the
units are
158
00:17:48,039 --> 00:17:53,809
employed to might have worked for example,
seven hours, but the hourly rate of this employee
159
00:17:53,809 --> 00:18:00,860
might be 200 different employees, they might
have worked for different number of hours,
160
00:18:00,860 --> 00:18:05,210
and each employee can have a different hourly
rate depending upon the capacity of the employee
161
00:18:05,210 --> 00:18:12,789
or the or the job nature the employee is doing
and so on. So, so, so, if we want to compute
162
00:18:12,789 --> 00:18:20,070
pay of all employees, one by one, the procedure
of computing pay is stays the same, the instances
163
00:18:20,070 --> 00:18:26,899
they differ for employee one, the value of
our is eight the value of Raiders 100 for
164
00:18:26,899 --> 00:18:32,210
employee to the procedure will stay the same
the values of our end rate they will differ
165
00:18:32,210 --> 00:18:40,350
so what should be the procedure, the procedure
might be that you take the take the input
166
00:18:40,350 --> 00:18:47,379
of let's say employ one or whatever employee
you are going to compute salary for take the
167
00:18:47,379 --> 00:18:56,009
hours hours value in a in a placeholder call
that place or call that placeholder as ours
168
00:18:56,009 --> 00:19:01,399
placeholder or a variable y this is called
a variable because for different employers
169
00:19:01,399 --> 00:19:06,649
this value will different will be different,
ours will take value eight for each one employee
170
00:19:06,649 --> 00:19:14,009
one this this variable, this placeholder will
take value seven for employee two and so on.
171
00:19:14,009 --> 00:19:20,130
Similarly, once whatever employ whatever employ
for which you are going to compute the pay,
172
00:19:20,130 --> 00:19:27,100
if you have taken the hours from some records
from some working records, then take the rate
173
00:19:27,100 --> 00:19:33,159
for the same employer as well. So input this
that step one in Purdue that is step two,
174
00:19:33,159 --> 00:19:37,879
the steps the sequence of these two steps
may change for example, you take the you take
175
00:19:37,879 --> 00:19:42,590
the rate value first and ours value later
than that, but either way, that's one way
176
00:19:42,590 --> 00:19:50,739
of that's one way of expressing this this
procedure. And then you compute the pay by
177
00:19:50,739 --> 00:19:58,269
this formula. So hours multiplied by rate.
So maybe this is confusing writing a star.
178
00:19:58,269 --> 00:20:04,580
Maybe maybe We should write this cross symbol
because that is more common in mathematics.
179
00:20:04,580 --> 00:20:14,080
Or maybe this whole line can be replaced by,
by this particular line, maybe. So pay is
180
00:20:14,080 --> 00:20:27,929
equal to multiply hours. And rate. Maybe this
is more expressive, but it completely depends,
181
00:20:27,929 --> 00:20:33,799
I mean, when you start writing pseudocode,
or whatever pseudo codes you're writing, what
182
00:20:33,799 --> 00:20:40,299
kind of keywords begin is a keyword and is
a key word, what kind of keywords you're using,
183
00:20:40,299 --> 00:20:46,190
and stay with those keywords for example,
if the keyword input is to use to take to
184
00:20:46,190 --> 00:20:53,309
get the values to to process on then the input
should stay everywhere wherever we want to
185
00:20:53,309 --> 00:20:59,360
do such kind of operation. If you if you're
using for example, the value get rather than
186
00:20:59,360 --> 00:21:06,590
input then use get always but come up with
some set of keywords that are expressive,
187
00:21:06,590 --> 00:21:12,080
as well as concise and then take the sequence
of those statements, each and every statement
188
00:21:12,080 --> 00:21:17,629
should be should have a unique meaning, it
should not be ambiguous, and the sequence
189
00:21:17,629 --> 00:21:24,090
should be in the sequence describe the flow
of what is happening, what is going on. So,
190
00:21:24,090 --> 00:21:30,739
first we take hours, then we take rate these
two values for for for any kind of employee,
191
00:21:30,739 --> 00:21:35,130
and then we will just multiply them and after
multiplication, whatever the scene we want
192
00:21:35,130 --> 00:21:43,220
to make, based on this pay, we will do that,
we may we may record this value, display value
193
00:21:43,220 --> 00:21:51,390
at at some other records register, we may
we may print that value on a print slip, we
194
00:21:51,390 --> 00:21:55,629
may have emailed this value to some other
department or whatever to see and we want
195
00:21:55,629 --> 00:22:02,510
to make, but the procedure really is still
here, then based on pay whatever action we
196
00:22:02,510 --> 00:22:10,039
are going to do that that may differ. Similarly
if we go this is this is I mean, some kind
197
00:22:10,039 --> 00:22:18,009
of structured example of, of the, of the expressiveness
of an algorithm which is called pseudocode.
198
00:22:18,009 --> 00:22:24,559
And what kind of keywords you're going to
use, there are no general keywords, I mean,
199
00:22:24,559 --> 00:22:30,110
some people may use get some people may use
different kinds of keywords for it, but it
200
00:22:30,110 --> 00:22:36,169
is good to come up with a set of keywords
to to describe the describe the solution of
201
00:22:36,169 --> 00:22:43,860
the solution of the problem in flowchart for
example, everything every every statement
202
00:22:43,860 --> 00:22:50,230
here, that is here in in pseudocode every
statement is described as a shape different
203
00:22:50,230 --> 00:22:55,009
shapes for different kinds of statements.
If you want to take input, then you have to
204
00:22:55,009 --> 00:23:00,509
describe that action using a parallelogram.
If you're going to do some computation, you
205
00:23:00,509 --> 00:23:07,320
have to express that using a rectangle the
start symbol and end symbol the start and
206
00:23:07,320 --> 00:23:14,039
end of any procedure in flowcharts they are
described by the ovals For example, this oval
207
00:23:14,039 --> 00:23:18,639
in that oval normally the flowchart sequences
from top to down, but it is always good to
208
00:23:18,639 --> 00:23:27,879
just print the arrows to describe the flow,
because in complicated flowcharts there are
209
00:23:27,879 --> 00:23:32,860
there are loops there are if conditions there
are so many things. So it is good always to
210
00:23:32,860 --> 00:23:40,669
describe the flow using using arrows. So,
now the question is flowchart or pseudocode
211
00:23:40,669 --> 00:23:48,549
because flowchart also looks like a very cool
way of writing. expressing an algorithm and
212
00:23:48,549 --> 00:23:55,539
pseudocode is also a way of expressing an
algorithm. Well, converting flowchart to actual
213
00:23:55,539 --> 00:24:01,979
programming code is somewhat tedious, writing
a pseudocode beforehand, which is readable,
214
00:24:01,979 --> 00:24:11,090
which is precise, concise, as well as unambiguous
then converting that pseudocode to code of
215
00:24:11,090 --> 00:24:17,039
any programming language, that is not that
hard, that is simple in writing flowcharts
216
00:24:17,039 --> 00:24:21,720
for very complicated problems is somewhat
tedious, because then it It also requires
217
00:24:21,720 --> 00:24:27,299
another transition from flowchart to reactive
programming code. That's why writing pseudocode
218
00:24:27,299 --> 00:24:32,229
is more feasible, if the goal eventually is
to convert that pseudocode to some core of
219
00:24:32,229 --> 00:24:38,140
programming language. So, you can go with
flowcharts you can go with pseudocode either
220
00:24:38,140 --> 00:24:45,830
one is fine, but more feasible way of expressing
algorithms is a pseudocode. That was just
221
00:24:45,830 --> 00:24:50,789
a very simple example. I mean computing, computing
salary of an employee writing a procedure
222
00:24:50,789 --> 00:24:59,429
for that. I mean, this is so simple, nobody
make your writing that kind of writing solution.
223
00:24:59,429 --> 00:25:05,730
have this kind of problem as a as an algorithm
or as a pseudocode as a flowchart. But the
224
00:25:05,730 --> 00:25:11,019
basic idea is, is is is the same, even if
you have a complicated problem if even if
225
00:25:11,019 --> 00:25:17,200
you have a problem with maybe many more steps,
the idea is still the same. In the in the
226
00:25:17,200 --> 00:25:25,759
next video, we will we will see a procedure
how to how to make tea for example, that might
227
00:25:25,759 --> 00:25:31,119
that may look look to you funny, I mean, do
we really want do we really want to know the
228
00:25:31,119 --> 00:25:37,639
procedure to make tea? Well, the idea is not
to learn how to make tea, the idea is to learn
229
00:25:37,639 --> 00:25:44,320
how to express the solution of this problem
making tea that's a problem, the solution
230
00:25:44,320 --> 00:25:49,489
of this for how to how to express solution
of that problem as as a pseudocode. And we
231
00:25:49,489 --> 00:25:55,330
will see one more example of flowchart as
well. So hope to see you in the next video.
232
00:25:55,330 --> 00:26:02,840
Okay. In the last video, we saw flowcharts
and pseudocode, we just took an example of
233
00:26:02,840 --> 00:26:10,289
we took a very simple example computing salary
or pay of employee of a company given hours
234
00:26:10,289 --> 00:26:16,490
and rate. And I also described weatherflow,
the the comparison between flowchart and pseudocode.
235
00:26:16,490 --> 00:26:22,629
And I said that pseudocode is closer to the
core of some programming language, which eventually
236
00:26:22,629 --> 00:26:29,960
we need, because eventually we need automation
of of a solution of a problem. And for that,
237
00:26:29,960 --> 00:26:36,749
we need a code of the digit the code for the
solution, the general solution in some programming
238
00:26:36,749 --> 00:26:43,110
language, so flowchart and pseudocode, and
then the core of some programming language
239
00:26:43,110 --> 00:26:45,519
like Python,
240
00:26:45,519 --> 00:26:52,639
it is somehow in sometimes handy to to break
the problem or to devise a general solution
241
00:26:52,639 --> 00:26:59,299
of any problem for in first step in a flowchart
because that is more expressive, and more
242
00:26:59,299 --> 00:27:04,549
generic, more general, maybe in a graphical
way. And then once the proof of concept is
243
00:27:04,549 --> 00:27:09,860
clear, once it is clear that this is indeed
a general solution, it has no bugs inside
244
00:27:09,860 --> 00:27:16,590
it has no errors, it will work always, then
we can take another step to convert that flowchart
245
00:27:16,590 --> 00:27:23,580
to pseudocode. And then pseudocode can be
converted to the the code of any the code
246
00:27:23,580 --> 00:27:29,119
in some programming language. But writing
pseudocode right away, I mean, from the very
247
00:27:29,119 --> 00:27:34,219
beginning without flowcharts is also a common
practice. Either way, whichever way suits
248
00:27:34,219 --> 00:27:43,499
you. In this particular video, I'm going to
talk about problem the problem is making tea.
249
00:27:43,499 --> 00:27:47,700
You might be thinking, what are the different
instances of this problem I'm in making tea
250
00:27:47,700 --> 00:27:53,779
is making tea. What what kind of different
instances are there? Well, one person may
251
00:27:53,779 --> 00:28:03,889
be liking tea with, for example, 1.5 units
of sugar, whatever the units are, and another
252
00:28:03,889 --> 00:28:12,000
person may want a tea with, let's say, two
units of sugar, one person maybe, maybe needing
253
00:28:12,000 --> 00:28:17,419
a D with, for example, point five units of
milk, and another one, maybe a different units
254
00:28:17,419 --> 00:28:24,099
of milk, and so on. So the procedure of making
tea should stay same. And the instances which
255
00:28:24,099 --> 00:28:31,690
means the different people want tea in a different
kind of combination that may vary. So let's
256
00:28:31,690 --> 00:28:37,320
let's like let's see a procedure first and
flowchart. And then in pseudocode, for for
257
00:28:37,320 --> 00:28:43,239
making a tea, for making tea. So let's start
that that might look like that might look
258
00:28:43,239 --> 00:28:50,179
you look to you a kind of funny kind of problem.
But that's a genuine problem. For example,
259
00:28:50,179 --> 00:28:59,539
if you want to make tea, what is algorithm
for this? So first we start and then the first
260
00:28:59,539 --> 00:29:07,559
step we do is we put teabag in a cup, that
might be a first step. You can argue should
261
00:29:07,559 --> 00:29:15,029
this be a first step should that be the second
step and so on the sequence of By the way,
262
00:29:15,029 --> 00:29:21,039
solving one problem, you can have multiple
algorithms for that. And do different algorithms
263
00:29:21,039 --> 00:29:26,119
may just vary because of the sequence of statements
even if you have the same statements. So I'm
264
00:29:26,119 --> 00:29:31,429
not talking about that the algorithm or the
general solution is unique. You can have multiple
265
00:29:31,429 --> 00:29:37,700
different general solutions or procedures.
So for example, putting a teabag in a cup
266
00:29:37,700 --> 00:29:42,969
that might be first step, or the first step
might be the boil, boil the water and pour
267
00:29:42,969 --> 00:29:48,599
the water and pour the water in the cup and
then put the tea back. Both are fine, I mean
268
00:29:48,599 --> 00:29:54,710
this way or that way. So let's start with
putting a tea bag in a cup. So that's an that's
269
00:29:54,710 --> 00:30:00,809
an input. We take the tea bag from somewhere.
That's our input last time, I do You that
270
00:30:00,809 --> 00:30:09,719
input is taken as parallelograms put a teabag
in a cup and then forget about that cup and
271
00:30:09,719 --> 00:30:15,029
boil the water somewhere there is a water
I mean take the water from somewhere and boil
272
00:30:15,029 --> 00:30:23,919
it and see if after let's say five or six
or seven time units whatever the time units
273
00:30:23,919 --> 00:30:29,460
are, see if the water is boiled or not assume
that there is a test that tells you that the
274
00:30:29,460 --> 00:30:34,349
water is boiled or not. So, there is a test
available to you. So, you apply that test
275
00:30:34,349 --> 00:30:39,490
and check that the water is boiled or not
if it is not oil then keep on boiling. So
276
00:30:39,490 --> 00:30:47,429
boil it again. And assume there is a procedure
of boiling of water in in in normal case,
277
00:30:47,429 --> 00:30:54,739
boiling water is just happened by I mean keeping
the temperature high or putting that thing
278
00:30:54,739 --> 00:31:01,759
putting the pot of water on fire or something
like so, but that that itself is a procedure.
279
00:31:01,759 --> 00:31:03,109
So,
280
00:31:03,109 --> 00:31:09,710
while the water again and boil the water again
check if the water is boiled if no then boil
281
00:31:09,710 --> 00:31:17,039
it again. If not boil again then check if
no then boil it again this is called a loop
282
00:31:17,039 --> 00:31:22,570
this is called a loop or repetition you are
doing the same kind of stuff again and again.
283
00:31:22,570 --> 00:31:27,590
Until there is a particular condition that
is that is met. So in this case, the condition
284
00:31:27,590 --> 00:31:33,950
is when while the water is not boil, keep
on doing the same procedure again and again.
285
00:31:33,950 --> 00:31:40,359
This is called repetition or loop. So you
boil the water again, check the condition
286
00:31:40,359 --> 00:31:45,419
if the condition is true, for example, the
water boil Yes, then come out. Then you're
287
00:31:45,419 --> 00:31:51,039
then you can exit this loop and come out.
Then pour the water pour the water in in the
288
00:31:51,039 --> 00:31:57,629
cup. Here we should hear we should describe
that is that the same cup or a different cup?
289
00:31:57,629 --> 00:32:06,919
Well, this see you pick up here is acting
as as a placeholder where this tea bag and
290
00:32:06,919 --> 00:32:12,499
the water is going in. So we have a cup, we
put teabag in it, then we put the boil water
291
00:32:12,499 --> 00:32:19,990
in it, but before pouring the boiled water
in it. We just boiled the water. Okay, and
292
00:32:19,990 --> 00:32:26,789
then after we have water in a cup and a tea
bag in a cup, what should we do next? We actually
293
00:32:26,789 --> 00:32:37,149
we actually first test one sugar or need more
sugar? If yes, then then add sugar. So let's
294
00:32:37,149 --> 00:32:45,169
apply some arrows. If yes, add them add sugar.
And then again ask do you need do you need
295
00:32:45,169 --> 00:32:54,229
more sugar? Or one sugar now? Yes, add sugar.
One sugar. Yes, add sugar that is again a
296
00:32:54,229 --> 00:33:01,600
loop that is again a loop while while the
while you want sugar. I mean you test that
297
00:33:01,600 --> 00:33:07,419
the sugar is okay or not. Here you test that
the sugar is okay or not or whatever sugar
298
00:33:07,419 --> 00:33:13,320
you need. If Is that okay or not? Until that
condition is not met, you keep on adding the
299
00:33:13,320 --> 00:33:20,619
sugar, add a teaspoon again, then test out
a teaspoon that is again a loop or repetition.
300
00:33:20,619 --> 00:33:26,849
Once the condition is met once you know then
exit this loop and ask what milk because some
301
00:33:26,849 --> 00:33:34,629
people just take tea without milk. Maybe somebody
wants a milk maybe somebody don't. So want
302
00:33:34,629 --> 00:33:41,690
milk? Yes. So add milk. So that's that's a
mistake this this loop should go there. There
303
00:33:41,690 --> 00:33:50,989
right there. And this line shouldn't be there.
That's that's wrong. Add milk and then ask
304
00:33:50,989 --> 00:33:58,989
what milk? Yes, admin, that's again a loop.
Once you exit the loop, then you ask need
305
00:33:58,989 --> 00:34:08,840
to steer. Yes, steer, then ask again. This
line again shouldn't be there. So that that's
306
00:34:08,840 --> 00:34:14,710
another loop. Once you exit this loop, then
the T is ready, you serve that D finish you're
307
00:34:14,710 --> 00:34:20,719
done with the procedure. Now let's see the
same procedure in pseudocode program is the
308
00:34:20,719 --> 00:34:29,230
keyword and that's what program name is program
make D what is a keyword put teabag in a cup
309
00:34:29,231 --> 00:34:38,340
while water not while while is a key word,
while this is not while this condition is
310
00:34:38,340 --> 00:34:45,429
not satisfied, keep on doing this. Whatever
written in while and while is is the body
311
00:34:45,429 --> 00:34:52,979
of this repetition are called loop. So while
water is not boil, boil water. Then again
312
00:34:52,980 --> 00:35:00,200
check water boiler not know what again. I'm
in keep on boiling. So this is repetition.
313
00:35:00,200 --> 00:35:06,020
Once the water is boiled, which means this
condition is becomes false what not oil becomes
314
00:35:06,020 --> 00:35:14,030
false so water boil, then you exit this loop,
you pour that water in cup, that's again a
315
00:35:14,030 --> 00:35:22,510
key word, you in a cup, and then you ask,
okay, need sugar? Yes, add sugar, need sugar,
316
00:35:22,510 --> 00:35:30,810
yes, add sugar. So you keep on doing this
until you don't need sugar anymore. So, that's
317
00:35:30,810 --> 00:35:37,900
again a loop. So, so, you might be thinking
that why we are writing this add sugar and
318
00:35:37,900 --> 00:35:45,100
this boil water to writer to this this why
we are really indenting this that style of
319
00:35:45,100 --> 00:35:50,860
pseudocode to just display that this is inside
this this is this particular statement or
320
00:35:50,860 --> 00:35:56,170
set of statements are called the body of the
loop and this end Oil should be here in this
321
00:35:56,170 --> 00:36:01,500
alignment here in this line and so, there
is a there is a bug in this slide this should
322
00:36:01,500 --> 00:36:02,500
be
323
00:36:02,500 --> 00:36:09,600
here okay once this condition is false sugar
needed no then you can exit this loop and
324
00:36:09,600 --> 00:36:17,880
you go here while milk needed yes add milk,
check again milk needed yes add milk milk
325
00:36:17,880 --> 00:36:24,040
needed yes add milk. Once this condition becomes
false milk needed no then you can exit this
326
00:36:24,040 --> 00:36:30,970
loop, you can just go to here. While latest
here need to steer steer D need to steer yes
327
00:36:30,970 --> 00:36:38,160
sturdy he was there yesterday, once this condition
is false get out and your tea is ready Do
328
00:36:38,160 --> 00:36:45,030
whatever you want to do. This example was
so simple, but it expresses a very powerful
329
00:36:45,030 --> 00:36:52,830
tool in in the pseudocode as well as in flowcharts.
And that tool is sometimes called loop which
330
00:36:52,830 --> 00:36:58,010
is there to repeat a particular procedure
whatever procedure you want to repeat again
331
00:36:58,010 --> 00:37:06,510
and again to until there is a particular condition
that is met that is loop loop is there. So,
332
00:37:06,510 --> 00:37:15,710
the The purpose of this slide is was just
to just to make you make you convinced and
333
00:37:15,710 --> 00:37:22,240
make you comfortable with the pseudocode and
flowchart we will not be talking about flowcharts
334
00:37:22,240 --> 00:37:28,040
any further from here on we will we will be
just talking about pseudocode in just one
335
00:37:28,040 --> 00:37:34,310
or two more videos. And then we will be directly
going towards from we will be we will be comfortable
336
00:37:34,310 --> 00:37:39,330
enough with pseudocode for solving certain
kinds of problems that we will then eventually
337
00:37:39,330 --> 00:37:45,090
be moving from pseudocode to actual Python
code. And and I bet you I'm going to tell
338
00:37:45,090 --> 00:37:51,520
you that the pseudocode in the next video
I'm going to explain that will be very, very
339
00:37:51,520 --> 00:37:57,240
easily will be converted to the actual exact
Python code. So in the next video, we are
340
00:37:57,240 --> 00:38:06,270
going to actually solve a problem of finding
out minimum value from a list of values, sometimes
341
00:38:06,270 --> 00:38:11,590
called the searching problem, we're going
to solve it by first using pseudocode. And
342
00:38:11,590 --> 00:38:17,630
then in a later video, we will see how to
write the actual Python code for that problem.
343
00:38:17,630 --> 00:38:26,030
So hope to see you in the next video. Okay,
let's dive into real problem. Let's say you're
344
00:38:26,030 --> 00:38:34,080
given, you're given a list of numbers, let's
say, let's say l is some list. with numbers,
345
00:38:34,080 --> 00:38:42,100
let's say we define list by these, these square
brackets, let's say the list contains 23.
346
00:38:42,100 --> 00:38:48,290
Let's say that's a value minus four, that
value is zero, that's a value 73. That's a
347
00:38:48,290 --> 00:38:56,320
value, and maybe maybe minus 10. That's a
value, maybe 13. That's a value. So let's
348
00:38:56,320 --> 00:39:08,600
just take an example that we have 123456 values
in a list. So and that list is basically we
349
00:39:08,600 --> 00:39:16,600
took the list here as L and we just describe
that let's say the list is declared by or
350
00:39:16,600 --> 00:39:21,620
expressed by the square brackets, and the
elements of the list, they are separated by
351
00:39:21,620 --> 00:39:26,850
comma. That is just our convention for this
kind of problem for this problem just for
352
00:39:26,850 --> 00:39:33,700
this code. And And I'm not talking about any
particular programming language yet. This
353
00:39:33,700 --> 00:39:42,380
is just a list of numbers. And let's say we
want a procedure that finds out the minimum
354
00:39:42,380 --> 00:39:49,730
value of any list. Well, first of all, why
this problem has multiple instances. Well,
355
00:39:49,730 --> 00:39:56,110
we need to come up with a solution that works
for any list for example, if the list is if
356
00:39:56,110 --> 00:40:01,140
the list has these six values, then the procedure
should find out the minimum In this list,
357
00:40:01,140 --> 00:40:06,320
the minimum value in this list out of all
the values is minus 10.
358
00:40:06,320 --> 00:40:11,860
Because minus 10 is smaller than every other
value. 23 is bigger minus four is smaller
359
00:40:11,860 --> 00:40:20,300
than 23. Zero is bigger than minus four, because
the, the value with negative sign, it is smaller
360
00:40:20,300 --> 00:40:27,380
with the value of a positive sign. But if
you have two values with negative signs, the
361
00:40:27,380 --> 00:40:32,660
value with a bigger number, in terms of magnitude
is actually smaller in negative sense. So
362
00:40:32,660 --> 00:40:39,670
if you compare minus four and minus 10 minus
10 is smaller. In minus in minus domain, in
363
00:40:39,670 --> 00:40:46,510
positive domain, the result is different.
So I was talking about why this problem has
364
00:40:46,510 --> 00:40:51,080
multiple instances, why you need a general
solution for that, that's less just go and
365
00:40:51,080 --> 00:40:56,640
find out the minimum that is minus 10. Go
home happy? Well, we need a solution that
366
00:40:56,640 --> 00:41:02,010
works for another list. Another list with
different numbers. And maybe different number
367
00:41:02,010 --> 00:41:06,640
of numbers. Maybe in this list, we have six
numbers, another list may have 74 numbers,
368
00:41:06,640 --> 00:41:11,770
another list may have 1 trillion numbers,
we want to come up with a procedure that always
369
00:41:11,770 --> 00:41:20,860
finds out the minimum value in that list.
Obviously, the minimum value may repeat, I
370
00:41:20,860 --> 00:41:27,250
mean, the minimum value may occur more than
once in a list. So what is a minimum value
371
00:41:27,250 --> 00:41:31,710
rather than knowing how many times that occur,
what is the minimum value, that's a problem
372
00:41:31,710 --> 00:41:35,890
finding out a minimum value, and we want to
find out, we want to come up with a procedure
373
00:41:35,890 --> 00:41:41,530
that finds out the minimum value, regardless
of the list, whatever the list is, this procedure
374
00:41:41,530 --> 00:41:48,230
should actually return or end up finding out
the minimum value. So, in this particular
375
00:41:48,230 --> 00:41:52,550
case, again, for this particular example,
the minimum value is minus 10. And we will
376
00:41:52,550 --> 00:41:59,740
take example of this list, and we will see
how to code a procedure for that. So but but
377
00:41:59,740 --> 00:42:07,110
before starting this procedure, what kind
of things we really need to to, to write a
378
00:42:07,110 --> 00:42:14,710
pseudocode. For this kind of problem, we may
start by writing that program, like in the
379
00:42:14,710 --> 00:42:25,591
previous video, program name as search. And
then we take input or input list, then we
380
00:42:25,591 --> 00:42:33,480
take input, the number of values in the list
the total number of values, and then we move
381
00:42:33,480 --> 00:42:40,260
on as as we want to move on. But writing out
a procedure in terms of pseudocode, it is
382
00:42:40,260 --> 00:42:47,310
always good to to avoid these input statements
inside the pseudocode. And always supply whatever
383
00:42:47,310 --> 00:42:54,570
whatever needed, always supply the instance,
from outside and assume that the instance
384
00:42:54,570 --> 00:42:59,720
is supplied and then just work on that instance.
Rather than reading the instance. Rather than
385
00:42:59,720 --> 00:43:04,520
taking the values of instance, a particular
instance from inside the code, it is always
386
00:43:04,520 --> 00:43:10,910
a good practice to, to, to supply the instance
from outside, so supply the list from somewhere,
387
00:43:10,910 --> 00:43:15,960
and this n is really the size of the list.
In this particular case, let's say if this
388
00:43:15,960 --> 00:43:21,210
is the list, then that list will be there,
supplied from somewhere, but we'll see how
389
00:43:21,210 --> 00:43:26,890
to supply that. And this n value here, in
this particular case, the N value is six the
390
00:43:26,890 --> 00:43:33,391
total number of values in the list 12345,
and six, these are six values. So it is a
391
00:43:33,391 --> 00:43:40,620
good practice to rather than writing program
and then this, just write the name of the
392
00:43:40,620 --> 00:43:45,870
problem you're going to solve in this particular
case the name is search minimum from list.
393
00:43:45,870 --> 00:43:51,190
And then this particular we are talking about
this list l with total number of elements
394
00:43:51,190 --> 00:43:59,080
as n whatever the values inside the L is we
do not know and and this n may take different
395
00:43:59,080 --> 00:44:05,330
values, l can be different, this n can be
different for different instances. But it
396
00:44:05,330 --> 00:44:12,690
is not a good practice to take input from
inside here. Then, one more convention is
397
00:44:12,690 --> 00:44:19,130
that, let's say list of two represents the
second element in the list. In this particular
398
00:44:19,130 --> 00:44:27,830
case, L of two is basically L of two is basically
the second element in the list, which is minus
399
00:44:27,830 --> 00:44:37,410
four, L of let's say three is the third element
in this list, which is a zero, and so on.
400
00:44:37,410 --> 00:44:43,430
So let's let's take a convention, that whenever
we want to access the elements of the lists,
401
00:44:43,430 --> 00:44:50,040
whatever whenever you want to read the elements
from the list, we will read the element number
402
00:44:50,040 --> 00:44:57,330
by giving the element number here let's say
whatever the if we write L of AI, that means
403
00:44:57,330 --> 00:45:01,060
it means the ayat element of the list.
404
00:45:01,060 --> 00:45:11,720
So, first we take a variable, we are assuming
here that the list is supplied to us the total
405
00:45:11,720 --> 00:45:16,310
number of elements in the list is supplied
to us. So we first take the minimum value,
406
00:45:16,310 --> 00:45:22,520
we, which we really want to compute the minimum
value we want to compute, but any list can
407
00:45:22,520 --> 00:45:26,901
be supplied in this procedure. So what's the
procedure, the minimum value that we want
408
00:45:26,901 --> 00:45:31,060
to compute, we just consider the very first
value of the list in this case, the very first
409
00:45:31,060 --> 00:45:36,450
value is 23, we consider that is the minimum
value. Obviously, that is wrong, this is not
410
00:45:36,450 --> 00:45:40,370
minimum value, minimum value may be somewhere
else, or maybe this one may be somewhere else,
411
00:45:40,370 --> 00:45:45,460
but we are not sure that the first value in
the list is the minimum value. But let, let's
412
00:45:45,460 --> 00:45:51,350
just hold on for a moment and move on. Let's
say the minimum value is this here, this is
413
00:45:51,350 --> 00:46:02,700
called the assignment assignment. This min
value is a placeholder or a variable, and
414
00:46:02,700 --> 00:46:10,620
I have assigned this value l one to it. Now,
from here onwards, the min value will be will
415
00:46:10,620 --> 00:46:18,390
be will be having a value which is 23. In
this particular case, okay, so min value is
416
00:46:18,390 --> 00:46:25,260
this, which is 23. Now, let's declare, let's
declare another variable, which is called
417
00:46:25,260 --> 00:46:30,650
counter, we may need this counter. And let's
declare this with two, why we are declaring
418
00:46:30,650 --> 00:46:37,310
this with two it will become clear later on.
So now we so min Valley right now, for this
419
00:46:37,310 --> 00:46:44,750
particular list, the min value takes the value
23. So and counter takes the value two, these
420
00:46:44,750 --> 00:46:51,880
are two things for these two variables. Now,
we apply a loop while counter is smaller than
421
00:46:51,880 --> 00:46:58,220
n smaller equal to n. Remember the value of
n for this particular example is six, and
422
00:46:58,220 --> 00:47:04,170
counter here is two. So because counter has
value two, while two is less than or equal
423
00:47:04,170 --> 00:47:10,790
to six, first check whether this condition
is true or false, because if this condition
424
00:47:10,790 --> 00:47:21,200
is true, then you will go to the body of the
loop, then this whole box will execute. If
425
00:47:21,200 --> 00:47:27,780
this condition becomes false, then you will
exit the loop and we'll go out. So now counter
426
00:47:27,780 --> 00:47:36,610
is to the so two is smaller or equal to six.
true false. That is true. So the condition
427
00:47:36,610 --> 00:47:41,670
is to two is indeed smaller than or equal
to six, that is true. So we will go inside
428
00:47:41,670 --> 00:47:48,870
to the box and see what happens. Then what
we will do, we will pick and pick a value
429
00:47:48,870 --> 00:47:57,550
from at the index counter. Right now the counter
has value to L off counter means pick the
430
00:47:57,550 --> 00:48:02,870
value, because the counter has value to pick
the second value, which is minus four and
431
00:48:02,870 --> 00:48:08,390
pick that value minus four from the list,
pick that value and copy that value or assign
432
00:48:08,390 --> 00:48:15,461
that value to a variable v. That's a new variable
we maybe needed somewhere okay. Previously
433
00:48:15,461 --> 00:48:20,880
the min value which is a variable, it was
containing the very first value which is 23.
434
00:48:20,880 --> 00:48:25,250
Now we have picked the second value the counter
value is two. So we have picked the second
435
00:48:25,250 --> 00:48:32,910
value from the list, which is minus four.
Now we compare if the value now which is minus
436
00:48:32,910 --> 00:48:41,440
four is that value smaller than our minimum
value. So far, the minimum value so far is
437
00:48:41,440 --> 00:48:50,160
is 23. So minus four is smaller than 23. Yes,
the condition is true, if the condition is
438
00:48:50,160 --> 00:48:58,030
true, we will go into this block, otherwise
we will go into this block. So right now the
439
00:48:58,030 --> 00:49:03,690
condition is true. So we will go in this block
and minimum value will just be replaced by
440
00:49:03,690 --> 00:49:10,160
the new value. And the new value right now
is minus four. So because a minus four is
441
00:49:10,160 --> 00:49:17,030
smaller than 23, so we are here in this body,
the if condition becomes true, you're in this
442
00:49:17,030 --> 00:49:24,100
body, and the minimum value becomes whatever
the value is in V and right for this example,
443
00:49:24,100 --> 00:49:31,640
the value in V is minus four. Okay? So if
if if you go into the if condition, then you're
444
00:49:31,640 --> 00:49:35,880
not going into the else part, either you're
going to F part or in the else part one of
445
00:49:35,880 --> 00:49:44,650
them. Okay, so then we move back Oh, there's
a bug here we need to add the counter. We
446
00:49:44,650 --> 00:49:50,740
need to increment the counter here after after
this. Before this. There is another statement
447
00:49:50,740 --> 00:49:59,890
increment the counter. increment counter.
That's another statement increment counter.
448
00:49:59,890 --> 00:50:04,780
So Now increment the counter after this if
part increment the counter, and the counter
449
00:50:04,780 --> 00:50:09,980
will become three. Now, we will repeat the
procedure and check three is smaller than
450
00:50:09,980 --> 00:50:15,660
six, yes, we will go inside, and we will pick
now the counter value is three, we will go
451
00:50:15,660 --> 00:50:21,360
and pick the third entry. And now the third
entry will be in V, the V will now contain
452
00:50:21,360 --> 00:50:28,150
zero. Previously it contained minus four now
it will contain zero min value is containing
453
00:50:28,150 --> 00:50:36,190
minus four now, so zero is smaller than minus
four, no, if zero is smaller than minus four,
454
00:50:36,190 --> 00:50:40,430
then do this. But zero is not smaller than
minus four, then go to the else part. And
455
00:50:40,430 --> 00:50:47,740
as far as just saying just go on do nothing,
I mean don't do anything. So when you're here
456
00:50:47,740 --> 00:50:52,570
don't do anything except if condition increment
the counter again. Now, you increment the
457
00:50:52,570 --> 00:50:58,670
counter the counter value will become four
and the value add for is 73. First of all
458
00:50:58,670 --> 00:51:04,350
check for is smaller equal to six Yes, we
will contain the value at index four which
459
00:51:04,350 --> 00:51:13,480
is 7373 is smaller than minus four no do nothing
and given the counter check the if condition
460
00:51:13,480 --> 00:51:18,800
check the while condition now counter will
be five five is smaller or equal to six Yes,
461
00:51:18,800 --> 00:51:24,900
pick the fifth entry because country's fifth
the fifth entry is minus 10
462
00:51:24,900 --> 00:51:31,370
minus 10 is smaller than minus four yes okay.
Replace min value with the new value. Now
463
00:51:31,370 --> 00:51:37,870
the min value will contain minus 10 okay because
if has executed else will not execute, you
464
00:51:37,870 --> 00:51:42,730
exit the if condition and then you increment
the counter the counter will become six. Now
465
00:51:42,730 --> 00:51:49,390
six is smaller equal to six Yes, because six
is equal to six hence the condition is true.
466
00:51:49,390 --> 00:51:57,201
Now, you go and pick the sixth entry which
is 13. Check 13 is smaller than minus 10 because
467
00:51:57,201 --> 00:52:02,650
min value is containing minus 10. So far,
no that is false go to else condition, the
468
00:52:02,650 --> 00:52:08,220
two else part just go on to nothing, increment
the counter, now the counter will become seven
469
00:52:08,220 --> 00:52:14,910
and you go back and check the condition seven
is smaller equal to six false exit the loop.
470
00:52:14,910 --> 00:52:20,600
Okay, exit the loop, go to this condition,
go to this statement. Now Now you're out of
471
00:52:20,600 --> 00:52:25,320
the loop and return the min value. And see
the min value here is containing the actual
472
00:52:25,320 --> 00:52:33,520
min value which is minus 10. So that's how
we search the minimum, this return is also
473
00:52:33,520 --> 00:52:40,290
a keyword. So which means if we if we just
if we just if we just use that function, if
474
00:52:40,290 --> 00:52:46,220
we if we just use that pseudocode with if
we just use that pseudocode for this different
475
00:52:46,220 --> 00:52:51,620
kind of lists with with its sizes, whatever
the list, this is this was just one example
476
00:52:51,620 --> 00:52:59,630
if we chain the list, the procedure will work
one one bug in in the code was the increment
477
00:52:59,630 --> 00:53:05,280
counter statement was not there, it should
be there after the end F and before this end
478
00:53:05,280 --> 00:53:11,650
while here. So this that was the pseudocode
of searching a minimum. In the next video
479
00:53:11,650 --> 00:53:18,880
we are going to use this pseudocode and we
will we will see how to rearrange the values
480
00:53:18,880 --> 00:53:23,880
of a list or sorting the values of lists such
that all the values that are smaller they
481
00:53:23,880 --> 00:53:30,060
become earlier than the bigger values. And
the problem is called sorting. So in the in
482
00:53:30,060 --> 00:53:36,520
the next video we are going to talk about
one more problem, very famous problem called
483
00:53:36,520 --> 00:53:43,820
the sorting problem. And after that problem,
we will be going towards Python. Because after
484
00:53:43,820 --> 00:53:48,160
that problem, you will be having a fairly
good idea how to solve a problem how to write
485
00:53:48,160 --> 00:53:52,140
a pseudocode for a problem. And the way we
are writing the pseudocode is very close to
486
00:53:52,140 --> 00:53:58,250
the actual Python code which will become so
clear to you. So hope to see you in the next
487
00:53:58,250 --> 00:54:03,690
video. Okay, in the last video we talked about
we talked about this how to find out minimum
488
00:54:03,690 --> 00:54:10,240
value from a list of values. And we came up
with an algorithm with name search men from
489
00:54:10,240 --> 00:54:18,030
list. Here we have just made a little modification
that rather than just returning the minimum
490
00:54:18,030 --> 00:54:24,110
value, we are also returning the position
of the minimum value in the list. So for example,
491
00:54:24,110 --> 00:54:35,550
if the list is 17024, let's say in nine letter
that's our list. There are seven numbers in
492
00:54:35,550 --> 00:54:42,330
the list, the minimum value is zero. so the
value the minimum value itself is zero, but
493
00:54:42,330 --> 00:54:49,619
that appears in position three. So when when
this procedure will end, the min value will
494
00:54:49,619 --> 00:54:58,490
contain zero and the ID x which is the position
at which the value the minimum value was achieved
495
00:54:58,490 --> 00:55:04,130
that will contain three So, not only we are
not only we are finding out the minimum value,
496
00:55:04,130 --> 00:55:08,290
but also we are finding out the position of
the minimum value.
497
00:55:08,290 --> 00:55:16,290
This procedure, our pseudocode actually describes
a very simple, very simple concept, you consider
498
00:55:16,290 --> 00:55:20,580
the very first value as a minimum value and
the very first position as a position of the
499
00:55:20,580 --> 00:55:27,450
minimum value, and then traverse the list
element by element and, and see if you find
500
00:55:27,450 --> 00:55:34,619
any value that is smaller than the minimum
value so far, if that is found, then replace
501
00:55:34,619 --> 00:55:40,740
your minimum value with the new minimum value
and update your position number. And then
502
00:55:40,740 --> 00:55:46,970
keep on moving till the end of the list. So,
so that's what, that's the concept behind
503
00:55:46,970 --> 00:55:52,580
the behind this algorithm searching minimum
from the list. And to traverse the list we
504
00:55:52,580 --> 00:55:58,980
use this loop while loop. So next we solve
a problem called sorting problem very, very
505
00:55:58,980 --> 00:56:05,980
famous problem in computer science. So the
problem really is let's say we have a list,
506
00:56:05,980 --> 00:56:15,600
let's say 14035. And seven, let's say and
the sorted order the ascending sorted order
507
00:56:15,600 --> 00:56:22,790
is the order in which the list is presented
so that the minimum value occurs first, then
508
00:56:22,790 --> 00:56:26,630
the second minimum, then the third minimum,
and so on. So the sorted order for this particular
509
00:56:26,630 --> 00:56:32,650
list will be this, so this is the result,
this should be the result of this sorting
510
00:56:32,650 --> 00:56:39,220
procedure. So let's see how can we solve this
problem, we named this algorithm as sorted
511
00:56:39,220 --> 00:56:48,190
list and sorted list contains this L. In this
particular case, the L is simply this. And
512
00:56:48,190 --> 00:56:55,100
this n is the size of the list. In this particular
case, the size of the list is six, so six,
513
00:56:55,100 --> 00:57:00,201
and right now l two is empty. So although
we have to populate l two, but right now it
514
00:57:00,201 --> 00:57:06,560
is empty. And counter again, we initialize
the counter with one. And as as long as the
515
00:57:06,560 --> 00:57:16,060
Conqueror is smaller than six, we keep on
we keep on moving inside this, this block,
516
00:57:16,060 --> 00:57:21,701
that's the that's the body of the loop. So
what we do is we pass the list and the size
517
00:57:21,701 --> 00:57:28,270
of the list. And we use the previous algorithm
to find out the minimum from the list. So
518
00:57:28,270 --> 00:57:33,480
the minimum from the list will be found as
zero and its position will be found as three.
519
00:57:33,480 --> 00:57:39,120
So min value will contain zero, and Id x will
contain three, then what we do, we pick this
520
00:57:39,120 --> 00:57:46,000
minimum value and insert in L two l two was
initially empty. So we insert in L two, we
521
00:57:46,000 --> 00:57:52,000
insert the minimum value, which is zero so
far. And then just in the original list l
522
00:57:52,000 --> 00:57:59,000
we delete the value at the position index.
So for example, the index position is three,
523
00:57:59,000 --> 00:58:05,190
so we delete this particular value. So what
we really do is we delete this value, we delete
524
00:58:05,190 --> 00:58:11,670
this particular value. And the list now becomes
with size 1234 and five, so what we do is
525
00:58:11,670 --> 00:58:18,240
we decrement the size with with one and then
we move on now the country is one again, the
526
00:58:18,240 --> 00:58:23,890
N value rather than six. Now the N value is
five, so one is smaller than five, but the
527
00:58:23,890 --> 00:58:29,210
list has no zero now in it because it was
deleted, we searched the minimum again, and
528
00:58:29,210 --> 00:58:34,680
we insert the minimum in the list. Now the
minimum will be one in the new list. And we
529
00:58:34,680 --> 00:58:40,330
delete that value from the list. And we decrement
the size we keep on moving, eventually the
530
00:58:40,330 --> 00:58:49,220
list l two will be populated like so. And
once. And once this value of n becomes negative,
531
00:58:49,220 --> 00:58:55,180
which is minus one with we will exit the loop
and we will return the sorted list. But see
532
00:58:55,180 --> 00:59:02,980
how this sorting procedure actually uses the
algorithm that we that we defined in in RPB
533
00:59:02,980 --> 00:59:04,900
previous video.
534
00:59:04,900 --> 00:59:09,700
I'm not talking about that this kind of sorting
algorithm is the most famous sorting algorithm.
535
00:59:09,700 --> 00:59:15,480
There are efficient algorithms very great
kind of algorithms for sorting. But the idea
536
00:59:15,480 --> 00:59:22,040
here is not to actually teach sorting the
idea here to actually come up with the pseudocode
537
00:59:22,040 --> 00:59:28,350
for this sorting problem. And also to show
you how you can use the pseudocode how you
538
00:59:28,350 --> 00:59:35,730
can use existing pseudo cores as as instructions
in in other pseudo codes. So that's all about
539
00:59:35,730 --> 00:59:40,369
problem solving. If you really understand
the selection sort and all that procedure
540
00:59:40,369 --> 00:59:45,300
really well, you're actually very good in
problem solving, at least the problem solving
541
00:59:45,300 --> 00:59:50,860
is that we encounter in the logic that we
need to solve different kinds of problems
542
00:59:50,860 --> 00:59:57,410
in computer science. In the next video, I'm
going to actually convert these pseudo codes
543
00:59:57,410 --> 01:00:04,630
to Python codes. What do you need? Doo doo
doo, right this sortlist procedure in actual
544
01:00:04,630 --> 01:00:10,170
python programming language, and how will
you change the search minimum from list in
545
01:00:10,170 --> 01:00:16,420
actual python programming language, we will
see the Python details bit by bit in detail,
546
01:00:16,420 --> 01:00:23,150
starting from right zero and ending at the
very high details of Python. So, in the next
547
01:00:23,150 --> 01:00:26,980
video, I will just be showing you how to convert
this code. But when we will start learning
548
01:00:26,980 --> 01:00:32,460
Python, we will start from zero and we will
see each and everything of, of Python in in
549
01:00:32,460 --> 01:00:41,160
detail. So don't worry. In the next video,
if you see, I mean, things like lengthy chords
550
01:00:41,160 --> 01:00:46,770
in a very beginning, these are just because
we have arrived at a pseudo code. It is very,
551
01:00:46,770 --> 01:00:53,700
I'm just want to show you how the pseudo codes
which are very across expressible, how they
552
01:00:53,700 --> 01:00:59,020
can be easily converted to Python programming,
just to show you the power of and simplicity
553
01:00:59,020 --> 01:01:03,830
of Python programming language. So in the
next video, I'll be converting these pseudo
554
01:01:03,830 --> 01:01:09,770
codes to Python code actual programming code.
So hope to see you in the in the next video.
555
01:01:09,770 --> 01:01:16,180
Okay, in the previous video, we just get a
flavor of problem solving by using this selection
556
01:01:16,180 --> 01:01:24,210
sort called the sorting procedure. The idea
was just to use this procedure to solve this
557
01:01:24,210 --> 01:01:30,540
kind of problem. And we saw in detail, not
in that detail, we just just brushed up but
558
01:01:30,540 --> 01:01:36,700
we saw how to write a pseudocode for solving
a problem of sorting, which requires actually
559
01:01:36,700 --> 01:01:42,010
a list to be sorting in ascending order. For
example, in this video, I'm going to convert
560
01:01:42,010 --> 01:01:47,400
first this code search minimum from list,
you see that code, you know that code completely,
561
01:01:47,400 --> 01:01:51,500
we're first going to convert that code in
Python code, and then we will convert this
562
01:01:51,500 --> 01:01:57,960
code in Python code. So see step by step,
what changes are there. First of all, in Python
563
01:01:57,960 --> 01:02:03,270
that we will see in detail. When you define
procedures, different kinds of procedures,
564
01:02:03,270 --> 01:02:10,250
they are called functions in Python. And rather
than writing this, we have to write a def
565
01:02:10,250 --> 01:02:14,300
statement before it and then whatever name
we want to write out, the rest of the thing
566
01:02:14,300 --> 01:02:19,370
stays the same, except at the very end, we
have to write a colon. That's the syntax of
567
01:02:19,370 --> 01:02:27,600
Python. So the changes from here to here is
a def statement, which defines that is used
568
01:02:27,600 --> 01:02:33,870
for defining def for define. And then at the
end, we write a colon. Next thing that we
569
01:02:33,870 --> 01:02:36,130
will see in detail, don't worry if you
570
01:02:36,130 --> 01:02:41,820
if you're if you just see that why we're messing
up with lips. So early, we will see that things
571
01:02:41,820 --> 01:02:48,980
in detail. But just to compare the in pseudocode.
Normally the lists are indexed the indexes
572
01:02:48,980 --> 01:02:53,480
of the list start from one. But in Python
programming language, the first index of the
573
01:02:53,480 --> 01:02:58,310
list usually starts from zero. So they are
the minimum value was the first value of the
574
01:02:58,310 --> 01:03:02,810
list here, the first value is actually the
index and Python is zero, rest of the things
575
01:03:02,810 --> 01:03:11,180
are same, you declare the variable as in pseudocode.
The same goes exactly in Python. They're the
576
01:03:11,180 --> 01:03:18,940
because the index was one. And so the counter
was one more than whatever the index was.
577
01:03:18,940 --> 01:03:28,250
Here, the counter is simply one, we need to
right here ID x ID x equals to zero that we
578
01:03:28,250 --> 01:03:34,280
just missed. In the previous the ID x is one,
so here the ID x is zero, that's okay. Okay,
579
01:03:34,280 --> 01:03:41,800
then next, we write while counter is less
or equal to n. Same thing while counter is
580
01:03:41,800 --> 01:03:50,900
less or equal to n here. So here we just write
the, the colon at the end, we might have written
581
01:03:50,900 --> 01:03:57,890
this equal sign here, this equal sign, we
just missed the equal sign the equal sign
582
01:03:57,890 --> 01:04:04,260
is there. So now, but see that see the difference
here, the violet goes that way, here we have
583
01:04:04,260 --> 01:04:10,050
a colon at the end, rest of the things are
exactly the same. Now, v is equal to L counter
584
01:04:10,050 --> 01:04:16,050
v is equal to L counter the same thing if
v is less than the minimum value, same thing
585
01:04:16,050 --> 01:04:20,850
if v is less than the minimum value in the
pseudocode. Python is exactly the same. Just
586
01:04:20,850 --> 01:04:25,600
see the colon at the end, we have colon at
the end of the while statement, we have colon
587
01:04:25,600 --> 01:04:30,070
at the end of the definition, we have colon
at the end of the if statement. The other
588
01:04:30,070 --> 01:04:36,930
statement in pseudocode. In Python exactly
the same. Now, in pseudocode, we have l statement.
589
01:04:36,930 --> 01:04:40,080
In Python, we have l statement. If we want
to write an else statement, we have write
590
01:04:40,080 --> 01:04:46,270
a colon at the end of that. Then in Python
in pseudocode, we have a past statement Python
591
01:04:46,270 --> 01:04:51,880
in our past statement, same things in pseudocode.
We have n def, just to describe that this
592
01:04:51,880 --> 01:04:58,140
f ends. In Python, everything is described
by the indentation style. So if this indentation
593
01:04:58,140 --> 01:05:05,480
goes on, if we have If you're here, then this
is goes if this if goes out, so we need not
594
01:05:05,480 --> 01:05:13,141
write ends every day. Similarly, the vile
body has this indentation style, this is all
595
01:05:13,141 --> 01:05:19,830
the while body, whatever that is, that is
earlier than this is not in the wild body.
596
01:05:19,830 --> 01:05:25,150
So, rather than writing the tokens and while
and if the Python handles everything using
597
01:05:25,150 --> 01:05:32,610
indentation, so no need of end if no need
of end while Oh, we haven't, right, we haven't
598
01:05:32,610 --> 01:05:38,440
written a counter here. So we have to write
a counter plus plus here, so counter. So the
599
01:05:38,440 --> 01:05:42,780
same statement, we missed this statement in
the Python code. So the same statement, exactly
600
01:05:42,780 --> 01:05:48,670
the same statement goes here. That's it. The
rest of the story is same, we do not need
601
01:05:48,670 --> 01:05:58,980
an end search here. The goal here is to show
that the pseudocode is, I mean, the way you
602
01:05:58,980 --> 01:06:01,760
write the pseudo codes, they are they're highly,
603
01:06:01,760 --> 01:06:08,690
they highly resemble with the actual code
in Python, Python is that expressive Python
604
01:06:08,690 --> 01:06:14,860
is very, very high level language. I mean,
the way the you the way you think the problem
605
01:06:14,860 --> 01:06:20,820
in the pseudocode, the actual Python code
is much similar to it. So learning the Python
606
01:06:20,820 --> 01:06:25,970
is very, very simple. The simplicity of Python
is really a great property of Python. And
607
01:06:25,970 --> 01:06:31,130
that's one big reason of popularity of, of
Python. Now the return statement is same and
608
01:06:31,130 --> 01:06:36,830
everything is same, then we move toward the
sorting. Again, we have sortlist, we have
609
01:06:36,830 --> 01:06:43,160
to write the Define def define, and then we
have this colon out there, we have to write
610
01:06:43,160 --> 01:06:49,260
the colon there, then let's do is defined
like empty, it's empty in Python as well.
611
01:06:49,260 --> 01:06:57,170
Counter starts from zero, because they are
the list starts from index one. In Python,
612
01:06:57,170 --> 01:07:03,609
the list starts from zero, so we are at zero,
while same as this one. Here we have this
613
01:07:03,609 --> 01:07:09,900
colon, maybe, maybe an equal sign, maybe an
equal sign should appear here. I guess we
614
01:07:09,900 --> 01:07:16,090
are missing an equal sign. But either way,
the code is more or less the same rest this
615
01:07:16,090 --> 01:07:22,480
statement exactly same as this statement,
we have insert in L two, here, we write a
616
01:07:22,480 --> 01:07:30,050
band append function, I'm in Python, here
with ID lead this in Python, we have a Dell
617
01:07:30,050 --> 01:07:35,970
statement, rest of the story is exactly same.
So you see converting pseudocode to Python
618
01:07:35,970 --> 01:07:43,840
code is, is way more easier. This is this
is not a this is not a formal introduction
619
01:07:43,840 --> 01:07:49,660
to Python. I mean, the the goal here in this
video in these kind of session videos is just
620
01:07:49,660 --> 01:07:58,170
to introduce you with problem solving. But
I I found this, I mean, I found this beneficial
621
01:07:58,170 --> 01:08:03,681
to show you that the pseudocode actually resembles
to the actual Python code a lot, although
622
01:08:03,681 --> 01:08:10,780
we will be dealing with variables lists, while
loops, if conditions, all these kind of stuff
623
01:08:10,780 --> 01:08:18,460
in them in a in a big and huge detail. When
we in the upcoming videos, when we will introduce
624
01:08:18,460 --> 01:08:23,679
the Python syntax and variables and all that
kind of stuff. Actually, you will be mastering
625
01:08:23,679 --> 01:08:29,920
each and everything in Python. And, and further,
you may not write these lengthy chords to
626
01:08:29,920 --> 01:08:36,259
do stuff in Python, I mean, the whole dad
thing is just you write l dot sort and you're
627
01:08:36,259 --> 01:08:43,948
done. I mean, you need not write a lot of
lines of codes in Python. Here, I just here
628
01:08:43,948 --> 01:08:48,538
I just showed you that if you have a procedure,
you can, if you have a pseudocode it looks
629
01:08:48,538 --> 01:08:55,508
like much like the same as Python, which,
which actually tells you the expressive power
630
01:08:55,509 --> 01:09:01,179
of Python and simplicity of Python, and how
it is closer to what you think. But the actual
631
01:09:01,179 --> 01:09:03,578
problem solving
632
01:09:03,578 --> 01:09:09,738
in Python does not require so many lines of
codes, I mean, there are so many functions,
633
01:09:09,738 --> 01:09:16,428
so many powerful procedures. For those you
just write one line and a huge amount of work
634
01:09:16,429 --> 01:09:23,029
is done for you. And there are very good one
liners for Python I mean in for for for for
635
01:09:23,029 --> 01:09:28,569
programming in Python, you did not write a
lot of lines of code to do some stuff. I mean
636
01:09:28,569 --> 01:09:33,349
a few lines of code even a single line of
code does a lot for you. And for that you
637
01:09:33,349 --> 01:09:39,350
need to know the features of Python the feature
of the features and the different kinds of
638
01:09:39,350 --> 01:09:45,679
syntax and features and libraries and the
packages and what what is available with Python.
639
01:09:45,679 --> 01:09:51,130
I tell you almost each and everything is available
just you need to know what is available. Once
640
01:09:51,130 --> 01:09:55,820
you know the what what what what are the things
that are available. You need not to write
641
01:09:55,820 --> 01:10:00,500
lengthy codes you need now to build a lot
of logic on yourself. Things are prepared,
642
01:10:00,500 --> 01:10:05,800
they're waiting for you, you just have to
figure them out what are these things to do
643
01:10:05,800 --> 01:10:11,010
what what kind of features are there in Python,
if you know that you are done. So you need
644
01:10:11,010 --> 01:10:15,389
not to be writing these kinds of codes and
lengthy kind of codes. Although knowing that
645
01:10:15,389 --> 01:10:23,280
all knowing that is a is a is a huge advantage,
but doing a bigger and bigger and bigger stuff.
646
01:10:23,280 --> 01:10:29,199
Python will give you a lot of features a lot
of functionality that you need not to go into,
647
01:10:29,199 --> 01:10:34,679
and you need not write a lot of code for it.
And that's the second power of Python. One
648
01:10:34,679 --> 01:10:40,780
is simplicity. Second, it gives you a lot
of features a lot of functionality, a lot
649
01:10:40,780 --> 01:10:46,170
of built in stuff ready for you, you want
to do something, it will be probably there
650
01:10:46,170 --> 01:10:52,969
in Python, you need to know where it is. And
for that we have whole future series on Python
651
01:10:52,969 --> 01:11:00,179
to know Python each and every step in Python,
and to know important packages in Python.
652
01:11:00,179 --> 01:11:05,059
Because knowing important packages and knowing
how to code in Python will save a lot of time
653
01:11:05,059 --> 01:11:10,989
for you. So spending some time on learning
Python will be saving a lot of your time.
654
01:11:10,989 --> 01:11:16,060
To solve the actual pure problem. Whatever
problems you're doing, you're going to solve.
655
01:11:16,060 --> 01:11:20,150
And Python is a real programming language
granting programming language, knowing this
656
01:11:20,150 --> 01:11:27,239
language is almost enough. So hope to see
you in in the next videos where we will start
657
01:11:27,239 --> 01:11:34,240
Python from exactly zero. And we will see
each and everything of Python in detail. Hope
658
01:11:34,240 --> 01:11:41,030
to see you in the next video. If you're new
to data science, you may stuck in choosing
659
01:11:41,030 --> 01:11:47,530
the best language for data science. And in
this video, I'm going to I'm going to talk
660
01:11:47,530 --> 01:11:55,570
about Python, which is the greatest language
so far for data science. To explain the features
661
01:11:55,570 --> 01:12:01,890
of Python, let me first go back to a little
bit history of Python from where it started.
662
01:12:01,890 --> 01:12:09,340
It basically starts in 1980s. It was introduced
first in 1980s. But with constant improvements
663
01:12:09,340 --> 01:12:16,849
and a lot of bug fixes. It was officially
launched in 1989. Nine years later. It was
664
01:12:16,849 --> 01:12:23,639
created by Guido van Rossum and it is open
source which means it is accessible to everyone.
665
01:12:23,639 --> 01:12:30,170
Even though it's open source. It can be used
for commercial purpose. The main goal of Python
666
01:12:30,170 --> 01:12:37,420
was to keep the code easier to use and understand.
Its huge library enables data scientists to
667
01:12:37,420 --> 01:12:46,099
work faster with the ready to use tools it
is dynamically typed. So the variables that
668
01:12:46,099 --> 01:12:50,860
you are defined that you are defining that
they are defined automatically, you need not
669
01:12:50,860 --> 01:12:56,369
to set the type whatever the contents in bring
in, the type will be defined automatically.
670
01:12:56,369 --> 01:13:01,420
It is more readable and uses lesser code to
perform the same task as compared to other
671
01:13:01,420 --> 01:13:09,519
programming languages. It is flexible, portable,
and can run on any platform easily. It is
672
01:13:09,519 --> 01:13:16,739
scalable, and can be integrated with other
third party software easy. Python programming
673
01:13:16,739 --> 01:13:24,989
is easy to use, and has a simple and fast
learning curve. new data scientist can easily
674
01:13:24,989 --> 01:13:32,000
understand Python, but it's easy to use syntax
and better readability. So so that's what
675
01:13:32,000 --> 01:13:36,500
this point is basically it's it's really a
beginner friendly if you if you're new to
676
01:13:36,500 --> 01:13:43,400
programming. Well, Python offers you a very
easy environment to go on. It also provides
677
01:13:43,400 --> 01:13:50,030
plenty of data processing tools that help
in better handling the data. Python is important
678
01:13:50,030 --> 01:13:55,670
for data scientists, because it provides a
vast variety of applications used in data
679
01:13:55,670 --> 01:14:00,540
science, it also provides more flexibility
in the field of machine learning and deep
680
01:14:00,540 --> 01:14:02,039
learning.
681
01:14:02,039 --> 01:14:10,479
It has, it has a lot of packages like TensorFlow,
Kara's tiano. That is helping data scientists
682
01:14:10,479 --> 01:14:17,011
to develop specifically the trending deep
learning algorithms very, very quickly. So
683
01:14:17,011 --> 01:14:24,510
basically, the sport, the sport of machine
learning and deep learning is huge in Python.
684
01:14:24,510 --> 01:14:34,729
That's huge. As, as is the case with many
other programming languages? It's available
685
01:14:34,729 --> 01:14:48,570
libraries that lead to Python success around
around 72,000 available packages. In Python
686
01:14:48,570 --> 01:14:56,820
package index, sometimes called by pi, Python.
Why? Python package index by by around 72,000
687
01:14:56,820 --> 01:15:04,630
packages are available and they are good Constantly.
So huge number of packages mature packages
688
01:15:04,630 --> 01:15:13,179
are available. It is free open source and
consequently, any Can anyone can write a library
689
01:15:13,179 --> 01:15:19,280
package to extend its functionality. Data
Science has become an early beneficiary of
690
01:15:19,280 --> 01:15:28,840
these particularly ponders The Big Daddy of
all of them. The other great thing about Python
691
01:15:28,840 --> 01:15:37,679
is there are millions of users who are happy
to offer advice or suggestions. When you get
692
01:15:37,679 --> 01:15:45,670
stuck in something, chances are someone else
has been stuck there first. So a lot of community
693
01:15:45,670 --> 01:15:51,909
is there, a lot of packages are there, it's
open source it it's easy to use, it's easy
694
01:15:51,909 --> 01:15:58,260
to learn. It's simple, it's readable, more
close to human language, it's high level language,
695
01:15:58,260 --> 01:16:03,590
you code less you do more, I mean, you write
a very few lines of codes, and you achieve
696
01:16:03,590 --> 01:16:13,139
a lot of work. So, I mean, I've spoken a lot
of verbs here, too, too. I mean, explain that
697
01:16:13,139 --> 01:16:19,000
Python really is best suited language for
data science. But let me let me introduce
698
01:16:19,000 --> 01:16:24,750
you some statistics about Python, the popularity
of Python with respect to big with respect
699
01:16:24,750 --> 01:16:32,540
to its use, and with respect to the job opportunities
that are there in Python. So for example,
700
01:16:32,540 --> 01:16:40,960
if you see this chart, in the ranking of top
10, languages, Python stays at the top. So
701
01:16:40,960 --> 01:16:50,949
that's the latest statistic, collected in
2019, February 2019. And out of the out of
702
01:16:50,949 --> 01:16:56,920
the total share of the languages, I mean,
around 26%, just goes for Python, and the
703
01:16:56,920 --> 01:17:02,030
trend is moving up, which means the people
are more interested in Python, I mean, the
704
01:17:02,030 --> 01:17:06,269
trend of using Python is getting larger and
larger, as compared to several other languages
705
01:17:06,269 --> 01:17:15,139
like Java, JavaScript, C, sharp, bhB, C, our
objective c, swift and MATLAB. I mean, many
706
01:17:15,139 --> 01:17:21,360
of them are used for data science, but Python
stays at the top. I mean, this is that popular
707
01:17:21,360 --> 01:17:30,300
language. And further, if you see, for example,
the job opportunities in Python so so that
708
01:17:30,300 --> 01:17:35,800
says, I'm in a different companies like Facebook,
Julia, and I'm in Google and several different
709
01:17:35,800 --> 01:17:43,880
companies. This actually graph shows from
2014 onwards, that the job opportunities and
710
01:17:43,880 --> 01:17:49,570
job postings are in different languages are
at what amount, and you can see the graph
711
01:17:49,570 --> 01:17:57,510
of Python, although starting a bit low, but
then stays up and stays up, which means the
712
01:17:57,510 --> 01:18:07,570
80 if you see the numbers 85% of the total
jobs, there are just for Python. And not only,
713
01:18:07,570 --> 01:18:13,460
I mean, Python is not just for data science,
it's a general purpose programming language,
714
01:18:13,460 --> 01:18:20,479
it's open source, it can be it can be used
to perform any kind of task for embedded programming
715
01:18:20,479 --> 01:18:28,030
for, uh, for for posting, I mean, codes or
embedding code on Raspberry Pi for web development
716
01:18:28,030 --> 01:18:33,300
and whatnot. You can you can, you can do the
desktop development on it, you can use the
717
01:18:33,300 --> 01:18:36,940
web developer knowledge you can use the data
science, I mean, I mean, this is general purpose
718
01:18:36,940 --> 01:18:42,559
programming language. In other disciplines
do it is performing very well. But data science
719
01:18:42,559 --> 01:18:46,690
for data science, it is almost the default
language today.
720
01:18:46,690 --> 01:18:54,809
So, I mean, if you're going to learn data
science, really, we need Python. I mean, Python
721
01:18:54,809 --> 01:19:00,329
really is the choice, the default choice,
and we need it. And in this particular course,
722
01:19:00,329 --> 01:19:06,619
we are going to, we are going to introduce
Python to you with all aspects, I mean, we
723
01:19:06,619 --> 01:19:13,500
will start from the very beginning level.
And we will gradually move towards the very
724
01:19:13,500 --> 01:19:19,290
advanced programming in Python, including
the introduction to the data science packages,
725
01:19:19,290 --> 01:19:26,820
like pandas and matplotlib, for visualizations,
and NumPy, for handling numeric data and stuff
726
01:19:26,820 --> 01:19:32,380
like so. So, in this particular course, we
are really going to teach you Python, and
727
01:19:32,380 --> 01:19:38,239
we are not assuming you have any programming
experience before. So and this is one plus
728
01:19:38,239 --> 01:19:42,719
of Python. I mean, whether you're an engineer,
you're coming from health sciences, you're
729
01:19:42,719 --> 01:19:48,420
coming from biology, you're coming from arts,
humanities, or from wherever. Python is something
730
01:19:48,420 --> 01:19:55,159
that is very easy to get hands on. So if you're
not assuming that you have any programming
731
01:19:55,159 --> 01:20:00,260
background, you have any data science background
nothing. So we will start from the zero and
732
01:20:00,260 --> 01:20:08,340
And we will gradually move to 200. So, and
including the introduction to the data science
733
01:20:08,340 --> 01:20:15,530
packages. So Python is the best, it is a default.
If you're going to work in data science, Python
734
01:20:15,530 --> 01:20:21,989
is the default. And we are going to, we're
going to introduce you Python from the very
735
01:20:21,989 --> 01:20:29,269
beginning to the very professional. So hope
to see you in this course. Okay, before actually
736
01:20:29,269 --> 01:20:39,050
discussing the best ID for Python, and particularly
for data science, let's first discuss what
737
01:20:39,050 --> 01:20:44,800
an ID he is, as you start your coding journey,
many of you prefer coding in a text editor
738
01:20:44,800 --> 01:20:50,080
maybe like notepad plus plus, where you write
the code and then open a terminal window to
739
01:20:50,080 --> 01:20:56,679
execute your code. When there is an error
detected in your code, you switch back to
740
01:20:56,679 --> 01:21:01,100
the text editor, correct your errors, typos
and run the code again in the terminal, everything
741
01:21:01,100 --> 01:21:07,499
is fine. Typically, for large scale problems,
however, you not only have to code but you
742
01:21:07,499 --> 01:21:12,309
also need to make sure your code works in
all scenarios, which means you also need a
743
01:21:12,309 --> 01:21:18,969
testing module. Many times you have multiple
coding and testing files, and switching between
744
01:21:18,969 --> 01:21:28,909
editor and terminal often becomes both confusing
and efficient. So, an environment is needed,
745
01:21:28,909 --> 01:21:37,560
where you can write you can run and play with
your code all at one place. So the one that
746
01:21:37,560 --> 01:21:44,190
provides you with the capability of not just
coding, not just writing the code, but but
747
01:21:44,190 --> 01:21:51,639
also testing your code, running your code
highlighting your syntax, bracket matching,
748
01:21:51,639 --> 01:21:58,780
auto completion, debugging your code, code
suggestions, and and many more features. That
749
01:21:58,780 --> 01:22:08,550
is called an ID II or integrated development
environment. Now, there are several ID is
750
01:22:08,550 --> 01:22:12,630
for different languages for for Python, there
are several ideas for example, Jupyter Notebook
751
01:22:12,630 --> 01:22:20,449
is an ID IE by charm is an ID IE spider is
an IP ID and thought cannot be whim atom and
752
01:22:20,449 --> 01:22:25,610
there are a lot more there are several of
them. Now the question is for data science,
753
01:22:25,610 --> 01:22:34,050
in particular, what Id E is is the best or
are what people suggest to be the best. So
754
01:22:34,050 --> 01:22:39,210
before actually showing you the statistics
that which one is the best before actually
755
01:22:39,210 --> 01:22:43,590
showing you the actual numbers, the statistical
numbers that shows which one is better, what
756
01:22:43,590 --> 01:22:48,420
are the other let me just go through a few
of them few of it ease and their features
757
01:22:48,420 --> 01:22:54,539
and stuff. And then we will move to move to
statistics and some numbers that will show
758
01:22:54,539 --> 01:23:02,849
that which one is better over the other. So
let me start with with this Jupyter Notebook.
759
01:23:02,849 --> 01:23:07,579
For the past couple of years Jupyter Notebook
has been gaining a lot of popularity in terms
760
01:23:07,579 --> 01:23:13,739
of coding and debugging. notebooks have been
redefining the concepts of an ID E and are
761
01:23:13,739 --> 01:23:21,440
adding more and more features on to it. Jupiter
was introduced in 2014 after its predecessor
762
01:23:21,440 --> 01:23:28,539
ipython and from that date, it is really considered
to be a bless in the coding community.
763
01:23:28,539 --> 01:23:35,340
Jupiter stands for I'm in some people say
Jupiter stand for Giulia Python r but that
764
01:23:35,340 --> 01:23:43,440
I come in that acronym does not mean just
this. I mean Jupyter Notebook today is supporting
765
01:23:43,440 --> 01:23:48,699
more than Giulia, Python and R and by the
way, this Giulia Python, R and R all these
766
01:23:48,699 --> 01:23:57,670
are open source languages for and they are
best suited for data science. This Jupyter
767
01:23:57,670 --> 01:24:02,849
Notebook, it has markdown editor. It allows
you to write HTML code, it allows you to write
768
01:24:02,849 --> 01:24:09,820
latex in it. I'm in a lot more. Further this
Jupyter Notebook. It's a web application based
769
01:24:09,820 --> 01:24:15,999
server client structure, which is easy to
use and allows you to create, analyze, and
770
01:24:15,999 --> 01:24:21,809
manipulate documents. And all these documents
are in the form of notebooks. Since it's a
771
01:24:21,809 --> 01:24:27,231
web web interface, it can integrate with many
of the existing web libraries. For example,
772
01:24:27,231 --> 01:24:34,130
for data visualization. Jupiter has so many
functionalities you can write formula using
773
01:24:34,130 --> 01:24:42,389
labtech run a Python code and visualization.
For example, a raw audio signal using matplotlib
774
01:24:42,389 --> 01:24:50,920
plotting library, all in the same notebook.
Jupyter Notebook is not just an idea he but
775
01:24:50,920 --> 01:24:58,400
it's widely used and an educational tool for
presentation and even for writing blogs. You
776
01:24:58,400 --> 01:25:06,929
can export your notebook from iPython Notebook
formats to PDF or to HTML or even to.py, which
777
01:25:06,929 --> 01:25:13,519
is the Python file. The user interface of
Jupiter makes it a favorite tool, especially
778
01:25:13,519 --> 01:25:21,329
amongst the data science community. And one
plus of this Jupiter is, it's it's very quick
779
01:25:21,329 --> 01:25:26,261
to start, I mean, very easy and very quick
to start, I mean, not much rocket science
780
01:25:26,261 --> 01:25:31,449
to write your first goal, you want to write
your HelloWorld it's very, very quick. And
781
01:25:31,449 --> 01:25:40,789
you're better to go and do that. By charm,
if I discuss pi charm, however, if I discuss
782
01:25:40,789 --> 01:25:50,541
some of its properties, and let me just discuss,
first that the pipe the PI charm is by the
783
01:25:50,541 --> 01:25:59,590
company JetBrains. And if you have never used
japin JetBrains other IDs like Java ID, then
784
01:25:59,590 --> 01:26:05,420
running your first code successfully can eat
up a little bit of your time, actually, a
785
01:26:05,420 --> 01:26:12,630
large amount of your time maybe such as I
mean, setting an interpreter by charm. By
786
01:26:12,630 --> 01:26:19,909
charm, however, is, is much better for, for
working with multiple scripts, handling multiple
787
01:26:19,909 --> 01:26:26,800
files and linking them together and huge large
scale coding products. The good thing about
788
01:26:26,800 --> 01:26:33,260
Python is it supports Anaconda. And as a result,
all the packages that fall under Anaconda
789
01:26:33,260 --> 01:26:38,869
are supported by char pi charm as well. And
those packages in including NumPy, Sai, pi
790
01:26:38,869 --> 01:26:44,900
matplotlib, and so on. Just like other IDE
ease pi charm has a powerful debugger. With
791
01:26:44,900 --> 01:26:51,820
a graphical interface. It offers jet integration,
it has skills, shell terminal and worryin
792
01:26:51,820 --> 01:26:58,159
control system. Python, it is customizable,
which allows you to choose between different
793
01:26:58,159 --> 01:27:05,199
themes, color schemes, and key binding and
whatnot. Additionally, Python lets you add
794
01:27:05,199 --> 01:27:10,840
plugins for non pythonic files. And these
plugins take care of indentation highlighting
795
01:27:10,840 --> 01:27:19,709
the errors and keywords just on the fly. So
Python is also providing I mean, a huge support
796
01:27:19,709 --> 01:27:27,540
for coding Python. But, I mean, the one bad
thing about Python, which is not that bad,
797
01:27:27,540 --> 01:27:33,940
but one bad thing is it is memory intensive.
It eats up a lot of memory. It's a heavy thing.
798
01:27:33,940 --> 01:27:41,119
And secondly, I mean getting getting getting
started with PI charm is not that quick. I
799
01:27:41,119 --> 01:27:48,510
mean, it takes a lot of time to just go with
that. Spider however, is a lightweight, open
800
01:27:48,510 --> 01:27:54,780
source ID Oh by the way, this by but this
by charm is is is not I mean it has Professional
801
01:27:54,780 --> 01:28:01,019
Edition and and Community Edition and it does
not open source completely. Spider however,
802
01:28:01,019 --> 01:28:07,760
is a lightweight open source, ie that comes
pre installed with Anaconda. And it was built
803
01:28:07,760 --> 01:28:15,010
mainly for data science practitioners and
engineers. Its look and feel is much like
804
01:28:15,010 --> 01:28:19,699
MATLAB. So if you're a MATLAB programmer,
if you've used MATLAB before, you switch to
805
01:28:19,699 --> 01:28:26,199
Spyder and you get a mean much look and feel
the same cannot be by the way the unthought
806
01:28:26,199 --> 01:28:30,100
cannot be also has roughly the same look and
feel as MATLAB
807
01:28:30,100 --> 01:28:38,730
So, but spider was built for data science
community, it is integrated with essential
808
01:28:38,730 --> 01:28:47,969
data centric libraries like NumPy, Sai, pi,
matplotlib, pandas, ipython, and whatnot.
809
01:28:47,969 --> 01:28:52,840
The built in capabilities can be extended
further by plugins and API's Spyder contains
810
01:28:52,840 --> 01:28:58,880
features like text editor with syntax highlighting
code completion, static code analysis, debugging
811
01:28:58,880 --> 01:29:06,559
variable exploring, it also has profiler that
recursively determines the runtime and number
812
01:29:06,559 --> 01:29:14,920
of calls for every function and methods call
in a file. And I mean, there's no thought
813
01:29:14,920 --> 01:29:21,840
cannot be there is a vendor's atom there are
a whole lot of it is just for Python language.
814
01:29:21,840 --> 01:29:27,760
But But the question really is being a data
scientist, which one is which one should you
815
01:29:27,760 --> 01:29:32,929
choose being a beginner? which one should
you choose? Even even for professionals, if
816
01:29:32,929 --> 01:29:37,750
you want to stay in data science, which ID
he will you prefer over the other? I mean,
817
01:29:37,750 --> 01:29:43,429
there are so many of them. I have just described
three or four of them. So let's see some stats
818
01:29:43,429 --> 01:29:48,690
based on popularity of different IDs for data
science, and then decide which one is better
819
01:29:48,690 --> 01:29:55,170
over the other. So for example, this data
this this analysis, that the chart I'm showing
820
01:29:55,170 --> 01:30:01,579
here, this analysis by was was done by Katie
nuggets and The link for that and it shows
821
01:30:01,579 --> 01:30:12,280
that the most popular Python editors till
December 2018 and you can see that the Jupiter
822
01:30:12,280 --> 01:30:18,409
is at the top, the second is pi charm, then
spider then Visual Studio code and sublime
823
01:30:18,409 --> 01:30:24,540
tags, then add on atom women there are so
many others, but Jupiter is at the top and
824
01:30:24,540 --> 01:30:32,949
this is for I mean, these all are listed with
respect to the data science community. So
825
01:30:32,949 --> 01:30:39,219
in the data science community which Python
ID he is best over the other and, and Jupiter
826
01:30:39,219 --> 01:30:48,789
Jupiter is at the top I mean it is it is way
out. And one reason to this is its simplicity.
827
01:30:48,789 --> 01:30:54,039
It's it's supporting to so many different
formats. It's it makes an interactive document
828
01:30:54,039 --> 01:30:59,060
it makes it makes a web page that is interactive,
you can just change the code you can make
829
01:30:59,060 --> 01:31:04,360
another web page and so on. You can you can
run it on a local system you can run it an
830
01:31:04,360 --> 01:31:10,860
online survey system and whatnot I mean it
has so much flexibility and very quick start
831
01:31:10,860 --> 01:31:19,289
and easy to use. If you for example see the
popularity of Python IDs with respect to the
832
01:31:19,289 --> 01:31:26,070
employment then then you can see overall the
the Jupiter has been a winner as compared
833
01:31:26,070 --> 01:31:33,999
to pi charm spider also your code and sublime
if you see company or self employed still
834
01:31:33,999 --> 01:31:38,780
the Jupiter is V out it has been if you see
for in a student perspective, Jupiter is the
835
01:31:38,780 --> 01:31:45,289
choice. If you go to academia or university,
Jupiter is the choice if you are working with
836
01:31:45,289 --> 01:31:52,909
government or nonprofit Jupiter is the choice
I'm in Jupiter is I mean Jupiter is kind of
837
01:31:52,909 --> 01:32:00,350
outlier it is it is staying at the top everywhere.
Further if you if you analyze the popularity
838
01:32:00,350 --> 01:32:06,969
of Python, it is with respect regions for
example, again, overall, Jupiter is a winner.
839
01:32:06,969 --> 01:32:13,179
If you see US or Canada Jupiter's most popular
mostly used Europe, Jupiter is the winner
840
01:32:13,179 --> 01:32:19,420
Asia, Jupiter is the winner, America use Jupiter
sevinor effect Africa and Middle East Jupiter,
841
01:32:19,420 --> 01:32:27,219
Australia, New Zealand Jupiter. I mean, these
numbers are suggesting that Jupiter is is
842
01:32:27,219 --> 01:32:35,350
at the top, not just at the top. It's easy,
I mean, and maybe that's one reason why Jupiter
843
01:32:35,350 --> 01:32:42,480
stands on the top for the data science. So
these numbers and these all statistics suggest
844
01:32:42,480 --> 01:32:49,429
that we should use Jupyter Notebook for Python.
And we will be doing that. In fact, for this
845
01:32:49,429 --> 01:32:56,080
particular course we'll be working on Jupiter
for all kinds of coding. And in the in the
846
01:32:56,080 --> 01:33:01,110
next video, I will be just showing you how
to install
847
01:33:01,110 --> 01:33:06,340
Jupiter environment how to install basically
Python and how to run Jupiter for the first
848
01:33:06,340 --> 01:33:13,300
time from it. So I hope to see you in the
next video. Okay, in this video, I will show
849
01:33:13,300 --> 01:33:19,920
you how to install Python. There are multiple
ways of installing Python you can go to python.org
850
01:33:19,920 --> 01:33:27,199
and install Python from there I would recommend
to use Anaconda distribution it has Python
851
01:33:27,199 --> 01:33:33,150
it has a lot of packages pre installed it
has Jupyter Notebook as well. So installing
852
01:33:33,150 --> 01:33:37,980
through Anaconda is easier as well. So if
for example if you are working on a Windows
853
01:33:37,980 --> 01:33:42,809
system you should download the executable
for Windows we will be working with Python
854
01:33:42,809 --> 01:33:47,440
three rather than Python two. So you should
be installing you should be downloading Python
855
01:33:47,440 --> 01:33:55,329
three point whatever the latest version is.
Further if your system is 64 bit you should
856
01:33:55,329 --> 01:34:00,670
be installing 64 bit version otherwise you
will be installing 32 bit version. So let's
857
01:34:00,670 --> 01:34:07,429
say you have downloaded the executable file
for Windows then after the download you just
858
01:34:07,429 --> 01:34:12,499
from that xe file and follow the steps and
you'll be able to install Anaconda once the
859
01:34:12,499 --> 01:34:18,479
Anaconda is installed then in the search bar
you just type Anaconda prompt and the Anaconda
860
01:34:18,479 --> 01:34:24,659
prompt kind of symbol that my mouse is pointing
at this will appear in front of you, you just
861
01:34:24,659 --> 01:34:31,420
run it you will see a command prompt like
so. Then in that just type Jupyter Notebook
862
01:34:31,420 --> 01:34:37,420
and press enter and you will be having Jupiter
running in front of you. Let me let me show
863
01:34:37,420 --> 01:34:44,670
you that on my on my system. How to do that.
Let's see. For example, this is my search
864
01:34:44,670 --> 01:34:51,439
bar. Let me type and conda prompt so this
is the Anaconda prompt. So if I click it,
865
01:34:51,439 --> 01:35:03,130
it runs then I just typed for example, Jupiter
note book Then I just press enter. For the
866
01:35:03,130 --> 01:35:11,860
first time it will take some seconds to run.
So let's wait for it. So yes, it runs and
867
01:35:11,860 --> 01:35:18,880
it will show you kind of browser in front
of you. And that's what the Jupiter into interface
868
01:35:18,880 --> 01:35:24,920
is. We will see then how from this Jupiter
how to write the code how to make the code
869
01:35:24,920 --> 01:35:30,679
files and stuff but that's how from Anaconda
installing after installing Anaconda that's
870
01:35:30,679 --> 01:35:38,449
how you will launch the Jupiter. So this is
that easy, no problem. Then, for example,
871
01:35:38,449 --> 01:35:43,960
you can install you can install Python if
you're working on Linux and just download
872
01:35:43,960 --> 01:35:52,780
the version for Linux. And then rather than
For example, let's say your your your file
873
01:35:52,780 --> 01:35:58,239
is downloaded in the Downloads folder then
run this command bash and this.sh that's the
874
01:35:58,239 --> 01:36:02,810
file name. The installer prompts in order
to continue installation process this I'm
875
01:36:02,810 --> 01:36:08,369
in these kinds of commands will will appear
Press Enter to Continue then press Yes, and
876
01:36:08,369 --> 01:36:13,249
the installer will finish with the thanks
message. After that, you just go to downloads
877
01:36:13,249 --> 01:36:19,209
folder and type Jupyter Notebook and the Jupyter
Notebook. interface the browser based interface
878
01:36:19,209 --> 01:36:26,019
will appear in front of you. You can have
if you're if you're working on Mac, you can
879
01:36:26,019 --> 01:36:35,199
you can in you can download the Anaconda distribution
for Mac, then you'll find an anaconda Anaconda
880
01:36:35,199 --> 01:36:41,459
navigator, the launchpad you can launch that
and then just click there's a Jupiter icon
881
01:36:41,459 --> 01:36:45,559
in front of you just press the Launch button
and you'll be having your Jupiter running
882
01:36:45,559 --> 01:36:52,539
in front of you. So in this video, we just
talked about how to install Python. If you
883
01:36:52,539 --> 01:36:57,659
install Python using Anaconda you will be
having Jupyter Notebook as well. In the next
884
01:36:57,659 --> 01:37:04,199
video, we will see how to actually use that
Jupyter Notebook interface for example, I
885
01:37:04,199 --> 01:37:09,110
work on Windows, so I'll be having this kind
of interface although the interface looks
886
01:37:09,110 --> 01:37:14,820
like same because it's a browser based web
based interface. In the next video, I will
887
01:37:14,820 --> 01:37:21,650
show you how to get comfortable with Jupiter
and we will be also writing our first HelloWorld
888
01:37:21,650 --> 01:37:29,090
program in Python. So hope to see you in the
next video. Okay, so in this video, I will
889
01:37:29,090 --> 01:37:31,829
show you
890
01:37:31,829 --> 01:37:38,949
how to write the first program in Python basically
the HelloWorld program. Before that, in the
891
01:37:38,949 --> 01:37:45,260
previous video, I show you I showed you how
to launch Jupyter Notebook. So once you launch
892
01:37:45,260 --> 01:37:49,829
Jupyter Notebook, whether you are working
on Windows, whether you're working on Linux
893
01:37:49,829 --> 01:37:55,199
or Mac, whatever, when you will launch the
Jupyter Notebook, you will see this web based
894
01:37:55,199 --> 01:38:03,110
interface. And here you are in the right corner
you can see the button new, you just click
895
01:38:03,110 --> 01:38:09,530
it, you will select Python three, and you
will see a beautiful interface in front of
896
01:38:09,530 --> 01:38:16,050
you that will allow you to go here, there
are a lot of file edit view there are a lot
897
01:38:16,050 --> 01:38:22,030
of parents kernel and a lot of controls here
we will see them as we move on. But this is
898
01:38:22,030 --> 01:38:27,499
how you this is this is what the coding environment
is this is kind of editor as well as I mean
899
01:38:27,499 --> 01:38:33,429
this is complete, ie interface in front of
you. So let's see this interface a little
900
01:38:33,429 --> 01:38:41,719
bit. Step by step at least the controls that
that we need. First of all, you are seeing
901
01:38:41,719 --> 01:38:48,150
where my cursor is moving. That's the file
name or the notebook name. You can change
902
01:38:48,150 --> 01:38:55,460
the notebook name or you can just write for
example. Whatever the name of the notebook
903
01:38:55,460 --> 01:39:03,550
you want, for example, mastering by Thorne
904
01:39:03,550 --> 01:39:05,300
for
905
01:39:05,300 --> 01:39:16,820
beginners. Okay, so let's say that you're
mastering Python, let's say let's say zero
906
01:39:16,820 --> 01:39:23,249
to hero, maybe. So let's say this is your
filing, you just create that file and you'll
907
01:39:23,249 --> 01:39:31,650
see this mastering Python zero to hero that
file is created with this file is renamed.
908
01:39:31,650 --> 01:39:39,800
Second. This is a cell in which you are going
to type your code. The code, I mean, the two
909
01:39:39,800 --> 01:39:46,179
modes of writing is one is you can write the
Python code. Another way is you can write
910
01:39:46,179 --> 01:39:53,219
the markdown. The markdown is important in
in a way that if you want to describe your
911
01:39:53,219 --> 01:39:58,979
code, if you want to write other stuff other
than Python code, you can use these markdown
912
01:39:58,979 --> 01:40:07,760
cells and they We will be helping you. For
example, if I select this markdown, and I
913
01:40:07,760 --> 01:40:16,520
just select this markdown, and I type here,
for example,
914
01:40:16,520 --> 01:40:35,030
this is by THON directorial. And then I press
Shift Enter, it will appear as a heading.
915
01:40:35,030 --> 01:40:39,900
And a new cell will be graded down. This is
also a cell. But this is a markdown cell.
916
01:40:39,900 --> 01:40:45,739
As you can see, now in this cell, that's a
code cell, you can switch a cell from code
917
01:40:45,739 --> 01:40:52,050
to markdown by just pressing an escape key,
when you press an escape key, you will see
918
01:40:52,050 --> 01:40:58,139
the color will change here, you can press
Escape key, then if you press M, it will change
919
01:40:58,139 --> 01:41:07,479
to markdown. And if you press Y, it will change
to a code cell. There are several I mean shortcuts
920
01:41:07,479 --> 01:41:12,519
that are available keyboard shortcuts, if
you if you just see, if you go to help and
921
01:41:12,519 --> 01:41:17,409
see this keyboard shortcuts, there are several
shortcuts that will be available in front
922
01:41:17,409 --> 01:41:24,090
of us. For example, if you press escape, and
then press F, you can do the Find and Replace
923
01:41:24,090 --> 01:41:30,699
operation. And if you press enter, then that
will go into Edit Edit Mode, if that's important,
924
01:41:30,699 --> 01:41:37,670
if you press Shift, enter, the cell will run
and the new the cursor will go into the new
925
01:41:37,670 --> 01:41:43,670
cell. And there are a lot of controls you
should be seeing most of them, I mean, getting
926
01:41:43,670 --> 01:41:50,099
a good grip on these controls will help you
moving in this Jupyter Notebook very quickly.
927
01:41:50,099 --> 01:41:55,519
So for example, this is a Python tutorial
that's a markdown cell, you can also create
928
01:41:55,519 --> 01:42:05,439
this, this cell also as a markdown cell. And
then you can type here for example. This is
929
01:42:05,439 --> 01:42:22,459
our first program in Python. It there it is
just started here, for example, and it just
930
01:42:22,459 --> 01:42:28,969
appears like like a description. And again,
a new cell is created down and there you can
931
01:42:28,969 --> 01:42:36,940
write your code. So let's write the first
Python code HelloWorld. So first of all, you
932
01:42:36,940 --> 01:42:44,689
will write Brent Brent command will allow
you to print anything on the screen. brantas
933
01:42:44,689 --> 01:42:52,110
says double codes, starts ends. And in the
double code, you write whatever you want to
934
01:42:52,110 --> 01:42:58,159
be printed on the screen, for example. Hello,
935
01:42:58,159 --> 01:43:00,050
world.
936
01:43:00,050 --> 01:43:06,920
And once you have written that code, just
press Shift and enter, and this code will
937
01:43:06,920 --> 01:43:14,290
execute in front of you. So that's HelloWorld
printed in front of you. And that's our first
938
01:43:14,290 --> 01:43:22,550
program, I mean, writing the very first program
in Jupyter Notebook. is is that easy. Not
939
01:43:22,550 --> 01:43:29,159
only that, this Jupyter Notebook will be created,
you can you can just I mean describe anything,
940
01:43:29,159 --> 01:43:37,150
you can write the headings, you can write
HTML in it, you can write math, using lattic.
941
01:43:37,150 --> 01:43:42,749
And for example, let me let me write lattic,
or mat in front of you just just let's say
942
01:43:42,749 --> 01:43:49,179
you're making a notebook that requires some
mathematics in it. And it allows you to write
943
01:43:49,179 --> 01:44:00,559
mathematics as well. For example, A equals
B plus C, Shift Enter, and that appears like
944
01:44:00,559 --> 01:44:07,889
a mathematical equation, not just this, you
can write very complicated equations. I mean,
945
01:44:07,889 --> 01:44:14,920
and and, and this whole notebook will contain
your descriptions in terms of HTML or latech,
946
01:44:14,920 --> 01:44:21,800
or descriptions, and code and all that mixed
up, whatever. And at the end, you will, you
947
01:44:21,800 --> 01:44:31,630
can, you can just download this. You can just
download this, this notebook, as if you want
948
01:44:31,630 --> 01:44:35,729
a PDF file PDF file. If you want a notebook
file, it's an output file if you want to latech
949
01:44:35,729 --> 01:44:40,570
if you want just a Python file if you want
slides, for example. I mean, you can download
950
01:44:40,570 --> 01:44:45,989
the same thing as slides. It will make slides
for you. So there are a lot of ways of using
951
01:44:45,989 --> 01:44:50,889
this notebook. And that's a ready made document.
I mean, you end coding, the document is ready
952
01:44:50,889 --> 01:44:57,809
for you. So this notebook is really, really
powerful Jupyter Notebook and coding in it
953
01:44:57,809 --> 01:45:03,019
is not just the coding. I mean, it is Preparing
a document. If you want to prepare a document,
954
01:45:03,019 --> 01:45:07,540
you want to describe anything you want to
add images, and at the end of the day, it
955
01:45:07,540 --> 01:45:14,249
will be an HTML document for you. It can be
shared on web. I mean, it's ready. Nothing
956
01:45:14,249 --> 01:45:21,670
we we want to further finish it. So that was
our HelloWorld program in Python. We will
957
01:45:21,670 --> 01:45:28,869
continue to build this byte mastering Python
zero to hero notebook, we will continue coding
958
01:45:28,869 --> 01:45:33,489
in that we will describe the headings we will
write the markdown cells and all that stuff.
959
01:45:33,489 --> 01:45:38,059
And we will at the end of this course, you
will be having one notebook with all kinds
960
01:45:38,059 --> 01:45:44,360
of descriptions and code in it. You can use
that notebook afterwards, we will be building
961
01:45:44,360 --> 01:45:50,409
well one notebook, one complete notebook for
Python. So that's about it. That's the hello
962
01:45:50,409 --> 01:45:59,030
world. In the next video, we will see how
to what are what are the constructs in in
963
01:45:59,030 --> 01:46:05,590
Python, what are variables and other stuff.
But before that, I also wanted to show that
964
01:46:05,590 --> 01:46:12,190
this notebook is an enhanced worryin are the
upgraded version of ipython shell. And I also
965
01:46:12,190 --> 01:46:19,380
want to show you ipython shell as well. So
in the next video, we will just see the ipython
966
01:46:19,380 --> 01:46:26,219
shell and we will see how can we how can we
view Python as just as a calculator by using
967
01:46:26,219 --> 01:46:31,979
ipython shell. So hope to see you in the next
video. Okay, so in this particular video,
968
01:46:31,979 --> 01:46:40,900
I'm going to show you the ipython shell just
open up the Anaconda prompt as as before,
969
01:46:40,900 --> 01:46:46,969
like you want to open a Jupyter Notebook,
then you just type here Jupyter Notebook.
970
01:46:46,969 --> 01:46:52,090
And you will be you will be in the in the
notebook word Jupyter Notebook word. But if
971
01:46:52,090 --> 01:47:01,889
you just type in ipython and press enter,
then a prompt is open for you in a colored
972
01:47:01,889 --> 01:47:09,170
way. And this is perfectly fine to write any
kind of Python code in here. Actually, the
973
01:47:09,170 --> 01:47:15,729
Jupyter Notebook is more enhanced and more
featured the use of ipython. Basically everything
974
01:47:15,729 --> 01:47:20,630
that I bought, that is there in ipython is
there in Jupyter Notebook as well. But it
975
01:47:20,630 --> 01:47:28,199
has more features more documentation and stuff.
So for example, if I just write a Python code
976
01:47:28,199 --> 01:47:29,199
here,
977
01:47:29,199 --> 01:47:36,909
hello world, let's say it will work in ipython
shell as well. But remember, previously in
978
01:47:36,909 --> 01:47:41,920
in Jupyter Notebook, we type Shift Enter to
run a particular command here, we just press
979
01:47:41,920 --> 01:47:47,920
enter and everything will work. If you want
to clear the screen here, whatever the whatever
980
01:47:47,920 --> 01:47:53,340
we typed here, if you want to clear that,
just press Ctrl l if you're on Windows Ctrl
981
01:47:53,340 --> 01:48:01,219
l will work on Windows. Now ipython is just
like, you can use the Python in this particular
982
01:48:01,219 --> 01:48:06,780
shell just like a calculator, for example,
you want to plus three, press enter, that's
983
01:48:06,780 --> 01:48:16,429
five, let's say it's nine multiplied by seven,
the answer is 63. You can write a complicated
984
01:48:16,429 --> 01:48:26,510
statement as well, for example, 45 minus eight
is static, or multiplication, static is achieved
985
01:48:26,510 --> 01:48:35,689
by multiplication is achieved by a static
symbol seven. And then you can have this minus
986
01:48:35,689 --> 01:48:45,249
then divided by two and just press Enter.
And that's the answer 16.0. If for example,
987
01:48:45,249 --> 01:48:51,381
by the way, I have just press the up arrow
key and last command just appears. I have
988
01:48:51,381 --> 01:48:56,550
pressed up arrow key again. And the second
last command appears. I press the up arrow
989
01:48:56,550 --> 01:49:01,719
key again and the third last command appears
and now I'm pressing the down arrow keys.
990
01:49:01,719 --> 01:49:11,610
So for example this and you may have whatever
the result is, you may have that multiplied
991
01:49:11,610 --> 01:49:26,650
by 10 and minus or or maybe plus plus 15.
So the result is minus 145, and so on. So
992
01:49:26,650 --> 01:49:34,030
this Python ipython shell, you can write very
complicated are almost I mean, the complete
993
01:49:34,030 --> 01:49:40,239
Python coding can be written in ipython shell.
And you can use this shell just for a calculator.
994
01:49:40,239 --> 01:49:51,199
Now let let's see, for example, you you compute
this result, let's say 45 minus 45 minus nine
995
01:49:51,199 --> 01:49:55,480
and let's say you compute this result, whatever
the result is, and you save that result in
996
01:49:55,480 --> 01:50:01,239
a symbol, let me call that symbol as a variable.
In here the variable is So let's say you save
997
01:50:01,239 --> 01:50:10,059
that in a, and then you have another variable,
let's say B, and three static 45, or maybe
998
01:50:10,059 --> 01:50:18,510
three steric 2.6, that is saved in B. Now,
you have you have done this particular calculation,
999
01:50:18,510 --> 01:50:25,669
you know that 45 minus nine is in a, the result
is in a, and then you have this particular
1000
01:50:25,669 --> 01:50:30,520
result that is in B. And now, you just want
to add the two results together, and you want
1001
01:50:30,520 --> 01:50:35,510
to print the
1002
01:50:35,510 --> 01:50:41,260
what what normal calculators does not have
the support of saving the results and reusing
1003
01:50:41,260 --> 01:50:48,289
them. But here in Python, even if you just
want to use the Python, just as a calculator,
1004
01:50:48,289 --> 01:50:53,600
you can declare as many variables as you can
and you can save the previous results, you
1005
01:50:53,600 --> 01:50:59,600
can retrieve the previous results. And you
can use the previous results, save new results
1006
01:50:59,600 --> 01:51:06,190
and so on. These kind of symbols that are
used to save the results, and then they can
1007
01:51:06,190 --> 01:51:13,329
be just used afterwards, these are called
variables. And our next video will be on variables,
1008
01:51:13,329 --> 01:51:18,249
what are these variables, what are the types,
what kind of variables the Python supports
1009
01:51:18,249 --> 01:51:22,619
one way or the other, if you want to go beyond
calculators, you need certain results to be
1010
01:51:22,619 --> 01:51:28,579
saved and retrieved retrieved afterwards.
And the variables are are the constructs the
1011
01:51:28,579 --> 01:51:34,750
variables are the features that actually do
that. So the calculator is fine, you can use
1012
01:51:34,750 --> 01:51:41,099
this ipython shell just as a calculator. But
if you want to do interesting programming,
1013
01:51:41,099 --> 01:51:45,959
complicated programs, I mean, you want to
achieve a task that involves much more calculations
1014
01:51:45,959 --> 01:51:51,489
one way or the other, you have to save certain
results in somewhere. And then you have to
1015
01:51:51,489 --> 01:51:56,439
combine the results together because the longer
problems in normally are broken up into smaller
1016
01:51:56,439 --> 01:52:01,860
piece of problems. And each smaller problem
has a result that should be saved somewhere
1017
01:52:01,860 --> 01:52:07,900
and afterwards the several results they should
be combined to achieve the result that we
1018
01:52:07,900 --> 01:52:11,530
are after. So these variables are required
if you are going to do some interesting or
1019
01:52:11,530 --> 01:52:20,719
complicated calculations or computations.
So you, by the way before, before having these
1020
01:52:20,719 --> 01:52:25,860
Jupyter Notebooks spit out just the enhanced
version of this ipython shell, the iPod ipython
1021
01:52:25,860 --> 01:52:32,360
shell just people used to write a lot of Python
programming just in ipython shell. And even
1022
01:52:32,360 --> 01:52:40,459
even today is several people are writing their
code complete code in ipython shell. But the
1023
01:52:40,459 --> 01:52:47,059
the Jupyter Notebook is more enhanced for
the enmore documented more, I mean, it has
1024
01:52:47,059 --> 01:52:53,850
better interfaces and several features that
are better than just using ipython shell.
1025
01:52:53,850 --> 01:52:59,119
So you have seen this ipython shell, it's
very powerful, great, everything is fine with
1026
01:52:59,119 --> 01:53:06,400
it. But we will be using Jupyter notebooks,
which are just the enhanced variants of this
1027
01:53:06,400 --> 01:53:14,869
ipython for our upcoming coding. So the purpose
of this video was just to was just to introduce
1028
01:53:14,869 --> 01:53:19,749
you with ipython shell and just to tell you
that you can use Python just as a calculator
1029
01:53:19,749 --> 01:53:25,900
and even more than that, and in the next video,
we will be introducing variables in Jupyter
1030
01:53:25,900 --> 01:53:31,659
Notebook and we will see the Python or Python
is really really much more powerful than just
1031
01:53:31,659 --> 01:53:37,400
a calculator. So hope to see you in the next
video. Okay, in this video, we will talk about
1032
01:53:37,400 --> 01:53:45,289
variables and operators the operations that
you can perform on on variables. A variable
1033
01:53:45,289 --> 01:53:53,659
in a very layman term is basically a symbol
that stores some data that can be used later
1034
01:53:53,659 --> 01:54:02,790
on. So for example, this x is a symbol corrector
or a symbol y is a symbol x y is a symbol
1035
01:54:02,790 --> 01:54:07,889
normally, and these are called names of the
variables. For example, this is a variable
1036
01:54:07,889 --> 01:54:15,769
name x, y is a variable name y, x y is a variable
name itself. Now, these variables, they can
1037
01:54:15,769 --> 01:54:21,880
store different kinds of data, I mean, whenever
you want a particular data to be used again
1038
01:54:21,880 --> 01:54:29,409
and again, it is better to save that data
or label that data by a symbol by a descriptive
1039
01:54:29,409 --> 01:54:37,999
name so that you can retrieve that team retrieve
that data by using that label or symbol. So
1040
01:54:37,999 --> 01:54:42,360
one way or the other. This this variable actually
is a description of the data that you want
1041
01:54:42,360 --> 01:54:50,380
to use our store and you want to use later
on in your program. Different types of data
1042
01:54:50,380 --> 01:54:55,739
are there, for example, the integer type data.
1043
01:54:55,739 --> 01:55:01,080
For example, if the data you want to store
is integer type, it's a number And the number
1044
01:55:01,080 --> 01:55:08,119
is just the integer number it does not have
a decimal point expansion that is a type of
1045
01:55:08,119 --> 01:55:14,709
data and that can be stored in a variable
in that in that case, the variable type itself
1046
01:55:14,709 --> 01:55:21,329
will be integer, you need not to specify the
type of variable when you are storing the
1047
01:55:21,329 --> 01:55:26,789
data to it the storing data to a variable
is sometimes called assigning data to a variable
1048
01:55:26,789 --> 01:55:33,409
or assignment. For example, if your variable
is x, and you are assigning a value let's
1049
01:55:33,409 --> 01:55:40,969
say two, then two is integer value its integer
it does not have a decimal expansion and when
1050
01:55:40,969 --> 01:55:49,260
to is assigned to x, based on the content
to that to basically is an integer type value,
1051
01:55:49,260 --> 01:55:55,249
automatically this the type of x is set to
be integer. And that is sometimes called the
1052
01:55:55,249 --> 01:56:01,699
dynamically typed Python is dynamically typed
language or dynamic typing, you need not to
1053
01:56:01,699 --> 01:56:07,249
specify the type of the variable the contents
that you are assigning to a variable, they
1054
01:56:07,249 --> 01:56:13,939
will define the type of the variable on the
fly. And the assignment for example, in here
1055
01:56:13,939 --> 01:56:20,789
I'm storing two insight x and next time if
I want to print for example, what is there
1056
01:56:20,789 --> 01:56:27,729
in x the the print value will be two. Now,
this kind of symbol is hot right there is
1057
01:56:27,729 --> 01:56:34,059
no keyboard symbol that looks like so, so
rather than writing this symbol for assignment,
1058
01:56:34,059 --> 01:56:39,780
normally an equal sign symbol is used for
assignment for example, x is equal to two
1059
01:56:39,780 --> 01:56:44,929
that means two is assigned in x five is equal
five is equal to five means five is assigned
1060
01:56:44,929 --> 01:56:52,150
in y 7.2 equal x y equals 7.2x y is completely
a new variable, it has nothing to do with
1061
01:56:52,150 --> 01:57:00,650
x or y. And it is handy sometimes to to to
suggest the name of the variables that are
1062
01:57:00,650 --> 01:57:05,469
too descriptive that are very, very descriptive
to increase the readability and management
1063
01:57:05,469 --> 01:57:09,760
of the code, because later on you will you
will be seeing when you will be working in
1064
01:57:09,760 --> 01:57:15,370
data science and other stuff. The programs
that you will be writing might not be very
1065
01:57:15,370 --> 01:57:20,539
short programs, they might be lengthy programs.
So readability of a program and management
1066
01:57:20,539 --> 01:57:28,820
of a program becomes an issue if you if you
if you do not assign the names of the variables
1067
01:57:28,820 --> 01:57:35,110
carefully. However, if you write the names
very in a very descriptive way, by just writing
1068
01:57:35,110 --> 01:57:40,829
the name of the variable by just creating
the variable symbol or or or the name, it
1069
01:57:40,829 --> 01:57:45,610
tells a better look and feel of what kind
of data inside and what should I do with that.
1070
01:57:45,610 --> 01:57:51,550
So, I was talking about this equal sign this
equal sign is used for assignment. Here for
1071
01:57:51,550 --> 01:57:58,650
examples when 7.2 is assigned to a variable
x y, automatically the type of x y variable
1072
01:57:58,650 --> 01:58:04,090
is set to be a floating point integer floating
point number a float is a data type in in
1073
01:58:04,090 --> 01:58:11,479
Python that describes that the particular
data is a real valued it may have a decimal
1074
01:58:11,479 --> 01:58:18,820
expansion as well not just integer and floats
are the only data types in Python, there are
1075
01:58:18,820 --> 01:58:24,579
several others for example, you can define
complex numbers if you if you want to you
1076
01:58:24,579 --> 01:58:29,550
can for example, defining a complex number
might be for example, you write the name of
1077
01:58:29,550 --> 01:58:37,599
C and you write two plus four j if you write
the symbol j here, it automatically becomes
1078
01:58:37,599 --> 01:58:43,099
complex. And now you can you can use this
see the way the complex numbers should be
1079
01:58:43,099 --> 01:58:50,849
created. Similarly, there are other data types
like fractions decimals, there are there are
1080
01:58:50,849 --> 01:58:59,050
further data types, the objects called strings.
For example, if you if you if you assign let's
1081
01:58:59,050 --> 01:59:05,610
say s equals double quotes Hello
1082
01:59:05,610 --> 01:59:12,919
then that S is also a variable and the type
of this variable a string string is just a
1083
01:59:12,919 --> 01:59:17,789
sequence of a lot of collectors, where he
is a collector is a collector L is a collector
1084
01:59:17,789 --> 01:59:23,599
L is a collector always a collector W is a
vector. And when we will define anything,
1085
01:59:23,599 --> 01:59:28,439
any sequence of characters inside the double
quotes and then ended the double quotes here,
1086
01:59:28,439 --> 01:59:33,960
or the single quotes, single quotes and double
course either way, then the type of this is
1087
01:59:33,960 --> 01:59:39,280
become strings. And these characters should
be created as it is. Like for example, if
1088
01:59:39,280 --> 01:59:45,999
we have another variable s two and we just
say one, two, in double quotes. Now this s
1089
01:59:45,999 --> 01:59:50,980
two is no longer 12 as an integer. It is a
sequence of characters where first character
1090
01:59:50,980 --> 01:59:57,070
is one and other graduates two, we will talk
about strings in detail in the upcoming videos
1091
01:59:57,070 --> 02:00:03,769
but just to give you a look and feel that
Python actually supports a lot of data types,
1092
02:00:03,769 --> 02:00:08,380
a lot of interesting data types including
the most important data type is integer float
1093
02:00:08,380 --> 02:00:15,739
and string as well that we will see in detail.
Further you can assign you can assign more
1094
02:00:15,739 --> 02:00:20,539
than one values to more than one variables
in in a single line there is sometimes called
1095
02:00:20,539 --> 02:00:27,510
multiple assignment. For example, if you write
a comma b equals four comma 5.00, then four
1096
02:00:27,510 --> 02:00:34,619
will be assigned to a and 5.0 will be assigned
to B. notice one thing although 5.0 looks
1097
02:00:34,619 --> 02:00:39,960
like an integer, but when you when you write
a decimal expansion, it automatically becomes
1098
02:00:39,960 --> 02:00:45,340
float. So, if you Now type the type, if you
now check the type of a it will be integer
1099
02:00:45,340 --> 02:00:51,719
and if you check the type of B it will be
float. Once you have declared a lot of variables,
1100
02:00:51,719 --> 02:00:59,090
they stay in the memory they occupy a particular
space inside the memory. For example, x is
1101
02:00:59,090 --> 02:01:05,880
just a label to a memory inside the memory
that is to located somewhere. Similarly, y
1102
02:01:05,880 --> 02:01:12,940
is also located somewhere in memory. And similarly
x y is also located somewhere in memory. And
1103
02:01:12,940 --> 02:01:18,010
this is the data inside that memory. These
will stay in the memory and the occupy the
1104
02:01:18,010 --> 02:01:23,829
memory. If you if you decide to no longer
use a particular variable and future in the
1105
02:01:23,829 --> 02:01:29,369
in the program, then you can call this function
d l space, whatever the variable name, and
1106
02:01:29,369 --> 02:01:36,309
it will delete the it will delete the variable
from the memory like it was never there. And
1107
02:01:36,309 --> 02:01:40,420
once the variable is no longer in memory,
it is it is not accessible. If you now access
1108
02:01:40,420 --> 02:01:46,050
the variable again, you will get an error.
Let's see all these concepts. Let let's see
1109
02:01:46,050 --> 02:01:53,909
most of these concepts in Jupyter Notebook
and let's let's actually, let's let's actually
1110
02:01:53,909 --> 02:02:00,800
define certain variables, use them, print
them, do some multiple assignment and see
1111
02:02:00,800 --> 02:02:07,260
a lot of stuff in in Jupyter Notebook. So
let's go to Jupyter Notebook. So that was
1112
02:02:07,260 --> 02:02:14,139
our notebook that we were doing, that we were
actually working on the last time. So let's
1113
02:02:14,139 --> 02:02:24,829
say I define a variable X, let's say x is
two. Why not? Why not? I should describe this.
1114
02:02:24,829 --> 02:02:38,099
as what we are doing here is let's say variables.
So just to give a heading that we are now
1115
02:02:38,099 --> 02:02:44,389
in variables, so variables, notice that now
I'm in a code cell. Previously I was in a
1116
02:02:44,389 --> 02:02:48,939
markdown cell, notice this change in this
particular cell, this is markdown in this
1117
02:02:48,939 --> 02:02:56,360
particular cell, this is code cell, C that
goes, Okay, x is equal to let's say, three,
1118
02:02:56,360 --> 02:03:06,820
let's into this. Now x is assigned a value
three. If you want to know how many variables
1119
02:03:06,820 --> 02:03:13,639
right now are there in the memory, we can
write this command whose This is a percentage
1120
02:03:13,639 --> 02:03:18,669
symbol, if you write percent a symbol and
then just type a command, w h o s, it will
1121
02:03:18,669 --> 02:03:23,380
tell you all the variables that are on right
now that are there in the memory. And right
1122
02:03:23,380 --> 02:03:30,570
now the memory has a variable with name x,
its type is integer, and the data inside the
1123
02:03:30,570 --> 02:03:36,579
variable is three, that's the memory view
that you're now seeing. Okay, if you want
1124
02:03:36,579 --> 02:03:43,780
to explicitly check the type of x, you can
print type x. So for example, this function
1125
02:03:43,780 --> 02:03:50,449
type will will actually find out the type
of whatever variable you give inside and then
1126
02:03:50,449 --> 02:03:56,380
this print function will help you printing
that on on the notebook. So if you see the
1127
02:03:56,380 --> 02:04:03,579
type of x, the type is basically its integer
type. Now,
1128
02:04:03,579 --> 02:04:11,869
if you for example, change the value of x
as three to let's say, 5.7. So you have same
1129
02:04:11,869 --> 02:04:20,889
variable, but you just change the value from
three to 5.7. So let's see what happens now.
1130
02:04:20,889 --> 02:04:30,510
So if we call us again, we have now the variable
name is still x, but its type automatically
1131
02:04:30,510 --> 02:04:35,220
it's type automatically change to floating
point number, because of because we assign
1132
02:04:35,220 --> 02:04:39,469
a floating point number to it. And this is
the data if we want to explicitly check the
1133
02:04:39,469 --> 02:04:51,730
type of this x, that would be class float
now, further. Let's say we have another variable
1134
02:04:51,730 --> 02:05:02,739
ABCD. That's a variable name, let's say and
we assign a value 55 six Point, three, two,
1135
02:05:02,739 --> 02:05:09,209
that's that's the value. If we now called
whose function whose command, we will be having
1136
02:05:09,209 --> 02:05:16,030
two particular values, one variable as ABCD,
its type is float. another variable is x,
1137
02:05:16,030 --> 02:05:23,010
its type is float, and that is there. If we,
for example, do a multiple assignment, for
1138
02:05:23,010 --> 02:05:27,840
example, a comma, when you write comma, first
variable finishes, second variable starts
1139
02:05:27,840 --> 02:05:36,499
A, B, C, D, F, let's say these are five variables.
And if you assign five values to five variables,
1140
02:05:36,499 --> 02:05:52,130
again in a comma separated list, 356, point
07, point two, and let's say minus three.
1141
02:05:52,130 --> 02:05:57,880
So if you enter that, and you now check the
status of the memory, because now all these
1142
02:05:57,880 --> 02:06:06,099
values are assigned to the respective variables,
if you now check the memory view, a is an
1143
02:06:06,099 --> 02:06:12,550
integer type variable with value three ABCD,
the old variable that we assigned earlier,
1144
02:06:12,550 --> 02:06:18,010
it's already float B is also integer, it has
value five sees float, sees float all those
1145
02:06:18,010 --> 02:06:23,860
6.0 looks looks much like integer. But when
you when you write a point explicitly, it
1146
02:06:23,860 --> 02:06:31,130
becomes it becomes a floating point number.
So D is again, float with 7.2, f is integer,
1147
02:06:31,130 --> 02:06:36,710
it's minus five. And x is the old old variable
that we know already. Now, if we, for example,
1148
02:06:36,710 --> 02:06:41,869
delete a particular variable, if we for example,
we we no longer want to use ABCD variable
1149
02:06:41,869 --> 02:06:48,949
ABCD. That's one variable that we don't want
to use in future. And now if we see again,
1150
02:06:48,949 --> 02:06:56,519
the view of the memory, we don't have this
and if we now want to access this, for example,
1151
02:06:56,519 --> 02:07:01,959
if we want to print this ABCD, we will get
an error, we will get an error and we should
1152
02:07:01,959 --> 02:07:06,649
we should get an error because this particular
variable does not exist in the memory, it
1153
02:07:06,649 --> 02:07:14,860
points to no data, it has gone, it has gone
like it was never, it was never there. So
1154
02:07:14,860 --> 02:07:21,860
that's about the variables. We just talked
about integer and float, there are several
1155
02:07:21,860 --> 02:07:28,170
other variable types as well. For example,
let me just give you an example of an example
1156
02:07:28,170 --> 02:07:33,939
of a complex number, if you are really interested
in that's a complex number if you print its
1157
02:07:33,939 --> 02:07:45,669
type so that the type is complex. Similarly,
you can have a string variable, let's say
1158
02:07:45,669 --> 02:07:56,439
hello, how are you? That's a string variable,
if you bring the type of this you will get
1159
02:07:56,439 --> 02:08:03,130
a string we will we have a whole set of videos
just on string data type, because this is
1160
02:08:03,130 --> 02:08:07,469
very important data type we will we will see
that in detail. But the purpose here is just
1161
02:08:07,469 --> 02:08:12,449
to tell you that there are a lot of data types
that Python supports and Python is dynamically
1162
02:08:12,449 --> 02:08:18,189
typed whatever content you are assigning to
a variable the that content decides the type
1163
02:08:18,189 --> 02:08:21,789
of the screen you need not to specify.
1164
02:08:21,789 --> 02:08:31,320
So I end this video here. In the next video,
we will be talking about operators basically
1165
02:08:31,320 --> 02:08:38,059
what kind of so once we have decided once
we have declared once we have defined a lot
1166
02:08:38,059 --> 02:08:44,260
of variables, what we can do with these variables,
can we add two variables together and get
1167
02:08:44,260 --> 02:08:49,360
the result stored in another variable can
we multiply two variables together, can we
1168
02:08:49,360 --> 02:08:55,219
have an operation like addition or mixed types
for example, one variable is a floating by
1169
02:08:55,219 --> 02:09:01,519
number and other variable is integer number
integer type, can we mix up those can we add
1170
02:09:01,519 --> 02:09:06,709
two different types of variables together
and get a result then what will be the type
1171
02:09:06,709 --> 02:09:12,039
of the result and so on. So a lot of these
discussions on operators the very basic arithmetic
1172
02:09:12,039 --> 02:09:16,889
operators on these variables, particularly
the integer and float variables, we will see
1173
02:09:16,889 --> 02:09:22,459
that in the next video, so hope to see you
in the next video. So in the last video, we
1174
02:09:22,459 --> 02:09:29,780
saw variables and we particularly saw integer
type variable and floating point, variable
1175
02:09:29,780 --> 02:09:37,989
type. We also saw very briefly on Jupyter
notebooks are complex, and string as well.
1176
02:09:37,989 --> 02:09:43,119
So in this video, we are going to talk about
operators, basically the arithmetic operators.
1177
02:09:43,119 --> 02:09:48,329
Obviously, if you are defining variables,
you're not defining the them the variables
1178
02:09:48,329 --> 02:09:54,399
just to just to view them later on. Most probably
you will be storing data to the variables
1179
02:09:54,399 --> 02:10:00,570
and then you are you're applying some computation
on a set of variables together. Comparing
1180
02:10:00,570 --> 02:10:05,989
new results saving that and doing some stuff,
most probably you will be adding to variables
1181
02:10:05,989 --> 02:10:10,979
some one way or the other in inside a program,
you may have to add two variables, you may
1182
02:10:10,979 --> 02:10:15,310
have to subtract a variable from the other,
you may have to divide a variable you may
1183
02:10:15,310 --> 02:10:20,439
have to compute for example, these are arithmetic
operators, let me let me just this this plus
1184
02:10:20,439 --> 02:10:25,689
symbol is used to add to variables. This minus
symbol or subtraction is used to subtract
1185
02:10:25,689 --> 02:10:31,380
a variable value from the other variable value.
Obviously, these all are operated on values,
1186
02:10:31,380 --> 02:10:37,439
not the names. Division, it like like the
name suggests, it's if you want to divide
1187
02:10:37,439 --> 02:10:44,719
this this person to a symbol when it is applied
to two different variables, if x is on left
1188
02:10:44,719 --> 02:10:52,849
and y is on right, what it does it, it actually
divides x by y, and checks what the remainder
1189
02:10:52,849 --> 02:11:01,809
is, for example, if x is 27, and y is five,
then what's the remainder? What do you think?
1190
02:11:01,809 --> 02:11:07,119
If we divide 27 by five, what's the remainder
the remainder will be? Two Yes, so the result
1191
02:11:07,119 --> 02:11:13,719
will be two here. So this computes the remainder.
This multiplication this star symbol is used
1192
02:11:13,719 --> 02:11:19,170
as multiplication like in mathematics, we
normally write this cross symbol. But in in
1193
02:11:19,170 --> 02:11:25,679
Python, and in most of programming languages,
Star symbol is used to achieve multiplication.
1194
02:11:25,679 --> 02:11:33,289
This double slash is like the division, but
it is division with the result flow to the
1195
02:11:33,289 --> 02:11:42,439
quotient. What I'm saying is the following.
For example, if you divide, let's say 10.
1196
02:11:42,439 --> 02:11:48,900
by three, the result will be a floating point
number, and the result will be 3.33. Something
1197
02:11:48,900 --> 02:11:55,770
like so. But if you want just the quotient,
not the remainder, if you want the integer,
1198
02:11:55,770 --> 02:12:01,570
that's the quotient value, then you write
the double slash three, and it will return
1199
02:12:01,570 --> 02:12:09,070
just the value that is that is there before
the decimal expansion. So this value will
1200
02:12:09,070 --> 02:12:14,159
be returned. So this is kind of the integer
division or floor division, this double star
1201
02:12:14,159 --> 02:12:20,709
is used to compute the power. For example,
if you want to compute to the right doublestar,
1202
02:12:20,709 --> 02:12:26,880
four, that means two raised to the power four
in mathematics, we write this as following.
1203
02:12:26,880 --> 02:12:32,560
And the result will be 16, you can save that
result in another variable, or you can just
1204
02:12:32,560 --> 02:12:41,199
print it or you can write that in a file of
whatever. So these are most important. operators.
1205
02:12:41,199 --> 02:12:46,439
One thing that I want to tell you that these
operator are not just for integers and floating
1206
02:12:46,439 --> 02:12:53,110
point numbers, the applications of these operators
is much broader than these later, we will
1207
02:12:53,110 --> 02:12:59,610
see the objects or the data types that are
collections. And very, I mean, the data types
1208
02:12:59,610 --> 02:13:05,550
that are beyond these integers and floats,
and still there, this plus minus division,
1209
02:13:05,550 --> 02:13:10,829
and all some of these are all of these, they
have their meanings there. Even even even
1210
02:13:10,829 --> 02:13:17,330
this plus is used for strengths. Now think
for example, if you have a string, let's say
1211
02:13:17,330 --> 02:13:19,659
hello.
1212
02:13:19,659 --> 02:13:23,880
And you have another string, for example,
let's say this is string s one, and you have
1213
02:13:23,880 --> 02:13:32,329
another string, let's say s two, which is
why then Python allows you even to add these
1214
02:13:32,329 --> 02:13:39,729
kind of data types, although some doesn't
make any sense with these kinds of string
1215
02:13:39,729 --> 02:13:45,809
variables, but we will see four different
kinds of data types. The the definition of
1216
02:13:45,809 --> 02:13:51,510
these operators, they actually changed or
adapted accordingly. For example, in mathematics,
1217
02:13:51,510 --> 02:13:56,760
we are much more fluent a four with plus with
Debian with subtraction, and it makes sense
1218
02:13:56,760 --> 02:14:01,939
to add two integers to subtract a floating
point number from another floating point number
1219
02:14:01,939 --> 02:14:08,110
and stuff, but with data type that is unfamiliar
to you right now, these operators may not
1220
02:14:08,110 --> 02:14:14,190
make that sense to you. But there are definitions
there, there are ways to use these variables.
1221
02:14:14,190 --> 02:14:19,329
For the data types that are even there or
even beyond an integer and floating point
1222
02:14:19,329 --> 02:14:25,140
numbers, we will see all these details as
we move on, as we move on to as we move on
1223
02:14:25,140 --> 02:14:31,079
to the videos. And I mean, as in later on,
we will see all these things in detail, but
1224
02:14:31,079 --> 02:14:34,269
just to tell you that these operators are
not just limited to integers and floating
1225
02:14:34,269 --> 02:14:39,309
point numbers or complex numbers, they can
be applied to several different data types.
1226
02:14:39,309 --> 02:14:45,520
So a lot of words, I guess you were born Now,
let's go to Jupyter Notebook and have fun
1227
02:14:45,520 --> 02:14:54,199
with these kinds of concepts that we are dealing
with. So yeah, here. So let's first press
1228
02:14:54,199 --> 02:15:03,449
escape, then m just to change it to markdown
and then good scape one for heading begetting.
1229
02:15:03,449 --> 02:15:10,010
And here I write, let's say operators, and
shift enter its runs and automatically then
1230
02:15:10,010 --> 02:15:16,010
go to code. Okay, now let's say I have a variable.
So let's say what kind of variables I already
1231
02:15:16,010 --> 02:15:21,940
have. In the previous video, we use that.
So we already have these kinds of variables
1232
02:15:21,940 --> 02:15:33,670
with us. Now, what is let me define a new
variable, let's say sum of sum of A, B, that's
1233
02:15:33,670 --> 02:15:39,119
a new variable sum underscore AB, that's a
variable name, you can have a better way you
1234
02:15:39,119 --> 02:15:50,000
will name maybe some of A and B, that might
be a variable name. It is good to have the
1235
02:15:50,000 --> 02:15:57,169
variable names that are descriptive that describe
what data is inside. Because in in programs,
1236
02:15:57,169 --> 02:16:02,300
the programs become manageable, readable,
and a lot of benefits are there. So Sum of
1237
02:16:02,300 --> 02:16:12,409
a and b, let's say that's a variable name.
And you add a, b, you just write a plus b.
1238
02:16:12,409 --> 02:16:18,489
Let me make the zoom level a little high so
that you can see it clearly. So a plus b,
1239
02:16:18,489 --> 02:16:28,239
let's say that's there. If you press Shift,
enter, and now your brand. Some of By the
1240
02:16:28,239 --> 02:16:34,170
way, if you have written some of you need
not write everything, just press tab, and
1241
02:16:34,170 --> 02:16:40,879
it will automatically complete the remaining
part of the variable and press Shift Enter
1242
02:16:40,879 --> 02:16:49,769
and you have eight. If you check the type
of this variable, some of tab automatically
1243
02:16:49,770 --> 02:16:55,250
completes tab complete that is called tab
completion, while it's integer, the type of
1244
02:16:55,250 --> 02:17:00,370
this particular variable is integer, that's
a new variable and why and the type is integer
1245
02:17:00,370 --> 02:17:09,350
because a was integer, B was integer. And
integer plus an integer is an integer. What
1246
02:17:09,350 --> 02:17:14,290
if we add an integer with a floating point
number? What do you think? What should be
1247
02:17:14,290 --> 02:17:25,090
the result? If I just type type? A, that's
an integer plus d with some floating point
1248
02:17:25,090 --> 02:17:31,250
number. So a plus d, the result will be here,
and type of that result. What will be the
1249
02:17:31,250 --> 02:17:36,700
type of that result? What do you think? Let
me pause here for a few minutes, and oh, no,
1250
02:17:36,700 --> 02:17:42,250
no, no, not for a few minutes. For a few,
maybe seconds, maybe two or three seconds,
1251
02:17:42,250 --> 02:17:48,120
what will be the result? What will be the
type of an integer and a float combined?
1252
02:17:48,120 --> 02:17:53,190
Well, the types are up costed, which means
the floating point number, the result will
1253
02:17:53,190 --> 02:17:57,129
be a floating point number. And the reason
is, every integer by default is a floating
1254
02:17:57,129 --> 02:18:03,550
point number, a floating point number is a
is an upper class, or you can say a superset.
1255
02:18:03,550 --> 02:18:10,459
So in Python, in Python, by default, the types
are up costed to super super sets. So here
1256
02:18:10,459 --> 02:18:16,099
integer plus a float, the result will be a
floating point number. And that's a result,
1257
02:18:16,100 --> 02:18:20,940
you might be thinking why we have why we haven't
stored the result in another variable. Well,
1258
02:18:20,940 --> 02:18:25,500
if we want to store the result in another
variable, we can, or if we just compute the
1259
02:18:25,500 --> 02:18:31,429
result and apply some operation on that, we
can do that. For example. We could do the
1260
02:18:31,429 --> 02:18:43,280
following, for example, a plus d. That's whatever
the result is raised to the power three, whatever
1261
02:18:43,280 --> 02:18:55,540
the result is, whatever the result is, divided
by maybe four. And we just save that in a
1262
02:18:55,540 --> 02:19:02,400
new variable. Let's say. Let's say the new
variable is V. Let's say we save that value,
1263
02:19:02,400 --> 02:19:11,020
and V. And now we print we, and we have the
result for me. Wow. So we can do a lot of
1264
02:19:11,020 --> 02:19:15,590
stuff with these kinds of variables. Let me
show you a fancy stuff that we will see later
1265
02:19:15,590 --> 02:19:22,888
on. Don't worry if you don't get it just as
one, for example, as one is Hello. Hello,
1266
02:19:22,888 --> 02:19:31,710
and let's say s two is world. And we have
another variable, let's say s, which is s
1267
02:19:31,710 --> 02:19:39,729
one plus s two. What it will do is it will
just concatenate them together. We will see
1268
02:19:39,730 --> 02:19:47,209
strings a lot later on. But just to tell you
this plus is not just for not just for numbers,
1269
02:19:47,209 --> 02:19:54,170
it is for other data types, very fancy data
types that are there. One more thing, let's
1270
02:19:54,170 --> 02:20:04,160
say we define 10 and we divide it by Three,
and we want a quotient, the quotient is three.
1271
02:20:04,160 --> 02:20:12,150
However, if we have 10 divided by three, Shift
Enter, the result actually is 3.33, and so
1272
02:20:12,150 --> 02:20:18,250
on, you might be wondering we have not saved
that result in a particular variable. So where
1273
02:20:18,250 --> 02:20:23,920
the result is saved, actually, if you do not,
if you do not save the result, if you do not
1274
02:20:23,920 --> 02:20:28,490
assign the result, for example, in this way,
the result will be assigned to a variable
1275
02:20:28,490 --> 02:20:34,300
or, but if you do not assign if you do not
store the result in a particular variable
1276
02:20:34,300 --> 02:20:40,591
explicitly, by default, there is a variable
in Python, which is underscore underscore
1277
02:20:40,591 --> 02:20:47,381
contains the last result that you did not
store in a particular variable explicitly.
1278
02:20:47,381 --> 02:20:55,450
So, that underscore is basically one default
variable for for the result, if you want,
1279
02:20:55,450 --> 02:21:03,490
don't try to update this underscore, just
just read it Do not assign anything to underscore.
1280
02:21:03,490 --> 02:21:10,210
For example, if you assign something to underscore
assignment will be done, but then the properties
1281
02:21:10,210 --> 02:21:18,960
of underscore will no longer be there as they
are in in Python built in properties. Okay,
1282
02:21:18,960 --> 02:21:28,400
so, that's about it, I guess. So that was
the operators, we will see the operators more
1283
02:21:28,400 --> 02:21:34,440
and more later on. But before ending this
video, I leave you with a question. So the
1284
02:21:34,440 --> 02:21:43,340
question is, we saw the variable names like,
Sum of a and b X, Y variable name can be can
1285
02:21:43,340 --> 02:21:48,620
be lengthy can be descriptive can be short
anyways. So the question really is, can a
1286
02:21:48,620 --> 02:21:54,540
variable name start with a digit? For example?
Is it possible that the variable name really
1287
02:21:54,540 --> 02:22:04,010
is is starts from the variable name starts
from for example, a digit? is a 3x? valid
1288
02:22:04,010 --> 02:22:12,101
variable name? Or, for example, at the rate
of at the rate of Why is that a variable name?
1289
02:22:12,101 --> 02:22:22,610
Or, for example, this symbol times two times
x, is that a variable name? What are the conventions
1290
02:22:22,610 --> 02:22:28,140
to for variable names? can we can we write
anything? In the left hand side? The right
1291
02:22:28,140 --> 02:22:33,730
let's say 3x? Is equal to four? That means
3x is now a variable name. Is that true in
1292
02:22:33,730 --> 02:22:40,300
Python? Or are there conventions to define
the variable names? So?
1293
02:22:40,300 --> 02:22:47,671
Yeah, think about it. See you in the next
video with the answer to this. So I hope you
1294
02:22:47,671 --> 02:22:53,590
will, you will be having answer for this question.
Hope to see you in the next video. Okay, so
1295
02:22:53,590 --> 02:23:01,011
in the last video, I asked you a question
about the naming convention of the odd variable
1296
02:23:01,011 --> 02:23:08,340
names. In particular, I asked you whether
3x is a proper variable name or not in Python?
1297
02:23:08,340 --> 02:23:15,360
So what's your answer? Yeah. What do you think?
How many of say, how many of you say no? How
1298
02:23:15,360 --> 02:23:24,900
many of you say yes? Well, by the way, you
might have tried that, declaring that variable
1299
02:23:24,900 --> 02:23:30,280
name and Jupyter Notebook, and then you might
have got this answer one of these? Well,
1300
02:23:30,280 --> 02:23:39,780
let me tell you, the answer is no. A variable
cannot start with a digit. Not with, not with,
1301
02:23:39,780 --> 02:23:44,110
at the rate of not with hash symbol, not with
I mean, there are several
1302
02:23:44,110 --> 02:23:50,910
other special characters are not there except
a few factors. One of those is underscore.
1303
02:23:50,910 --> 02:23:59,950
Let's go to let's go to Jupyter Notebook and
and check this. So, for example, 3x equals
1304
02:23:59,950 --> 02:24:21,880
five error, invalid syntax, let's say activate
of y equals four. Invalid star d equals four
1305
02:24:21,880 --> 02:24:35,170
error. Well, an exception is underscore underscore
E equals six, that's allowed. Starting a variable
1306
02:24:35,170 --> 02:24:40,210
name with underscore is allowed, it is different
than the underscore that is built in underscore
1307
02:24:40,210 --> 02:24:47,960
this underscore E is different than simply
underscore. So it is good to not declare the
1308
02:24:47,960 --> 02:24:54,000
variable names that start from these because
you will be getting errors further. variable
1309
02:24:54,000 --> 02:24:58,170
names should be descriptive. They should give
you a look and feel of the data what they
1310
02:24:58,170 --> 02:25:05,240
are containing and you're free to define variable
names, as as descriptive as you want. So it
1311
02:25:05,240 --> 02:25:11,960
is a good practice to, to start writing the
variable names in a better way. One, one better
1312
02:25:11,960 --> 02:25:17,400
notation, one better notation of defining
these variable names, even the function names,
1313
02:25:17,400 --> 02:25:23,290
we will see the functions later on. One way
to defining those is to use camel notation.
1314
02:25:23,290 --> 02:25:31,960
camel notation camel notation is you start
with the variable name with for example, lowercase
1315
02:25:31,960 --> 02:25:40,131
letters, let's say your variable is starting
time of the course. Let's say that's your
1316
02:25:40,131 --> 02:25:46,170
variable name. So you write starting, that's
one word finishes, then the next word should
1317
02:25:46,170 --> 02:25:56,061
start from capital T, starting time of the
course, let's say. So this kind of notation
1318
02:25:56,061 --> 02:26:00,920
is called camel notation. And very famous,
particularly the Java developers, they normally
1319
02:26:00,920 --> 02:26:06,570
follow this and several other developers.
But you should come up with a notation that
1320
02:26:06,570 --> 02:26:13,830
is one notation, there are other ways of keeping
consistently keeping the consistent strategy
1321
02:26:13,830 --> 02:26:19,340
of defining variables. There are several other
ways this is one way. So starting time of
1322
02:26:19,340 --> 02:26:27,132
the course is let's say 2.0. That's it. So
that's a variable name, if you if you now
1323
02:26:27,132 --> 02:26:33,871
check, that's a variable name. But now, if
you see this variable, just just the name
1324
02:26:33,871 --> 02:26:41,210
suggests the data inside is doing what? So
the names should be descriptive, I mean, and
1325
02:26:41,210 --> 02:26:50,670
make that as a habit. So, yeah, I guess we
have now answered our question very concretely,
1326
02:26:50,670 --> 02:26:56,760
that variable name cannot start with a digit
not with any special character other than
1327
02:26:56,760 --> 02:27:07,260
underscore, okay. In the next video, I will
be introducing comparisons with with variables.
1328
02:27:07,260 --> 02:27:11,130
For example, what if you want to compare whether
one variable is smaller than the other or
1329
02:27:11,130 --> 02:27:15,920
not? What if you want to compare whether the
two variables they are containing values they
1330
02:27:15,920 --> 02:27:24,490
are same or not? What if you want to do comparisons
of the of the data that is stored inside the
1331
02:27:24,490 --> 02:27:29,170
variables, and based on the result of the
comparison, you want to do something else.
1332
02:27:29,170 --> 02:27:35,400
So in the next video, we will see a bool data
type that is very, very famous, and it is
1333
02:27:35,400 --> 02:27:40,670
used in a lot in decision making. And we will
see the comparison operator sometimes called
1334
02:27:40,670 --> 02:27:46,680
the relational operators in the next video,
so hope to see you in the next video. Okay,
1335
02:27:46,680 --> 02:27:54,010
in this video, we are going to talk about
a data type which is called bool. That's very,
1336
02:27:54,010 --> 02:27:59,660
very famous data type. Actually, it's the
most famous data type because it is used in
1337
02:27:59,660 --> 02:28:06,750
decision making all the control flow most
of the controls, so depends on this data type.
1338
02:28:06,750 --> 02:28:14,320
Although it is very, very famous, very much
applicable data type, it is very simple. It
1339
02:28:14,320 --> 02:28:19,650
is a data type with just two states with just
two values. By the way, there are capacities
1340
02:28:19,650 --> 02:28:24,160
of different data types. For example, in T
integer, the
1341
02:28:24,160 --> 02:28:27,880
different kinds of values that you can store
are huge, you can store any negative number
1342
02:28:27,880 --> 02:28:32,721
in it, you can store zero, you can store any
positive number, the capacity of floating
1343
02:28:32,721 --> 02:28:37,990
point number or the number of values that
it can save is is even higher than even higher
1344
02:28:37,990 --> 02:28:43,510
than integer and the complex number is even
higher than that and so on. But the bool data
1345
02:28:43,510 --> 02:28:51,250
type, it has just two states one state is
true. It has just two values. True is a value.
1346
02:28:51,250 --> 02:28:58,170
And false is a value just these two straights
true or false. In some programming languages,
1347
02:28:58,170 --> 02:29:04,630
the true is denoted by one, and the false
is denoted by zero. But in Python, the true
1348
02:29:04,630 --> 02:29:11,290
is just t ru e true that thing and false is
false. That's it. If you For example, define
1349
02:29:11,290 --> 02:29:18,300
a variable let's say any variable name, whatever
the name is, let's say B and you assign true
1350
02:29:18,300 --> 02:29:24,000
then it's its default data type will become
bool. And if you have another variable, let's
1351
02:29:24,000 --> 02:29:34,640
see which is false. Then C is also bool. One
thing that is important, there are other operations
1352
02:29:34,640 --> 02:29:40,321
other than arithmetic operators that we saw,
adding subtraction division and stuff, there
1353
02:29:40,321 --> 02:29:48,971
are other operators that we can apply on bool
datatype. For example, a true and and is a
1354
02:29:48,971 --> 02:30:00,250
keyword combining true and true. If if there
is a variable, let's say a with a There is
1355
02:30:00,250 --> 02:30:05,802
a boolean variable a with data true. If there
is a boolean variable b with data true, then
1356
02:30:05,802 --> 02:30:14,460
a and b is also true. So let's say I've used
this variable D, in storing this A and B,
1357
02:30:14,460 --> 02:30:28,420
the D will also be true. So true and true
is always true. Further true and false, this
1358
02:30:28,420 --> 02:30:35,160
is always false. And this is committed if
for example, true and true is true, true and
1359
02:30:35,160 --> 02:30:43,860
false is false, false and true is false, false
and false is false. So, if you apply an operator
1360
02:30:43,860 --> 02:30:51,220
and keyword to combine the two Boolean variables
together, if both are true, then and will
1361
02:30:51,220 --> 02:30:59,000
result a true otherwise and will result of
false other than this and there are there
1362
02:30:59,000 --> 02:31:11,950
is there is another, there is another operator,
keyword or so, this results false. If both
1363
02:31:11,950 --> 02:31:22,351
are false, false, false, false or false is
false. If any one of these is true, then the
1364
02:31:22,351 --> 02:31:32,250
result is true. Remember the difference between
n and R and will result false if any one of
1365
02:31:32,250 --> 02:31:35,480
the two operands at least one of the two operands
is false,
1366
02:31:35,480 --> 02:31:42,510
then the result is false. If both are or are
anvisa true, if both of the operands are true,
1367
02:31:42,510 --> 02:31:43,660
otherwise it is false
1368
02:31:43,660 --> 02:31:51,550
or will result false if both of the options
is false or false. Otherwise it is true. So,
1369
02:31:51,550 --> 02:31:59,200
you now know and you now know are there is
another operator called not. This is not so
1370
02:31:59,200 --> 02:32:12,550
not for example, returns not true. Results
false and not false. returns true. Great.
1371
02:32:12,550 --> 02:32:18,551
So knot is a unary operator. unary means it
just takes it just takes one variable and
1372
02:32:18,551 --> 02:32:24,220
operate on that, and is a binary operator
like plus is a binary operator. It takes two
1373
02:32:24,220 --> 02:32:30,341
variables to operate on, or is a binary operator
it operate, it takes two operators, it takes
1374
02:32:30,341 --> 02:32:38,851
two variables to operate on and so on. So
remember, remember these things, one, and
1375
02:32:38,851 --> 02:32:45,200
we'll return true if both of the variables
are true, otherwise the result is false, or
1376
02:32:45,200 --> 02:32:53,250
will result false. If both are false. Otherwise,
it will return true and not is not just flips
1377
02:32:53,250 --> 02:33:01,171
the the state. So not true means false, not
false means true. So these are basic, that's
1378
02:33:01,171 --> 02:33:06,480
how you can combine the Boolean variables
together. In the next video, we will be seeing
1379
02:33:06,480 --> 02:33:12,331
how to apply these comparison operators and
the result will be Boolean types. And how
1380
02:33:12,331 --> 02:33:18,110
can we combine the Boolean types together
to to build a better decision making. So in
1381
02:33:18,110 --> 02:33:23,681
this particular video, I just, I just introduced
the boolean data type for you with you. In
1382
02:33:23,681 --> 02:33:30,660
the next video, we will see where the boolean
data type actually appears, and how it impacts
1383
02:33:30,660 --> 02:33:36,510
our, our our programming style or thinking
style or coding style. So hope to see you
1384
02:33:36,510 --> 02:33:42,050
in the next video with comparison operators
that actually produces the Boolean variables.
1385
02:33:42,050 --> 02:33:47,160
Hope to see you in the next video. Okay, in
the last video, I discussed boolean data type
1386
02:33:47,160 --> 02:33:53,530
and I discussed that a boolean variable takes
either a true or a false and we can combine
1387
02:33:53,530 --> 02:34:01,351
these Boolean variables together with and
our operators. And then we can apply a knot
1388
02:34:01,351 --> 02:34:08,040
operator on a particular variable. And we
we saw that a true and true returns true and
1389
02:34:08,040 --> 02:34:16,450
and otherwise it also returns false. Similarly
false or false is false. Otherwise, or always
1390
02:34:16,450 --> 02:34:24,030
returns of a true before before actually discussing
these comparison operators. Let's do let's
1391
02:34:24,030 --> 02:34:30,080
just go to Jupiter and just just play with
a boolean data type. Just Just for just for
1392
02:34:30,080 --> 02:34:45,961
a moment. Let us just convert this to markdown
cell and just cried. Both that's a word Boolean
1393
02:34:45,961 --> 02:35:03,490
variable. So let's say A is true and B is
true and C is false. False. And okay, so these
1394
02:35:03,490 --> 02:35:12,230
are variables. Let's press those to see what
are the states of. So, a is a boolean variable
1395
02:35:12,230 --> 02:35:17,570
with value true B is a boolean variable with
value true C is a boolean variable with value
1396
02:35:17,570 --> 02:35:25,920
false. So, now it is true B is true, C is
false. So that means, let me print print a
1397
02:35:25,920 --> 02:35:34,580
and b, what do you think? What is what will
be the result? Let me print a and see what
1398
02:35:34,580 --> 02:35:46,140
will be the result. And let me Brent? C and
A. So because a and b both are true, the first
1399
02:35:46,140 --> 02:35:55,140
result will be true, because C is false, false,
true and true is true. The the other two statements
1400
02:35:55,140 --> 02:36:01,680
they will result false. So first value will
be true, then false false. So yes, true, false
1401
02:36:01,680 --> 02:36:09,351
false. Let's, let's check the or print. And
by the way, let's store that are in another
1402
02:36:09,351 --> 02:36:16,990
variable, let's say A is true, or C is false.
So what do you think what will be the result
1403
02:36:16,990 --> 02:36:24,580
here, because or gives false when both are
false, here is true. So the value of d will
1404
02:36:24,580 --> 02:36:26,630
be true
1405
02:36:26,630 --> 02:36:39,630
for the not a, because A is true, not a will
be false. Similarly, not B, B is true. So
1406
02:36:39,630 --> 02:36:48,860
not B will be false. Not C, C is true, C is
false, and not c will be true. Similarly,
1407
02:36:48,860 --> 02:37:00,000
not D, we can save the result in another variable,
let's say D. and we can just check the type
1408
02:37:00,000 --> 02:37:07,390
of D if we want, that's a Boolean, we can
also check the value inside D and that is
1409
02:37:07,390 --> 02:37:15,550
false. So, yes, not only that, I mean, we
can we can we can we can combine at a higher
1410
02:37:15,550 --> 02:37:26,980
level for example, A and A and B, whatever
the result is, or C or D, whatever the result
1411
02:37:26,980 --> 02:37:34,461
is, and whatever the result is not of that.
I mean, we can we can combine them in a very
1412
02:37:34,461 --> 02:37:40,150
complicated way. If we want a and b the result
will be some Boolean, that Boolean and that
1413
02:37:40,150 --> 02:37:41,620
Boolean there
1414
02:37:41,620 --> 02:37:42,620
are the
1415
02:37:42,620 --> 02:37:47,540
result eventually will be a Boolean, and then
not have that. So let's check what if that
1416
02:37:47,540 --> 02:37:55,051
is the result is false, well, why the result
is false. figured out why the result is false,
1417
02:37:55,051 --> 02:38:04,250
let me go to comparison operators. So, the
comparison operators, let me just go through
1418
02:38:04,250 --> 02:38:09,500
comparison operators. This equal equal to
it compares whether two variables whether
1419
02:38:09,500 --> 02:38:13,920
whatever the variables are whether they are
integer floating point, whatever, whether
1420
02:38:13,920 --> 02:38:22,660
two variables are are, they have same data
or not, for example, x equals equals two y.
1421
02:38:22,660 --> 02:38:31,110
That will be true if x and y, they both have
same data. So for example, if X has value
1422
02:38:31,110 --> 02:38:36,920
four, and y has value four, then we are just
checking x equals equal to buy or not, the
1423
02:38:36,920 --> 02:38:43,230
result will be Boolean. Because an X may not
be a boolean variable y may not be a boolean
1424
02:38:43,230 --> 02:38:48,480
variable. If we want to compare the values
of x and y, then we write w equal without
1425
02:38:48,480 --> 02:38:54,200
a space inside. Remember, if we write single
equal that will be an assignment operator.
1426
02:38:54,200 --> 02:39:00,580
If we write w equal that means we are checking
whether the two values are same or not. Similarly,
1427
02:39:00,580 --> 02:39:06,210
if we write this particular symbol that checks
whether two values are not equal or not, for
1428
02:39:06,210 --> 02:39:14,160
example, x is not equal to y, the result will
be true if x and why they both have different
1429
02:39:14,160 --> 02:39:18,950
values, otherwise the result will be false.
Remember, the result of comparison is always
1430
02:39:18,950 --> 02:39:25,410
a Boolean, it is either true or false. Okay,
next we check whether less than So for example,
1431
02:39:25,410 --> 02:39:33,311
if x is less than y, the result will be true.
If x indeed has a value that is smaller than
1432
02:39:33,311 --> 02:39:38,840
y, let's say x is two and y is 10. In that
case, the result will be a true otherwise
1433
02:39:38,840 --> 02:39:43,410
the result will be false. Similarly, we can
compare the two variables using greater than
1434
02:39:43,410 --> 02:39:49,251
we can compare the two variables by less or
whether whether the whether one variable less
1435
02:39:49,251 --> 02:39:55,070
or equal to the other. For example, if X is
less or equal to y, the result will be true
1436
02:39:55,070 --> 02:40:02,000
of this comparison the result will be true
if X has a value that is not larger than why
1437
02:40:02,000 --> 02:40:07,920
as long as x and y are equal or x is smaller
than y In any case, the result will be true
1438
02:40:07,920 --> 02:40:15,471
otherwise false. Similarly, greater than or
equal to. Okay, so I end this video here in
1439
02:40:15,471 --> 02:40:21,880
the next video, we will be, we will be moving
to Jupiter and playing with these operators,
1440
02:40:21,880 --> 02:40:27,410
and seeing the return types of Booleans. And
then combining them together with ands and
1441
02:40:27,410 --> 02:40:34,070
ORS and doing doing interesting stuff with
that. In this particular video, I just talk
1442
02:40:34,070 --> 02:40:40,301
about the comparison operators, the boolean
data type and combining them by and or not.
1443
02:40:40,301 --> 02:40:45,500
In the next video, we'll be first moving to
Jupiter, we will see the comparison operators,
1444
02:40:45,500 --> 02:40:50,700
we will write all these statements in Jupiter
and just get a good hands on grip on that.
1445
02:40:50,700 --> 02:40:55,380
And then we'll be moving on verse. So hope
to see you in the next video. So in the last
1446
02:40:55,380 --> 02:41:03,670
video, I talked about comparisons, w equal
to not equal to less than, greater than, less
1447
02:41:03,670 --> 02:41:08,890
than or equal to, greater than or equal to.
So let's go to Jupyter Notebook and see how
1448
02:41:08,890 --> 02:41:23,891
they actually work. So let me just first enter
a markdown cell and type comparisons. Shift
1449
02:41:23,891 --> 02:41:34,670
Enter comparisons. So we can we can compare
different values by first assigning them to
1450
02:41:34,670 --> 02:41:41,561
variables. And then comparing those variables
or we can we can compare the values directly
1451
02:41:41,561 --> 02:41:52,410
or for example, rent. Two is less than three.
What do you think two is lesson three, the
1452
02:41:52,410 --> 02:41:57,400
result will be what Remember, the result of
a comparison operator is always Boolean, it
1453
02:41:57,400 --> 02:42:03,561
is either true or false. So in this case two
is smaller than three. So the result will
1454
02:42:03,561 --> 02:42:10,090
because this statement is true. So the result
will be true and true will be counted. Further,
1455
02:42:10,090 --> 02:42:16,570
we can store that result in in another variable
for example to is smaller than three, whatever
1456
02:42:16,570 --> 02:42:21,690
the result is, the result will be true, the
result will be saved in a variable, see, if
1457
02:42:21,690 --> 02:42:26,750
we check the type of see
1458
02:42:26,750 --> 02:42:37,190
reject the type of seeing as long as let's
print the value of C. So you can see the type
1459
02:42:37,190 --> 02:42:45,960
of C is Boolean, and C in this particular
case is true. Moreover, for example, let's
1460
02:42:45,960 --> 02:42:56,490
have three equals to four. Is that true or
false? What do you think three equals to four,
1461
02:42:56,490 --> 02:43:03,340
three, w equals to four, that is false, three
is not equal to four. And let's save this
1462
02:43:03,340 --> 02:43:09,920
result in D, remember three double equals
to four, that's an operation the result is
1463
02:43:09,920 --> 02:43:17,290
false. This equal is an assignment operator
that the false value will be assigned to the
1464
02:43:17,290 --> 02:43:28,170
variable D. and here we can see Brent D. Burn
it is false. Similarly, what do you think?
1465
02:43:28,170 --> 02:43:41,510
Three double equal to 3.0? What will be the
result? Remember, three is integer. 3.0 is
1466
02:43:41,510 --> 02:43:48,210
a floating point number. And I'm comparing
three double equals to 3.01 is integer, and
1467
02:43:48,210 --> 02:43:53,180
other is a floating point number. So what
will be the result? Let's say the result is
1468
02:43:53,180 --> 02:44:02,410
true, because they are comparing the values
by discarding the decimal position. Further,
1469
02:44:02,410 --> 02:44:13,900
let's see. Three is smaller or equal to so
let's say x is equal to four, y is equal to
1470
02:44:13,900 --> 02:44:28,891
nine. And z is equal to let's say 8.3. And
r is equal to minus three, let's say and these
1471
02:44:28,891 --> 02:44:36,091
are our variables. Let's see. So what do you
think what will be the result here x is smaller
1472
02:44:36,091 --> 02:44:44,490
than y. What will be the result of that x
is smaller than y, the result will be true
1473
02:44:44,490 --> 02:44:57,850
and z is smaller than z is smaller than y.
The result is again true because the smaller
1474
02:44:57,850 --> 02:45:14,061
than y or r r is r is equal to for example,
x. So what do you think what will be the result
1475
02:45:14,061 --> 02:45:22,670
at the end after this, so, let's see first
first this will be true, this will be again
1476
02:45:22,670 --> 02:45:35,780
true, and that is false. Okay. So, this true
and true will return true and true or anything,
1477
02:45:35,780 --> 02:45:44,420
the result final result is true. So, this
will return or it's returning true. But, if
1478
02:45:44,420 --> 02:45:54,450
I just do if I just switch the order, for
example, if I just write this statement, which
1479
02:45:54,450 --> 02:46:03,670
is false, this particular statement here and
then I do this, what will be the result now,
1480
02:46:03,670 --> 02:46:14,910
Now see, x is smaller than y it is true, r
is equal to x that is false. So, this result
1481
02:46:14,910 --> 02:46:23,870
will be false eventually, and z is smaller
than y, that result is z is smaller than y,
1482
02:46:23,870 --> 02:46:31,110
let me just say z is larger than one, let
me just check z is larger than y, z is larger
1483
02:46:31,110 --> 02:46:40,600
than I just just do just to tell you. So,
this is true, this is false. Both of these
1484
02:46:40,600 --> 02:46:48,920
are let me let me switch the let me switch
the listing r equals to x, I just want to
1485
02:46:48,920 --> 02:47:02,220
show you the precedents of r and x is smaller
than y. So now, if you see this is false,
1486
02:47:02,220 --> 02:47:15,800
this is true, false and true is true, true
or false and true is false, this is also false.
1487
02:47:15,800 --> 02:47:23,390
And the result overall is false. It should
happen, but what if, what if this goes first,
1488
02:47:23,390 --> 02:47:29,890
if this goes first, I mean, I want to show
you whether and an AR, which one of them will
1489
02:47:29,890 --> 02:47:35,660
operate first. So, in this particular case,
the result is false, but it can happen let
1490
02:47:35,660 --> 02:47:51,490
me let me tell you this in more and two, or
false and true or false. And
1491
02:47:51,490 --> 02:47:54,800
true,
1492
02:47:54,800 --> 02:48:01,010
what do you think what will be the result
here, true or false and true, if true or false
1493
02:48:01,010 --> 02:48:07,140
operate operate First, if true or false operate
First, the result will be true, true and true,
1494
02:48:07,140 --> 02:48:16,080
the result is true. If however, let me let
me just write a false here. If all operates
1495
02:48:16,080 --> 02:48:24,920
First, if all operates first, then false or
false is false and false and true is the result
1496
02:48:24,920 --> 02:48:34,690
eventually is false. And if and operates first,
then false and true is false, false or false
1497
02:48:34,690 --> 02:48:43,821
the result in both cases here is is false.
So, a better way of representing these kind
1498
02:48:43,821 --> 02:48:50,311
of sometimes sometimes they can make confusions,
sometimes they can make confusions, for example,
1499
02:48:50,311 --> 02:48:56,420
if we have a true here, if you have a false
here for example, false and true
1500
02:48:56,420 --> 02:49:23,870
How can I so, false, false and false or true.
So, in this case, if in this case, if false
1501
02:49:23,870 --> 02:49:32,800
or true that operate First, the result will
be true and false and false, false and true
1502
02:49:32,800 --> 02:49:39,021
the result will eventually be false. However,
if n operates First, the result will be false
1503
02:49:39,021 --> 02:49:47,300
here, false or true the result will be true.
So, here if and applies if you apply if n
1504
02:49:47,300 --> 02:49:53,090
is applied first, then the result overall
result will be true. But if all is applied
1505
02:49:53,090 --> 02:49:58,880
first, then the overall result will be false.
So it is it is good to know whether and will
1506
02:49:58,880 --> 02:50:03,360
be applied first or off will be applied first
in this particular case and will be applied
1507
02:50:03,360 --> 02:50:07,561
first even if you even if you change this
even if you change this order for example,
1508
02:50:07,561 --> 02:50:22,670
if you even if you pick this thing and apply
here still the result is and will be applied
1509
02:50:22,670 --> 02:50:29,000
first and or will be applied after, it is
always good rather than to one way is to remember
1510
02:50:29,000 --> 02:50:35,720
the precedents and will be applied first then
or, I mean it is good to think about the precedents.
1511
02:50:35,720 --> 02:50:41,860
Another good thing is to specify the order
using parentheses. For example, now, we specify
1512
02:50:41,860 --> 02:50:46,730
this first our will be applied and then four
and will be applied. So, it is good for readability
1513
02:50:46,730 --> 02:50:51,880
to always apply these parentheses and and
check the order in which ands and ORS and
1514
02:50:51,880 --> 02:50:58,051
the combination will be applied. So, the in
any way the result of these comparisons will
1515
02:50:58,051 --> 02:51:11,000
be bullions. Question, what will be the result
here? So, not to not equal to three and true
1516
02:51:11,000 --> 02:51:17,490
or false and true. See this slide for a while.
Even if you want to pause the video, pause
1517
02:51:17,490 --> 02:51:26,130
the video, see it? and answer the Brent will
return true or false. okay with this question,
1518
02:51:26,130 --> 02:51:31,130
I end this video. In this particular video,
we just saw the comparisons on Jupyter Notebook.
1519
02:51:31,130 --> 02:51:35,750
Just see how the comparisons return true or
true or false. We combine the different tools
1520
02:51:35,750 --> 02:51:43,410
and different Boolean values using ands and
ORS. And here is a question for you. Okay,
1521
02:51:43,410 --> 02:51:49,590
I will see you in the next video with answer
of this question. So I left you with a question
1522
02:51:49,590 --> 02:51:55,670
in the last video. So that was the question
if you remember. So the question really was,
1523
02:51:55,670 --> 02:52:03,670
what's the what's the result here? So what's
your answer? True or false? The result, either
1524
02:52:03,670 --> 02:52:10,130
will be true or false, because these are all
comparisons and combination of Boolean values.
1525
02:52:10,130 --> 02:52:17,021
So let's see step by step. First of all, let's
see this two is not equal to three The result
1526
02:52:17,021 --> 02:52:24,380
is two is not equal to three Yes, it is true,
two is not equal to three That's true. So
1527
02:52:24,380 --> 02:52:43,290
not true not true is false. So, this is false.
So, this whole thing is false. Now false and
1528
02:52:43,290 --> 02:52:55,630
true false and true that is false. So, this
whole thing here till here is false. Now we
1529
02:52:55,630 --> 02:53:09,150
have or or and then we have false and true
false and true is false. So, this whole thing
1530
02:53:09,150 --> 02:53:16,460
is false this whole thing is false and or
between false or false it is false. So the
1531
02:53:16,460 --> 02:53:24,390
result of this. So the So the answer to this
question is is false. Let me let me just convince
1532
02:53:24,390 --> 02:53:34,660
you by typing the statement in in Jupyter
Notebook. So, if you remember we have Brent.
1533
02:53:34,660 --> 02:53:49,250
Brent, not two is not equal to three and then
we were having I guess and false and yeah,
1534
02:53:49,250 --> 02:53:59,380
that was a different one. And true, sorry,
that was and true. So this was and true, then
1535
02:53:59,380 --> 02:54:01,431
we were having our
1536
02:54:01,431 --> 02:54:12,460
and then we were having these false and true.
So the front ends here and the result is Oh,
1537
02:54:12,460 --> 02:54:21,500
I have some I have some parenthesis mismatch.
So not true and this okay, I should have this
1538
02:54:21,500 --> 02:54:31,190
one I guess this goes to there and this goes
to there and I guess Yes. So the result is
1539
02:54:31,190 --> 02:54:40,230
false. The result is false. The purpose of
this question was not just to the purpose
1540
02:54:40,230 --> 02:54:46,521
of this question is to appreciate actually
the fact how we can combine different Boolean
1541
02:54:46,521 --> 02:54:51,860
values to to to achieve the final boolean
value and these kind of combinations will
1542
02:54:51,860 --> 02:54:57,261
become very, very helpful further in in control
flow and we will see the if conditions and
1543
02:54:57,261 --> 02:55:05,090
decision making and stuff so The answer to
this question is false. Yeah, and I end this
1544
02:55:05,090 --> 02:55:14,561
video here. In the next video, we are going
to see some useful functions of Python. And
1545
02:55:14,561 --> 02:55:19,050
after seeing the some some kind of useful,
there are a lot of functions, we will see
1546
02:55:19,050 --> 02:55:25,710
just a few of them very useful of them. And
after seeing those functions, then we will
1547
02:55:25,710 --> 02:55:30,540
directly jump to control flow basically the
if conditions and stuff where you will see
1548
02:55:30,540 --> 02:55:36,760
these comparisons, these Boolean values in
a much more applicable sense, then then earlier.
1549
02:55:36,760 --> 02:55:43,600
So hope to see you in the next video. Okay,
so let's have a very quick tour over some
1550
02:55:43,600 --> 02:55:49,640
some useful functions in Python. Obviously,
there are a lot of functions in Python, but
1551
02:55:49,640 --> 02:55:55,010
I will be covering just a few of them. That
I think with the passage of time, we will
1552
02:55:55,010 --> 02:56:01,640
be covering more and more but let's start
a function are sometimes, particularly a built
1553
02:56:01,640 --> 02:56:09,100
in function is is basically a feature from
the language that is supplied for the users
1554
02:56:09,100 --> 02:56:18,771
to achieve particular task. For example, around
function. If you give round for example, around,
1555
02:56:18,771 --> 02:56:27,961
let's say 4.6. This 4.6 is a floating point
number, and rounding means make it as integer.
1556
02:56:27,961 --> 02:56:34,400
And what round does is it finds the nearest
integer to 4.6. And the nearest integer in
1557
02:56:34,400 --> 02:56:40,671
this case is five, because five is more closer
to 4.6, then four. However, if you call round,
1558
02:56:40,671 --> 02:56:48,600
for example, on four point, let's say three,
then the result will be four, because four
1559
02:56:48,600 --> 02:56:53,971
is more closer to 4.3, than five. So that's
one use of round eight rounds, basically rounds
1560
02:56:53,971 --> 02:57:03,600
a floating point number to the nearest integer.
Another use of round is if you give another
1561
02:57:03,600 --> 02:57:07,480
argument that that is called an argument to
the function. For example, when you write
1562
02:57:07,480 --> 02:57:17,640
Brent. Brent, let's say a, this a is called
argument to a function Brent. Similarly, round
1563
02:57:17,640 --> 02:57:23,881
is a function 4.6 is an argument round is
function 4.3 is an argument, we will see functions
1564
02:57:23,881 --> 02:57:29,670
in details, and we will be writing our own
functions as well. But for now, just just
1565
02:57:29,670 --> 02:57:34,660
bear that just bear with me that functions
are these kinds of features that are available.
1566
02:57:34,660 --> 02:57:42,340
However, we we will be writing our own functions
later on. So this particular function accepts
1567
02:57:42,340 --> 02:57:48,430
two arguments surround has two different kind
of implementation. One is when it accepts
1568
02:57:48,430 --> 02:57:54,211
only one input argument, it returns the nearest
integer to that, if it accepts a floating
1569
02:57:54,211 --> 02:58:00,771
point number as well as another argument like
here we have three, that means after after
1570
02:58:00,771 --> 02:58:07,141
point, after decimal, go to three places only,
and then round up, then round, for example,
1571
02:58:07,141 --> 02:58:15,391
this 4.55 and then eight will be rounded based
on its next value. If the next value is larger
1572
02:58:15,391 --> 02:58:20,140
than five, then eight will go to nine and
stop. If the next value is smaller than five,
1573
02:58:20,140 --> 02:58:27,680
then it will stay as eight and the result
will be three decimal places after this. So
1574
02:58:27,680 --> 02:58:33,760
let's practice this round function just on
a Jupyter Notebook very quickly. Let's see.
1575
02:58:33,760 --> 02:58:51,280
So here we are. So let's see rent around,
let's say 4.556. And in this case, the result
1576
02:58:51,280 --> 02:58:59,351
will be 4.5. And the reason is 4.5. And it's
rounded up, it stays to five and the reason
1577
02:58:59,351 --> 02:59:03,540
is this 4.556, it is more closer to five then
1578
02:59:03,540 --> 02:59:14,350
than four. However, if you if you just print
round, four point, let's say 345. Let's see,
1579
02:59:14,350 --> 02:59:22,271
and the result will be for the reason is 4.345
is more closer to four. However, if you call
1580
02:59:22,271 --> 02:59:33,931
this round function with more than one argument,
for example 4.556789 let's say or with argument,
1581
02:59:33,931 --> 02:59:40,521
let's do that means the result should be only
two decimal places after the after the decimal
1582
02:59:40,521 --> 02:59:49,140
point. So in this case, the result is 4.56.
And the reason is, this five is rounded based
1583
02:59:49,140 --> 02:59:55,771
on the next digit and the next digit is larger
than five. Hence it is rounded up. So 4.56
1584
02:59:55,771 --> 03:00:02,100
If however, I call this function for three
Then what do you think what will be the result
1585
03:00:02,100 --> 03:00:07,430
it will be 4.55. And the six will be rounded
up based on the seven, and it will become
1586
03:00:07,430 --> 03:00:17,221
4.557. Yes. However, if, for example, there
will be a value at at the place of seven,
1587
03:00:17,221 --> 03:00:25,030
if there is a value, let's say three, then
you call this function, then 4.556. And then
1588
03:00:25,030 --> 03:00:29,900
based on the next value three, the six will
stay as six rather than going to nine, and
1589
03:00:29,900 --> 03:00:37,180
the result will be 4.556. Yeah, so that's,
that's the, that's the round function. Basically,
1590
03:00:37,180 --> 03:00:44,850
another function is diff mode, diff mode function
basically divides and returns quotient, and,
1591
03:00:44,850 --> 03:00:52,000
and remainder. So in the next video, we will
be seeing this diff mode in detail how it
1592
03:00:52,000 --> 03:00:59,200
actually works and how, how it is useful.
So in this particular video we saw around
1593
03:00:59,200 --> 03:01:03,230
function in the next video, we will see diff
mode, and there are a couple of more functions
1594
03:01:03,230 --> 03:01:07,780
that we will see in the upcoming videos. So
hope to see you in the next video. So in the
1595
03:01:07,780 --> 03:01:13,820
last video, we saw round function that sometimes
accepts one argument and sometimes accept
1596
03:01:13,820 --> 03:01:18,811
two arguments and behave accordingly. In this
particular video, we are going to see another
1597
03:01:18,811 --> 03:01:25,061
function dev mode. And it accepts two arguments,
two different arguments, but maybe same or
1598
03:01:25,061 --> 03:01:32,430
different arguments. And it it returns two
outputs, two numbers, two terms basically
1599
03:01:32,430 --> 03:01:38,521
quotient and remainder. For example, in this
particular case, the quotient is five, and
1600
03:01:38,521 --> 03:01:44,271
the remainder is two, because if five is divided
by if 27 is divided by five, the result is
1601
03:01:44,271 --> 03:01:50,110
five, but then the remainder is two. And the
result is returned in a kind of an ordered
1602
03:01:50,110 --> 03:01:58,471
pair. And these kind of collection in which
we have two or more elements, we call these
1603
03:01:58,471 --> 03:02:05,350
collection as tupple that we will see in detail
when we will see the data structures module
1604
03:02:05,350 --> 03:02:11,130
of this course. But right now just bear with
me that it returns two numbers, two elements,
1605
03:02:11,130 --> 03:02:17,381
and the two elements are ordered in an ordered
pair, which is called a tupple. A tupple is
1606
03:02:17,381 --> 03:02:21,521
not just an ordered pair, it can have three
more three, four, or five or seven, or maybe
1607
03:02:21,521 --> 03:02:27,350
several elements. But right now we will a
tupple is just an ordered list, which we will
1608
03:02:27,350 --> 03:02:35,780
see in detail. So let's see the working of
the stiff mode function in in Jupyter. notebook.
1609
03:02:35,780 --> 03:02:48,490
Let's see. So let's say we have dev mode.
Let's say for example, we have 34. And then
1610
03:02:48,490 --> 03:02:54,410
we have lots of them. Or maybe let's say nine,
so what do you think what will be the quotient
1611
03:02:54,410 --> 03:03:02,950
and what will be the remainder. So 918 27
So three, three is the quotient. And the remainder
1612
03:03:02,950 --> 03:03:10,870
is remainder is seven. So three is quotient
and salmon is the remainder. So and if you
1613
03:03:10,870 --> 03:03:15,391
save the result, for example, if you save
the result in a variable, let's say G. So
1614
03:03:15,391 --> 03:03:21,090
if you see the G the type of G if you if you
just type the type of if you just find the
1615
03:03:21,090 --> 03:03:26,790
type of ci it's a tupple, which we'll see
in details, and if you see the contents of
1616
03:03:26,790 --> 03:03:32,830
G if you see the contents of G the contents
of gr three and salmon, and if you want to
1617
03:03:32,830 --> 03:03:38,570
access each element independently, then you
can access the element first element, because
1618
03:03:38,570 --> 03:03:44,431
the if there are multiple elements in in a
variable normally that that kind of variables
1619
03:03:44,431 --> 03:03:50,410
are called collections that we will see in
detail later on. And these are the indexing
1620
03:03:50,410 --> 03:03:56,200
the positioning is start by zero rather than
one. So g zero means the first element of
1621
03:03:56,200 --> 03:04:02,960
G which is three in this case, and the second
element of G is one
1622
03:04:02,960 --> 03:04:10,400
at one, which is seven. So, this is basically
this is called the index or position of of
1623
03:04:10,400 --> 03:04:16,171
elements or data in this particular collection,
we will see these indexing and all these kinds
1624
03:04:16,171 --> 03:04:22,061
of collections in detail in in the in the
data structure scores, and we will see arrays
1625
03:04:22,061 --> 03:04:31,850
and strains and different kinds of structures.
But and default sometimes is, is basically
1626
03:04:31,850 --> 03:04:37,330
sometimes it is helpful. By the way you can
achieve dev mode by by another by another
1627
03:04:37,330 --> 03:04:43,410
thing. For example, if you want to achieve
a more 34 nine, you can do the same thing
1628
03:04:43,410 --> 03:04:49,120
by let's say 34 divided by double divided
by nine that will give you a quotient. And
1629
03:04:49,120 --> 03:04:54,830
the question is three and further if you write
34, remainder nine and that will give you
1630
03:04:54,830 --> 03:05:01,271
the remainder that you need. So you can call
that function Dave mode. Or you can use these
1631
03:05:01,271 --> 03:05:08,771
two there are multiple ways of doing the same
stuff. Okay? So, yes, so, I mean, sometimes
1632
03:05:08,771 --> 03:05:13,690
it's useful when you're going and knowing
this kind of function that returns quotient
1633
03:05:13,690 --> 03:05:21,950
and remainder. Okay, next function that is
more useful is is in stance, and we will see
1634
03:05:21,950 --> 03:05:28,850
this function in the in the next video. So
hope to see you in the next video okay, this
1635
03:05:28,850 --> 03:05:37,021
function is in stance, it actually returns
either true or false. And it just checks that
1636
03:05:37,021 --> 03:05:43,240
particular given data value belongs to this
type or not. For example, if you want to check
1637
03:05:43,240 --> 03:05:50,660
whether one has type integer, so, you can
check that using this function by the way,
1638
03:05:50,660 --> 03:05:57,140
you know that one is of type integer then
you may think that why on earth one should
1639
03:05:57,140 --> 03:06:03,940
be interested in checking the type of one
if somebody no it is in teacher, sometimes,
1640
03:06:03,940 --> 03:06:08,540
we have certain variables and certain data
is stored in it, and we want to check the
1641
03:06:08,540 --> 03:06:16,271
data inside it belongs to which kind of type
and in several cases the value to this variable
1642
03:06:16,271 --> 03:06:23,331
is not assigned by us It may be read from
some file or maybe through input a user give
1643
03:06:23,331 --> 03:06:29,740
some number or something like so. So, sometimes
it becomes important to check the type of
1644
03:06:29,740 --> 03:06:35,500
a particular way if we are if we are expecting
a particular type of the input and the input
1645
03:06:35,500 --> 03:06:41,721
is different than this function might be helpful.
somewhere. Either way, this is a function
1646
03:06:41,721 --> 03:06:48,591
available in Python and it checks whether
the given value has a particular type of not.
1647
03:06:48,591 --> 03:06:56,150
So is instance one int returns true is instance
1.0 integer that returns false maybe, because
1648
03:06:56,150 --> 03:07:02,100
this is a floating point number, and you can
check a particular value belongs to one of
1649
03:07:02,100 --> 03:07:07,021
the several types or not, you can give several
types in a in a tupple. And you can check
1650
03:07:07,021 --> 03:07:14,030
whether it belongs to this, this or not. So,
let's go to Jupyter Notebook and see, actually
1651
03:07:14,030 --> 03:07:21,730
how it works. So, by the way, this is the
same notebook that we have, that we are populating.
1652
03:07:21,730 --> 03:07:28,730
So, hold on with me, at the end of the day,
we'll be having one notebook complete. So,
1653
03:07:28,730 --> 03:07:38,471
is in stance is instance, let's say three
is that instance of integer The result is
1654
03:07:38,471 --> 03:07:51,932
true in this particular case, if for example,
we check whether is in stance 3.4 is that
1655
03:07:51,932 --> 03:07:58,620
nmt? Is that an end user? The answer is no
it does not end in Deezer. If for example,
1656
03:07:58,620 --> 03:08:04,940
we check if this is not in nature, then maybe
it is a float? The answer is yes. Or maybe
1657
03:08:04,940 --> 03:08:13,431
we check that. For example, if that value
is either float or integer, if it is one of
1658
03:08:13,431 --> 03:08:21,391
these, then I mean check that particular value
in this particular case 3.4 whether it belongs
1659
03:08:21,391 --> 03:08:29,250
to one of these types, we can increase these
types, for example. So, let's say we we gave
1660
03:08:29,250 --> 03:08:38,230
a complex number here and check is in stance
let's say two plus three j that's a complex
1661
03:08:38,230 --> 03:08:42,830
number. And let's say we asked whether it
is an integer or float or not, the result
1662
03:08:42,830 --> 03:08:48,980
is obviously false. And the reason is, it
is neither integer nor float or even if we
1663
03:08:48,980 --> 03:08:54,290
give string there str, so, it will still say
no it is not
1664
03:08:54,290 --> 03:09:00,750
not any of these, but maybe there is a complex
data type if you see that, that says yes,
1665
03:09:00,750 --> 03:09:08,521
because it is complex. So sometimes this is
instance becomes really useful. Next function
1666
03:09:08,521 --> 03:09:14,841
is power. So power you can you can compute
power by the way using using for example,
1667
03:09:14,841 --> 03:09:20,990
if you want to compute x raise to the power
y, you can use double star and that computes
1668
03:09:20,990 --> 03:09:27,641
exactly x raised to the power y or equivalently
you can call the function POW x comma y and
1669
03:09:27,641 --> 03:09:33,370
that will give you the same result as this
one. But power sometimes take three arguments
1670
03:09:33,370 --> 03:09:40,890
as well. And in that case, it it a it performs
the power function in a different behavior.
1671
03:09:40,890 --> 03:09:48,471
So for example, if you supply three arguments
what it does it it raise y to equate x raise
1672
03:09:48,471 --> 03:09:54,000
to the power BI whatever the result is, then
it takes the remainder by z and gives the
1673
03:09:54,000 --> 03:10:02,720
result. So let's see the functioning of this
power function in Jupyter Notebook. So let's
1674
03:10:02,720 --> 03:10:09,360
say Baba, I want to compute to raise to the
power for the result is 16. No problem. To
1675
03:10:09,360 --> 03:10:14,550
raise to the power four, I can compute the
result 16 this way as well. But here is another
1676
03:10:14,550 --> 03:10:19,641
way, how can we use this to raise to the power
for whatever the result is, then I want to
1677
03:10:19,641 --> 03:10:26,420
take the remainder, by let's say, I want to
take the remainder by seven, or two, so we've
1678
03:10:26,420 --> 03:10:31,460
got four is 16, then if we take the remainder
by seven, the result will be two. And that's
1679
03:10:31,460 --> 03:10:36,721
the result two. So that's how you can use
this power function. I'm just introducing
1680
03:10:36,721 --> 03:10:41,431
you some built in functions that are available,
there are so many functions that are available,
1681
03:10:41,431 --> 03:10:46,471
I'm just getting you comfortable with these
kinds of functions so that in future if you
1682
03:10:46,471 --> 03:10:54,051
see another function that he had not seen
here, you'll be able to use it and apply it.
1683
03:10:54,051 --> 03:11:02,100
So in this particular video, we saw this is
in stance function and this power function.
1684
03:11:02,100 --> 03:11:06,800
In the next video, we will see one more function
that will allow you to take input from the
1685
03:11:06,800 --> 03:11:13,511
user. So far, we are supplying values or assigning
values to variables directly, what if on the
1686
03:11:13,511 --> 03:11:17,631
fly, we want to give the values and those
values should be assigned to the variables.
1687
03:11:17,631 --> 03:11:22,061
So in the next video, we will see the function,
we will see a function that will allow you
1688
03:11:22,061 --> 03:11:27,011
to give input from the keyboard, hope to see
you in the next video. So in this video, we
1689
03:11:27,011 --> 03:11:35,181
are going to see a very important function
called input. This function is I mean, this
1690
03:11:35,181 --> 03:11:42,190
is beneficial for taking input from the keyboard
from the user. And the way to call this function
1691
03:11:42,190 --> 03:11:51,400
is you type input. And then you type a message
that actually describes the expected entry
1692
03:11:51,400 --> 03:11:57,190
that for example, into something if you want
somebody to or tell somebody to just incur
1693
03:11:57,190 --> 03:12:02,220
let's say, a number, you can write into a
number, or any specification to help the user
1694
03:12:02,220 --> 03:12:09,440
to enter whatever input the user want to interest
properly. One thing is that no matter what
1695
03:12:09,440 --> 03:12:19,710
the user will enter, the variable a will be
having type string, str. So even if you enter
1696
03:12:19,710 --> 03:12:26,790
a number, let's say 12, or 34, or whatever,
that will be received as a string. And then
1697
03:12:26,790 --> 03:12:31,351
there are ways to convert string to number
if that really was a number. So whatever you
1698
03:12:31,351 --> 03:12:37,181
receive using input function will be a string.
And then there are ways to deal with that
1699
03:12:37,181 --> 03:12:43,280
string, if that was a number, how to convert
that string to a number, and, and so on. So
1700
03:12:43,280 --> 03:12:51,360
for example, let's see, let's see on the Jupyter
Notebook, how it works. So let's see, for
1701
03:12:51,360 --> 03:13:04,360
example, x is equal to input, enter a number.
Let's see. And then then if I press Shift
1702
03:13:04,360 --> 03:13:10,900
Enter, a prompt will appear in front of you,
that will require you to enter a number for
1703
03:13:10,900 --> 03:13:18,440
example, if I enter, let's say 56, and then
I press enter, not Shift Enter, Enter, then
1704
03:13:18,440 --> 03:13:24,230
x will receive 56. Now, you might be thinking
this 56 is an integer, so the type of x should
1705
03:13:24,230 --> 03:13:31,910
be an integer. But this is not the case the
type of x will be a string. And the reason
1706
03:13:31,910 --> 03:13:37,320
is, whatever you enter is received as characters
five and six, even if you have entered something
1707
03:13:37,320 --> 03:13:43,100
else that would have been received as a sequence
of characters. So this is no longer a five
1708
03:13:43,100 --> 03:13:48,120
as a digit five, six as a digit six. These
are some characters sequence of characters.
1709
03:13:48,120 --> 03:13:49,811
Now, if you want to,
1710
03:13:49,811 --> 03:13:57,180
I mean, there are ways to convert this x,
for example, maybe you want, let's say, y
1711
03:13:57,180 --> 03:14:08,240
or x as int x. So this means you have now
converted this string to integer and then
1712
03:14:08,240 --> 03:14:12,751
whatever the result is, you have stored that
result in x again, if you now see the type
1713
03:14:12,751 --> 03:14:24,670
of x type of x, the result is integer. And
you can for example, print x minus 34. And
1714
03:14:24,670 --> 03:14:36,050
the result is 22. Because X was X was 56.
So this input function is I mean, it is an
1715
03:14:36,050 --> 03:14:40,440
one way by the way, if you if you're expecting
an integer or a float value, for example,
1716
03:14:40,440 --> 03:14:47,760
let's say you're expecting a float value,
then it is good to write input, let's say
1717
03:14:47,760 --> 03:14:55,620
enter a real number, maybe or any message,
any message and then at this particular time
1718
03:14:55,620 --> 03:15:03,620
at the time of import, then it is okay to
convert that thing to float and it will become
1719
03:15:03,620 --> 03:15:14,771
a float. Yeah, that's it. So, now, for example,
you enter 12.5 if you see the type of a now,
1720
03:15:14,771 --> 03:15:21,580
type of a will be float okay. But there are
problems for example, if you are if you are
1721
03:15:21,580 --> 03:15:29,021
expecting float and somebody enters into something
that is not float for example, a or let's
1722
03:15:29,021 --> 03:15:41,680
say B equals load, input enter are real number,
let's say and then you press Shift Enter and
1723
03:15:41,680 --> 03:15:48,470
somebody just interest let's say ABC. So,
now, this is not a float ABC cannot be converted
1724
03:15:48,470 --> 03:15:55,290
to a real number no matter what. So, you will
catch an error there are ways to avoid these
1725
03:15:55,290 --> 03:16:01,061
kinds of errors and programming program breaks
using exception handling and there are other
1726
03:16:01,061 --> 03:16:10,940
ways, but be careful I mean the user is not
I mean the one who is going to enter the the
1727
03:16:10,940 --> 03:16:20,100
enter the input if that that user is not restricted
enough, then you can get errors. So, I mean,
1728
03:16:20,100 --> 03:16:23,610
this is not the case that whatever you will
enter it will be converted to a float if it
1729
03:16:23,610 --> 03:16:28,580
really, if whatever you have entered is really
to convert it is really convertible to a float
1730
03:16:28,580 --> 03:16:33,440
then it can be convertible to a float, not
otherwise. And at the input time, there is
1731
03:16:33,440 --> 03:16:37,390
no restriction you cannot restrict the keyboard
to enter water or whatnot, although there
1732
03:16:37,390 --> 03:16:46,690
are ways although there are ways to do that.
So that's about the input function. So, we
1733
03:16:46,690 --> 03:16:53,230
have seen some of the functions, let me just
let me just go through quickly we have seen
1734
03:16:53,230 --> 03:17:00,150
input we have seen is in stands, we have seen
diff mode, we haven't we have seen power function,
1735
03:17:00,150 --> 03:17:07,530
we have seen the round function and there
are several others. Yes, so from now on, we
1736
03:17:07,530 --> 03:17:15,260
will be actually moving towards basically
decision making based sometimes we will use
1737
03:17:15,260 --> 03:17:18,460
these kind of functions, mostly you will be
using input function, but sometimes we'll
1738
03:17:18,460 --> 03:17:25,600
be using maybe other functions like these
functions. And sometimes we will be doing
1739
03:17:25,600 --> 03:17:29,890
decision making based on the ease and and
stuff like so, one thing that I want to tell
1740
03:17:29,890 --> 03:17:35,930
you is if for example, you know the function
name, some function, let's say like power,
1741
03:17:35,930 --> 03:17:41,841
you know, that POW power is a function, but
you do not know how to use that function.
1742
03:17:41,841 --> 03:17:48,610
One way is to just type question mark in front
of it, and then just press Shift Enter,
1743
03:17:48,610 --> 03:17:54,150
and in front of you, the documentation of
the power will open up so it will tell that
1744
03:17:54,150 --> 03:18:01,351
this is power, that's how it should be called
and then some description will be in front
1745
03:18:01,351 --> 03:18:07,340
of you that equivalent to x raised to the
power y with no arguments, the two arguments
1746
03:18:07,340 --> 03:18:11,630
are equivalent to x raised to the power y
remainder with z with three arguments and
1747
03:18:11,630 --> 03:18:18,980
so on, if you want to see implementation of
this function as well. We will see the functions
1748
03:18:18,980 --> 03:18:24,850
later on but if you want to see more about
the help, you can type the double Sam equal
1749
03:18:24,850 --> 03:18:37,750
a double question mark and more things should
be open up in front of you. So, in this particular
1750
03:18:37,750 --> 03:18:44,610
case, the small function does not have an
implementation in Python. So, the single question
1751
03:18:44,610 --> 03:18:53,050
mark and double question mark are the same
at one more way is to use the help function
1752
03:18:53,050 --> 03:19:02,150
help out and you will get a lot of information
about the power how for example, help on built
1753
03:19:02,150 --> 03:19:06,480
and function power in module built in. So
this is power this is equivalent to this some
1754
03:19:06,480 --> 03:19:13,190
key types and stuff like so, or for example,
you want to know how can I use the input function
1755
03:19:13,190 --> 03:19:21,190
for example, so you can write help on input
and this is how this can be used. So sometimes
1756
03:19:21,190 --> 03:19:25,690
it is okay if you know the if you know the
name of some function, and you know how to
1757
03:19:25,690 --> 03:19:30,830
use it, you can just open up the documentation
right here in Jupyter Notebook by either using
1758
03:19:30,830 --> 03:19:39,190
a help function or you can use just a question
mark in front of the name and so on. So, that's
1759
03:19:39,190 --> 03:19:46,240
about the functions. In the next video, we
will be seeing the power of comparisons and
1760
03:19:46,240 --> 03:19:53,771
the decision making or sometimes called the
control flow. So the real fun will begin from
1761
03:19:53,771 --> 03:19:59,060
the next video because we will be actually
deciding which part of the code should run
1762
03:19:59,060 --> 03:20:04,410
and which part should Not run based on based
on certain conditions. So hope to see you
1763
03:20:04,410 --> 03:20:13,340
in the next video. Okay, we are in control
flow, the most interesting part of any programming
1764
03:20:13,340 --> 03:20:21,950
language will assume that you have two numbers,
you have taken two numbers from the user a,
1765
03:20:21,950 --> 03:20:29,211
you've taken that number from the user using
input, I have not supplied the input message
1766
03:20:29,211 --> 03:20:34,010
here, the message is optional. It's a description
if you supply that that's okay, if you don't
1767
03:20:34,010 --> 03:20:39,440
supply even that, that's okay. So A is some
number the user will supply when the code
1768
03:20:39,440 --> 03:20:44,930
will run B is some number the user will supply
when the code will run. Now, once you have
1769
03:20:44,930 --> 03:20:49,560
a and b in front of you, obviously the user
will supply that on the fly, you don't know
1770
03:20:49,560 --> 03:20:54,850
what the value of a and b are. Because when
the program will run, only at that time, the
1771
03:20:54,850 --> 03:21:01,090
A will be populated and B will be populated.
Your task is whatever the value of a is that
1772
03:21:01,090 --> 03:21:04,521
is that you don't know whatever the value
of b is that you don't know, the user will
1773
03:21:04,521 --> 03:21:09,440
supply that value those values, your task
is to print the value that is bigger than
1774
03:21:09,440 --> 03:21:15,030
both. So for example, if a is bigger than
B, then print a if b is bigger than a, then
1775
03:21:15,030 --> 03:21:21,101
print B. So whatever the bigger value is,
print that value. Let's say that's your task.
1776
03:21:21,101 --> 03:21:30,640
How can you do that? So the question is how
does Python allows us does Python allow us
1777
03:21:30,640 --> 03:21:37,890
to do that, for example, if a is bigger than
we should print a, if b is bigger than we
1778
03:21:37,890 --> 03:21:43,381
should print B, remember again, and again
we are we are talking in terms of if A is
1779
03:21:43,381 --> 03:21:51,160
bigger, if so this is this is this is what
if a is larger than B, then this condition
1780
03:21:51,160 --> 03:21:56,870
will be true. This is like the comparison.
So this is true, but then we must have an
1781
03:21:56,870 --> 03:22:05,580
F condition as well. If A is bigger than to
what, so if a is bigger than B, then do certain
1782
03:22:05,580 --> 03:22:10,120
things. Otherwise, don't do that. Those kinds
of things. So this if condition is really,
1783
03:22:10,120 --> 03:22:18,720
really powerful, and is available in all programming
languages. In here, for example, let's see
1784
03:22:18,720 --> 03:22:25,950
if a is an input B is an input, writing an
if condition, that's if is a keyword. That's
1785
03:22:25,950 --> 03:22:30,840
a comparison that we have done earlier as
well. And then the syntax required a colon
1786
03:22:30,840 --> 03:22:36,940
in front of that. So if this condition is
true, if this result, if this comparison results
1787
03:22:36,940 --> 03:22:44,530
to remember the comparisons, they return Boolean
values, if this comparison, if this, whatever
1788
03:22:44,530 --> 03:22:51,990
the result of this operation is if that is
true, then you go into this block. And whatever
1789
03:22:51,990 --> 03:22:56,790
the statement inside is do that, for example,
print b is greater than a.
1790
03:22:56,790 --> 03:23:03,750
Now my question is, is that is that done?
Are we done with the task, the task was to
1791
03:23:03,750 --> 03:23:11,120
print the bigger number. If b is greater than
a, then B will be printed then or they might
1792
03:23:11,120 --> 03:23:15,891
have printed, for example, we might have printed
rather than writing this we might have might
1793
03:23:15,891 --> 03:23:24,080
have printed, let's say just print B because
b is bigger. If b is not bigger than a, what
1794
03:23:24,080 --> 03:23:33,050
will? What we will do them. So yeah. If b
is bigger than a then B will be printed? Yes.
1795
03:23:33,050 --> 03:23:39,160
Because then you will be inside here. If b
is not bigger than if this condition is false.
1796
03:23:39,160 --> 03:23:46,140
We will do what then? So that's a question.
So right now I'm just coding this in Jupyter.
1797
03:23:46,140 --> 03:23:51,450
notebook. And then we will see how can we
deal with that if b is not bigger than a kind
1798
03:23:51,450 --> 03:23:58,510
of condition? So let's first see the blessings
of if condition and Jupyter Notebook. Yeah,
1799
03:23:58,510 --> 03:24:08,530
so let's say a is an integer. Let's say you're
expecting an integer input. input, let's say
1800
03:24:08,530 --> 03:24:20,290
and then you write if, let's say B is again,
an integer input maybe. And let's say if a
1801
03:24:20,290 --> 03:24:30,910
is greater than b, then print a. That's it.
That's your program. Remember, this indentation,
1802
03:24:30,910 --> 03:24:37,021
I have not written this print here. This is
the indentation that defines the block of
1803
03:24:37,021 --> 03:24:47,460
a let's say if I want to print a, then I want
to print, let's say, I am still inside. If
1804
03:24:47,460 --> 03:25:01,590
condition, condition, and so whatever that
starts from this, whatever that starts Form
1805
03:25:01,590 --> 03:25:09,850
whatever that starts from this alignment,
if I write something here, let's say x is
1806
03:25:09,850 --> 03:25:15,801
equal to five, all that block all that block
is called the body of the if condition, if
1807
03:25:15,801 --> 03:25:24,600
it starts from this alignment, If however,
I I typed a statement, but I typed that statement
1808
03:25:24,600 --> 03:25:30,280
in that kind of alignment, the alignment like
this, this is no longer inside the if condition.
1809
03:25:30,280 --> 03:25:40,551
So, for example, here I type I am outside
the if condition. So, the purpose of writing
1810
03:25:40,551 --> 03:25:45,471
these multiple lines is just the if condition
does not require to contain only one line
1811
03:25:45,471 --> 03:25:52,561
of code, it can contain a whole block of code
multiple lines of codes. So, this is no longer
1812
03:25:52,561 --> 03:25:57,980
inside the if condition. So, now we will take
input a input B, whatever the numbers will
1813
03:25:57,980 --> 03:26:03,320
be, if the value in a will be larger than
B, then this will be printed and this will
1814
03:26:03,320 --> 03:26:09,311
be printed. Once these two are printed, then
this has to be printed regardless of the values
1815
03:26:09,311 --> 03:26:15,570
of a and b, because this does not this last
sprint statement, it does not depend upon.
1816
03:26:15,570 --> 03:26:20,360
This does not depend upon the values of a
and b, it has the if condition has no impact
1817
03:26:20,360 --> 03:26:24,820
on that, that is just a sequence of statements.
the if condition, the statement inside the
1818
03:26:24,820 --> 03:26:30,290
if are just these two. For example, if a is
not bigger than B, then neither this will
1819
03:26:30,290 --> 03:26:36,300
execute, nor this will execute. But this will
still execute because this is this has nothing
1820
03:26:36,300 --> 03:26:43,810
to do with the condition. So let's run this
code and see how it works. So let's set the
1821
03:26:43,810 --> 03:26:48,870
value of a see the power of descriptions.
If we could have written a description, then
1822
03:26:48,870 --> 03:26:52,930
the description could have been could have
appeared here. But let's say this is the value
1823
03:26:52,930 --> 03:27:02,310
of a let's say 12. The value of b let's say,
let's say 10. In this particular case, because
1824
03:27:02,310 --> 03:27:07,980
the value of b is 10, the value of a is 1212
is bigger than B if this condition is true,
1825
03:27:07,980 --> 03:27:12,460
this statement becomes true. Whenever this
condition becomes true, you're inside the
1826
03:27:12,460 --> 03:27:19,210
prints you are inside the if condition. Now
this print executes and you're you get well
1827
03:27:19,210 --> 03:27:27,420
this print executes and you get I am still
inside the if condition, and this has to execute
1828
03:27:27,420 --> 03:27:33,280
no matter what the values of NBR so now let
me read on this and give other values of a
1829
03:27:33,280 --> 03:27:41,180
and b let's say the value of a is 10. And
the value of b is let's say 45. Now, this
1830
03:27:41,180 --> 03:27:47,200
can this condition becomes false because 10
is greater than 45 this is not true, this
1831
03:27:47,200 --> 03:27:52,220
is false. So whenever this condition is false,
you never land inside the if condition
1832
03:27:52,220 --> 03:27:57,190
and you go out from the if condition. So these
are the statements that are inside the if
1833
03:27:57,190 --> 03:27:58,190
condition
1834
03:27:58,190 --> 03:28:03,331
they cannot execute because because you never
visit them, they can only be executed if condition
1835
03:28:03,331 --> 03:28:08,210
becomes true. So then once you're out the
if condition that's the statement there is
1836
03:28:08,210 --> 03:28:15,642
going to be executed anyways. So yeah, so
that's the flavor of if condition on the see
1837
03:28:15,642 --> 03:28:21,521
and making and this is the comparison operator
that returns a Boolean value. You may have
1838
03:28:21,521 --> 03:28:26,040
different kinds of comparisons here or combination
of comparisons here No, no problem depending
1839
03:28:26,040 --> 03:28:32,330
upon your logic. But the question is, are
we done we are going to print only the bigger
1840
03:28:32,330 --> 03:28:37,940
number we have, we have printed the one that
is if a is bigger, we have printed that what
1841
03:28:37,940 --> 03:28:42,971
if if b is bigger, we have not solved the
task yet. This is the task we have not solved
1842
03:28:42,971 --> 03:28:54,641
the task yet. So how to do it. Okay. So yeah,
it looks like complicated. How to print only
1843
03:28:54,641 --> 03:29:02,190
that number that is bigger. So if b is bigger
than a, then we will print B. Maybe Maybe
1844
03:29:02,190 --> 03:29:08,750
we should make maybe we should apply another
if condition. If b is bigger than a then print
1845
03:29:08,750 --> 03:29:17,271
B. If A is bigger than B, then print eight,
maybe. Yeah, why not? So
1846
03:29:17,271 --> 03:29:20,660
um,
1847
03:29:20,660 --> 03:29:27,521
so for example, let's go to Jupyter Notebook
and, and write the following. Let me let me
1848
03:29:27,521 --> 03:29:40,890
write a whole new program here. A equals and
import. Okay, let's do not have a message
1849
03:29:40,890 --> 03:30:01,800
and input and then if A is bigger than B,
then print a. Okay. However, if B is bigger
1850
03:30:01,800 --> 03:30:11,850
than a then print B, I guess we are done.
If this condition becomes true, then we are
1851
03:30:11,850 --> 03:30:18,120
here and we know if this condition becomes
true, then this condition cannot become true,
1852
03:30:18,120 --> 03:30:22,440
because it cannot happen there is because
then B as well as B is bigger than a This
1853
03:30:22,440 --> 03:30:27,230
cannot happen. So, whatever the bigger number
will be that will be executed further you
1854
03:30:27,230 --> 03:30:32,780
can see I have this if condition and this
if condition they are aligned in a way that
1855
03:30:32,780 --> 03:30:40,550
this if condition is not this the second if
condition is not inside the body of the first
1856
03:30:40,550 --> 03:30:46,260
if condition, we will see such cases such
cases when this is required. But right now,
1857
03:30:46,260 --> 03:30:52,840
I guess we are done. If A is bigger than B,
then print a, if b is bigger than a then print
1858
03:30:52,840 --> 03:30:57,810
B and only one of these if conditions will
become true, because A is bigger than B B
1859
03:30:57,810 --> 03:31:04,010
is bigger than a, these two statements cannot
be true at the same time. So, let's see. So
1860
03:31:04,010 --> 03:31:11,730
A is 10, b is 45. So the answer is 45. Well,
because 45 is bigger. So let's run it again.
1861
03:31:11,730 --> 03:31:20,380
So A is let's say 22. b is let's say four
and the result is 22. Because 32 is bigger,
1862
03:31:20,380 --> 03:31:26,311
I guess we are done with the task, we have
used this if condition twice to achieve the
1863
03:31:26,311 --> 03:31:33,080
task to print the number that is bigger and
both the numbers we we took both the numbers
1864
03:31:33,080 --> 03:31:41,870
from the keyboard Yeah, I end this video here.
And in the next video, I will tell you more
1865
03:31:41,870 --> 03:31:47,370
features of this if condition particularly
the L statement, whatever what we have done
1866
03:31:47,370 --> 03:31:54,021
recently with another if could could be achieved
through an L statement that is more powerful
1867
03:31:54,021 --> 03:32:00,660
and more readable. So in the next video, I
will talk about ELS statement which is a part
1868
03:32:00,660 --> 03:32:07,510
of F so hope to see you in the next video.
Okay, in the last video, we saw if condition
1869
03:32:07,510 --> 03:32:15,670
and we actually had an example in which we
wanted to know we wanted to just print the
1870
03:32:15,670 --> 03:32:22,590
greater number. So we input a number a we
input a number B and if b is greater than
1871
03:32:22,590 --> 03:32:29,630
a we printed the is greater than eight, then
we applied another if condition to check if
1872
03:32:29,630 --> 03:32:40,180
a is greater than b, then paint a the else
clause or the else part of f is as as the
1873
03:32:40,180 --> 03:32:47,591
name suggests, if this condition is true.
So, if this condition is true, this particular
1874
03:32:47,591 --> 03:32:53,440
condition is true, then go there. If this
is not true, which means else if this is true,
1875
03:32:53,440 --> 03:33:01,021
then go there, else go there. So if this is
true, then you learned here, if this is false,
1876
03:33:01,021 --> 03:33:08,200
then you learn else part for sure. And this
else is I mean, if b is greater than a if
1877
03:33:08,200 --> 03:33:13,380
this condition is true, then you print this
thing. Otherwise, a might be greater than
1878
03:33:13,380 --> 03:33:19,721
B or A might be equal to b either way you
learn in else part. So this if and else they
1879
03:33:19,721 --> 03:33:26,591
both have this alignment, but then the block
of ELLs started from this particular alignment,
1880
03:33:26,591 --> 03:33:33,570
maybe you have more statements here, the alignment
of this if block structure from here, and
1881
03:33:33,570 --> 03:33:41,100
you may have more statements here. So let's
go to the Jupyter Notebook and see the else
1882
03:33:41,100 --> 03:33:59,271
running. So let's say a equals and input and
B is
1883
03:33:59,271 --> 03:34:15,910
B is int input and we say okay, if a is greater
than b, then brand a
1884
03:34:15,910 --> 03:34:35,700
else else rent else brand be elsewhere outspent
B. Now B will be printed, even if it is equal
1885
03:34:35,700 --> 03:34:46,021
to A or if it is greater than a either way,
B will be printed. So let's just see. Let's
1886
03:34:46,021 --> 03:34:55,841
just run this and see what happens. So Shift
Enter. So input a number. So A is let's say
1887
03:34:55,841 --> 03:35:03,720
10, and B is let's say, 12. So what do you
think when I will press enter what will be
1888
03:35:03,720 --> 03:35:13,860
printed, B or A, B, B is printed, that's what
B is printed. Now, if I run this again, and
1889
03:35:13,860 --> 03:35:21,370
a is done, and B is done, still the 10 will
be printed. So let's modify it, let's, let's
1890
03:35:21,370 --> 03:35:37,021
just say, print. If part. So that means we
landed in if part. Otherwise, we landed in
1891
03:35:37,021 --> 03:35:49,100
Ellsberg. So just to be more elaborated, let's
say so 10 and 10. And we landed in L sport.
1892
03:35:49,100 --> 03:35:53,670
And the reason is if a is greater than b,
so 10 is greater than b 10 is greater than
1893
03:35:53,670 --> 03:36:00,570
10. False. So you got two L's, and the LS
block, the whole block just executed. So that's
1894
03:36:00,570 --> 03:36:07,771
what else is, it's really very nice to have
an L state or whatever this whenever the,
1895
03:36:07,771 --> 03:36:12,500
if this is false, whatever that condition
is, if that is false, then you learn in else.
1896
03:36:12,500 --> 03:36:35,110
So yeah, that's the health part simply now,
okay. So, we have this f l structure, we can
1897
03:36:35,110 --> 03:36:43,600
have one more power with this F, what if we
want, if a if b is greater than a, then you
1898
03:36:43,600 --> 03:36:53,340
print B. Else, if A is equal to b, then you
print they're equal. And if this is false,
1899
03:36:53,340 --> 03:36:58,040
and this condition is false, if both these
conditions are false, then you go to else
1900
03:36:58,040 --> 03:37:06,101
part. So basically, if else if else if else,
if else, so, you can have really deep structure
1901
03:37:06,101 --> 03:37:14,790
for example, in this particular example, if
b is larger than a, then you land in this
1902
03:37:14,790 --> 03:37:24,320
part else, if this L is just short form of
else, else means B is not greater than a else,
1903
03:37:24,320 --> 03:37:33,900
you can have another check elsif A is equal
to b, then do what?
1904
03:37:33,900 --> 03:37:34,900
l
1905
03:37:34,900 --> 03:37:40,771
l, if we can have one more check, we can have
one more check, we can have several checks,
1906
03:37:40,771 --> 03:37:47,051
and then else else will only execute if all
if conditions or elsif parts on top. Their
1907
03:37:47,051 --> 03:37:53,811
conditions, they are false, and only then
else will be execute. So let's see these l
1908
03:37:53,811 --> 03:38:06,720
diff running on Jupyter. notebook. Okay, so
let's say a is and so rather than taking inputs,
1909
03:38:06,720 --> 03:38:16,030
let's say is one, B is let's say five. Let's
say we have taken these inputs is one B is
1910
03:38:16,030 --> 03:38:33,450
five, if A is if a is equal to b, then the
word rent equal l l F, which means else if
1911
03:38:33,450 --> 03:38:39,910
now, because this is if you should you have
to write a condition here, which will be either
1912
03:38:39,910 --> 03:38:54,600
true or false. If A is larger than B, then
do what? then print, let's say, a. And else,
1913
03:38:54,600 --> 03:39:07,980
let's say your brain be okay. So that's it.
And this statement, rent is not in if condition
1914
03:39:07,980 --> 03:39:16,940
Not, not in if this is outside complete, this
is complete if condition with all its L's
1915
03:39:16,940 --> 03:39:23,771
and LDAP parts, and this is no longer inside.
So let's run this. What do you think what
1916
03:39:23,771 --> 03:39:29,810
will be the result if A is one B is five,
then else bar is going to be run because A
1917
03:39:29,810 --> 03:39:34,700
is not equal to B, A is equal to b that's
false is larger than B that is also false.
1918
03:39:34,700 --> 03:39:40,590
So you will learn in export and B will be
printed and then a statement will be printed
1919
03:39:40,590 --> 03:39:49,270
which is not an F. So yeah, so B is printed
and not an F. If b is 10, then what will happen?
1920
03:39:49,270 --> 03:39:55,660
A equals to B that is false, so you will not
land here. Else if A is larger than B true.
1921
03:39:55,660 --> 03:40:01,311
You will land here because you land here else
will not execute. So He will be printed and
1922
03:40:01,311 --> 03:40:10,200
then not enough. If A is 10 and b is also
banned, let's say, then you have equal. Yeah,
1923
03:40:10,200 --> 03:40:24,940
so that's elsif. Okay, so that's about if
else if else if or short form is lf l structure.
1924
03:40:24,940 --> 03:40:30,480
In the next video, we will be talking more
about this if else if else structure in a
1925
03:40:30,480 --> 03:40:36,540
bit more detail. And we will also be giving
you a short form of this this guide of ELLs
1926
03:40:36,540 --> 03:40:44,400
if elsif elberfeld of structure. So hope to
see you in the next video. Okay, one way of
1927
03:40:44,400 --> 03:40:50,730
writing this, if elsif else kind of structure
there is a short form as well, which is written
1928
03:40:50,730 --> 03:40:58,430
down here in a in this green color, for example.
This is kind of a same code that we saw in
1929
03:40:58,430 --> 03:41:03,980
the last video, but that's the short form,
let's say a equals nine and B equals 10, then
1930
03:41:03,980 --> 03:41:13,310
print a if A is larger than B, else print
this particular thing, if A is equal to b,
1931
03:41:13,310 --> 03:41:19,610
l sprint that this is exactly the same kind
of structure, for example, print a, if A is
1932
03:41:19,610 --> 03:41:25,960
larger than B, so you just read that if a
is larger than B, then print a else if A is
1933
03:41:25,960 --> 03:41:33,600
equal to b, then print equal, else print that.
So that is kind of a short form of writing
1934
03:41:33,600 --> 03:41:41,800
this if Elif else kind of structure. But I
will, I will recommend to to to use, I'm in
1935
03:41:41,800 --> 03:41:47,040
the structure in this particular horizontal
form. Rather than writing that in this particular
1936
03:41:47,040 --> 03:41:52,390
way. Because this kind of structure, that
horizontal kind of structure is much more
1937
03:41:52,390 --> 03:41:57,270
readable, much more manageable. And this might
be this structure might be confusing some
1938
03:41:57,270 --> 03:42:03,230
time for for some kind of readers or, and
also if this structure goes on and on and
1939
03:42:03,230 --> 03:42:09,770
on, which we'll see in a in an example today.
Writing that writing very deep and lengthy
1940
03:42:09,770 --> 03:42:16,640
structures in short form is not very feasible.
So although but but this feature is there
1941
03:42:16,640 --> 03:42:21,790
if you like to write if elsif else kind of
structure in this way, this is available in
1942
03:42:21,790 --> 03:42:28,771
Python. Okay, let's let's get a good grip
on this f LS f l structure on Jupyter. notebook.
1943
03:42:28,771 --> 03:42:35,850
Let's move on to Jupyter Notebook. To see
an example, just an example. So let's say
1944
03:42:35,850 --> 03:42:49,360
the example is user will input a number, let's
say int input, let's say and enter marks,
1945
03:42:49,360 --> 03:42:56,190
let's say enter marks for a particular subject,
let's say user with enter some some marks.
1946
03:42:56,190 --> 03:43:06,600
And our goal is if the marks are larger than
85, then we will print a grade. If the marks
1947
03:43:06,600 --> 03:43:14,771
are larger than larger than 80, but smaller
than smaller, so if the marks are larger equal
1948
03:43:14,771 --> 03:43:25,900
to 85, then we will print a grade. Else if
marks are larger equal to 80, but smaller
1949
03:43:25,900 --> 03:43:35,440
than 85, then we will print a minus grade.
And if else if if marks are larger than larger
1950
03:43:35,440 --> 03:43:45,150
equal to 75, but smaller than 80, we will
paint we will print for example, b grade for
1951
03:43:45,150 --> 03:43:50,780
example, b grade, and so on, let's print this
whole nested structure that let's let's make
1952
03:43:50,780 --> 03:43:57,190
this else. if else if elsif kind of structure
a little empty, let's let's get comfortable
1953
03:43:57,190 --> 03:44:07,390
with it. So if a is larger than or equal to
85 to enhance readability, it is good to include
1954
03:44:07,390 --> 03:44:14,860
a space is a space after the variable and
space but don't actually write the space inside
1955
03:44:14,860 --> 03:44:21,850
there because larger and equal to the combined
without space is an operator. So if a is larger
1956
03:44:21,850 --> 03:44:46,650
than 85, then print let's say a grade rate
l if A is a is larger or equal to a D and
1957
03:44:46,650 --> 03:44:56,460
E is smaller than 85. So let me let me write
this in a more readable form. Else if A is
1958
03:44:56,460 --> 03:45:06,671
smaller than 85 and is larger or equal to
80 then we should do what it is sometimes
1959
03:45:06,671 --> 03:45:13,210
good to include these kind of parentheses
sometimes it is good just to make these things
1960
03:45:13,210 --> 03:45:20,811
more readable that this is one block. This
is one this is one Boolean, this is one Boolean,
1961
03:45:20,811 --> 03:45:26,790
this is one to see and this font is E and
although not writing the parenthesis is also
1962
03:45:26,790 --> 03:45:35,560
okay. But writing the parenthesis make code
a little more readable. So, for example, if
1963
03:45:35,560 --> 03:45:42,310
a is smaller than 85 and a is larger than
80, if that is true, So, remember and is true
1964
03:45:42,310 --> 03:45:47,040
only when the left side is true and right
side both are true, then this whole condition
1965
03:45:47,040 --> 03:45:54,230
becomes true. And I promised you that I will
show you the power of comparisons and actually
1966
03:45:54,230 --> 03:46:00,550
combining the Boolean variables using ands
and ORS and stuff like so. So here you're
1967
03:46:00,550 --> 03:46:19,350
seeing the one. In that case, let's say brand.
Let's say a binary sprayed and Elif if he
1968
03:46:19,350 --> 03:46:42,700
is if he is smaller than if he is smaller
than 80. And a is bigger or equal to 75. If
1969
03:46:42,700 --> 03:46:46,940
that's the case, then what should we do? Let
me omit the parentheses just to show that
1970
03:46:46,940 --> 03:46:52,260
whether writing parenthesis or not writing
parentheses is perfectly okay. I just recommend
1971
03:46:52,260 --> 03:46:59,920
right parenthesis, so the code becomes much
more readable than otherwise. Okay, then we
1972
03:46:59,920 --> 03:47:16,670
have Brent, let's say, b grade. And let's
say one more lF lF. If A is smaller than 75.
1973
03:47:16,670 --> 03:47:22,370
And a is larger or equal to let's say
1974
03:47:22,370 --> 03:47:43,740
70. samedi, then Brent b minus grade, let's
say. And let's just finish this let's else
1975
03:47:43,740 --> 03:47:55,421
print. below. Average, for example, let's
say that's it, that's our, that's our record.
1976
03:47:55,421 --> 03:48:02,601
So, we will we will enter numbers, if the
number is greater than 85, then a grade if,
1977
03:48:02,601 --> 03:48:09,530
when this condition becomes true, then this
print will execute. And we will out of the
1978
03:48:09,530 --> 03:48:16,240
structure right there. If this condition is
false, then this condition will be checked.
1979
03:48:16,240 --> 03:48:21,460
If this condition becomes true, then this
print will execute. And we will be out of
1980
03:48:21,460 --> 03:48:28,440
this structure. If this is false, and this
is false, then this will be checked. If this
1981
03:48:28,440 --> 03:48:34,310
is true, then we print degrade and we are
out. But if this is false, then this will
1982
03:48:34,310 --> 03:48:40,910
be checked. And if this is true, then we'll
print b minus grade. And we will be out. If
1983
03:48:40,910 --> 03:48:47,010
this is also false, then we will dive into
L sport and we will say okay, below average.
1984
03:48:47,010 --> 03:48:57,100
So let's see, for example, let's say the marks
are at two. So a minus grade. That, that that
1985
03:48:57,100 --> 03:49:01,940
that makes sense, a minus grade because the
marks are smaller than 85 and larger than
1986
03:49:01,940 --> 03:49:11,530
larger or equal to 80. So a minus grade. Let's,
let's run this again. And we have let's say
1987
03:49:11,530 --> 03:49:20,790
marks let's say 64 below average. Okay, great.
So you see this if Elif, Elif Elif else this
1988
03:49:20,790 --> 03:49:28,440
can go as long as you want, depending upon
your logic. So great. And further, you can
1989
03:49:28,440 --> 03:49:34,770
combine several comparisons several billions,
together with ands and ORS, and nots, whatever
1990
03:49:34,770 --> 03:49:42,350
you whatever you like to like to do. Let me
give you one more or one more beautiful thing.
1991
03:49:42,350 --> 03:49:48,561
let's let's let's create an L without writing
an else or let's let's just let's just write
1992
03:49:48,561 --> 03:49:56,941
lF and implement ELS completely so we are
not going to write ELS explicitly, but we
1993
03:49:56,941 --> 03:50:02,850
are going to write a program that actually
simulates ELS So let's see, if a equals let's
1994
03:50:02,850 --> 03:50:17,490
say, three. If A is larger than 10, then Brent
let's say larger than that. Now, we are not
1995
03:50:17,490 --> 03:50:22,470
going to write else, but we are going to achieve
the aerosport.
1996
03:50:22,470 --> 03:50:25,470
Tell If
1997
03:50:25,470 --> 03:50:26,970
not,
1998
03:50:26,970 --> 03:50:41,420
a is bigger than 10. To see, then print you
see that I mean, that's beautiful. If this
1999
03:50:41,420 --> 03:50:48,780
condition is true, then go there. If this
condition is false, then not have false is
2000
03:50:48,780 --> 03:50:54,480
true, then you learn here. And you need not
to write an expert if you want just I've implemented
2001
03:50:54,480 --> 03:51:03,890
I have implemented l spark using l f. So see
that. So l sparks so we are right now Spark.
2002
03:51:03,890 --> 03:51:13,940
If A is let's say 13, then we will think okay,
rather than just for fun, just for fun, okay.
2003
03:51:13,940 --> 03:51:23,130
Okay, great. So, we saw if condition it's
shorthand and LDAP structure in in a bit more,
2004
03:51:23,130 --> 03:51:29,360
lengthy way. So in the next video, we will
see if condition inside or in the body of
2005
03:51:29,360 --> 03:51:35,860
another if condition, which is called a nested
F. So hope to see you in the in the next video.
2006
03:51:35,860 --> 03:51:42,400
In the last video we saw if lF structure,
in this particular video, we will see nested
2007
03:51:42,400 --> 03:51:49,311
F, or are simply called if inside the body
of another F. So let's take an example to
2008
03:51:49,311 --> 03:51:55,521
understand what nested if condition is simply
we can understand if condition inside another
2009
03:51:55,521 --> 03:52:02,630
if condition, that's all rest of the story
is same. The way it works, it works even if
2010
03:52:02,630 --> 03:52:08,980
it is inside the body of another if or or
anywhere, actually. So let's say we have input
2011
03:52:08,980 --> 03:52:15,350
a number, and then we check if x is larger
than 10, then you move inside the if condition.
2012
03:52:15,350 --> 03:52:20,610
If that is true. If that is false, then you
are here, whatever you write here, it will
2013
03:52:20,610 --> 03:52:25,400
work from here. But let's say x is greater
than 10, then you print your number is greater
2014
03:52:25,400 --> 03:52:32,880
than 10, your number is above 10. Let's say
let's see Brent that now after this, after
2015
03:52:32,880 --> 03:52:39,150
this statement, you move to the statement,
and you just make another check if x is larger
2016
03:52:39,150 --> 03:52:47,920
than 20. Now you see this if condition. This
particular statement is inside this particular
2017
03:52:47,920 --> 03:52:55,280
if condition, if this, this condition becomes
true only then you dive in, otherwise you're
2018
03:52:55,280 --> 03:53:00,940
not. So here you're checking if x is larger
than 10, then you move inside and inside you're
2019
03:53:00,940 --> 03:53:05,920
making more checks. So for example, if x is
larger than 10, then you print or do some
2020
03:53:05,920 --> 03:53:11,300
stuff here, then you apply Further more, more
checks more graduality more, whatever your
2021
03:53:11,300 --> 03:53:16,850
logic is. So let's say here you're checking
if x is larger than 20. Now, if this condition
2022
03:53:16,850 --> 03:53:24,480
is true, then you move here else now this
else is of this if if x is not larger than
2023
03:53:24,480 --> 03:53:31,340
20, then you move to this else l squat and
you're here. So and we can have another if
2024
03:53:31,340 --> 03:53:38,800
inside this particular F or an F inside this
L sport and so on. So if inside an F is called
2025
03:53:38,800 --> 03:53:47,940
nested if and we can have I mean deep structures,
for example, if then something then if then
2026
03:53:47,940 --> 03:53:54,560
something then if so maybe we can have a very
lengthy structure if nested if structure depending
2027
03:53:54,560 --> 03:54:03,480
upon the logic. So let's get ourselves comfortable.
As always, by writing the code on Jupyter
2028
03:54:03,480 --> 03:54:10,610
Notebook because that makes much more sense.
When we see things running on, on on the notebook.
2029
03:54:10,610 --> 03:54:24,060
So let's say a is let's say again, and let's
say we take some number and if a is larger
2030
03:54:24,060 --> 03:54:42,000
than 10, then we say okay, Brent, larger than
10 and do more stuff, Brent. That's inside.
2031
03:54:42,000 --> 03:54:53,900
If condition, okay, then then maybe we have
another check if A is larger than 20 then
2032
03:54:53,900 --> 03:55:08,860
say rent greater than
20 Yeah, greater than 20. And you can rent
2033
03:55:08,860 --> 03:55:31,900
now rent inside the nested if, okay. Else
rent l sprint, smaller or equal to 20, smaller
2034
03:55:31,900 --> 03:55:46,140
equal to 20. And then brand, for example,
inside the L spark of nested if that's it,
2035
03:55:46,140 --> 03:56:00,020
and you can print here, brand outside all
it's fine. So that's it that's that that's
2036
03:56:00,020 --> 03:56:05,150
the structure. So let's see, let's give an
input which is larger than, by the way, if
2037
03:56:05,150 --> 03:56:10,511
input is not larger than 10, this if condition
is false, then you directly dive to this print
2038
03:56:10,511 --> 03:56:16,780
statement and all this structure is not going
to be executed, this is this complete thing
2039
03:56:16,780 --> 03:56:21,910
is called the body of this if condition, and
the body will only execute if the condition
2040
03:56:21,910 --> 03:56:26,900
becomes true, whether that condition is just
a single condition, or you have a combination
2041
03:56:26,900 --> 03:56:32,800
of a lot of comparisons and a lot of Booleans
whatever, if this condition becomes true,
2042
03:56:32,800 --> 03:56:37,810
whatever that condition takes form of, then
Then and only then you dive into this part.
2043
03:56:37,810 --> 03:56:42,641
And when you are in this part, then that's
a whole new universe, then you're on its own
2044
03:56:42,641 --> 03:56:50,330
in the new part, in the new part, for example,
if this condition becomes true, then you are
2045
03:56:50,330 --> 03:56:55,210
in this part, that's the body of this particular
if condition, and that's the body of the else
2046
03:56:55,210 --> 03:57:02,540
part, see the the body of the top if condition
has this kind of alignment, all the statements
2047
03:57:02,540 --> 03:57:08,660
that are in the body of if condition, they
start the same alignment, and all the conditions
2048
03:57:08,660 --> 03:57:12,750
all the statements that are in the body of
this particular if condition, they have their
2049
03:57:12,750 --> 03:57:18,940
own alignment, and this indentation is necessity
just to define, for example, which statement
2050
03:57:18,940 --> 03:57:26,450
is in what kind of block for example, if I
just press a tab, then another tab, then this
2051
03:57:26,450 --> 03:57:33,000
print statement is in this L sport and this
is the indentation that is defining the placement
2052
03:57:33,000 --> 03:57:41,650
of this print, if for example, I press I align
this with this, this particular structure
2053
03:57:41,650 --> 03:57:47,950
here, then this print statement is inside
this if condition, this is the indentation
2054
03:57:47,950 --> 03:57:54,090
that is defining the placement of different
statements. And if the print starts from here,
2055
03:57:54,090 --> 03:58:01,410
then it is completely outside of all if conditions
it is like this way. So let's run this board
2056
03:58:01,410 --> 03:58:07,880
and see what happens. Let's say we brand let's
say we just cried a equals let's say 12. So,
2057
03:58:07,880 --> 03:58:12,150
what do you think what should be printed,
if A is 12 then first of all this condition
2058
03:58:12,150 --> 03:58:17,990
is true. So greater than 10 will be printed
inside the top if that will be printed, then
2059
03:58:17,990 --> 03:58:23,560
this check will be executed and this condition
will become false because 12 is not larger
2060
03:58:23,560 --> 03:58:28,400
than 20 then you will go to the else part
and less or equal to 20 this number this string
2061
03:58:28,400 --> 03:58:32,940
will be printed and then inside the else part
of nested if that will be printed and then
2062
03:58:32,940 --> 03:58:37,650
you will be out of all if condition then outside
of all F's that will be printed. So let's
2063
03:58:37,650 --> 03:58:45,070
see whether whatever we have said is correct
or not. So yes, greater than 10 inside the
2064
03:58:45,070 --> 03:58:51,160
top if less than or equal to 20 inside the
else part of the nested f outside all F's
2065
03:58:51,160 --> 03:58:58,500
Yeah. So that's what the nested F is. And
by the way, you can have you can have for
2066
03:58:58,500 --> 03:59:04,940
example, more if conditions inside the nested
ifs for example, you can have one more condition
2067
03:59:04,940 --> 03:59:16,021
here, if A is larger than 30 for example,
then do what then print it is larger than
2068
03:59:16,021 --> 03:59:25,580
30 as well. And for the brand, maybe not necessarily
that you always write print statements you
2069
03:59:25,580 --> 03:59:26,860
can do any interesting stuff
2070
03:59:26,860 --> 03:59:42,301
inside inside the nested if of nested if find
and then you can write the else part of this
2071
03:59:42,301 --> 03:59:51,240
particular if condition here if you want to
or or whatever I mean you can have as hilarious
2072
03:59:51,240 --> 03:59:56,370
structure as you want, but that completely
depends upon the logic or you may have an
2073
03:59:56,370 --> 04:00:02,971
if condition inside that l spot here for example,
You can write an if condition here, if whatever
2074
04:00:02,971 --> 04:00:10,550
that is also, that is also perfectly fine.
So, if a is larger than 20, then you print
2075
04:00:10,550 --> 04:00:15,630
this if A is larger than 30, then this, for
example, and literally write the else part
2076
04:00:15,630 --> 04:00:35,380
here else, print less than or equal to 30.
And we can print inside the nested inside
2077
04:00:35,380 --> 04:00:49,490
the else for all of nested if of nested if,
okay, so, while you see that program, let
2078
04:00:49,490 --> 04:00:56,930
me let me just scale it down so that you can
see that completely see that program. I mean,
2079
04:00:56,930 --> 04:01:02,900
yeah, it makes perfectly sense to me, for
example, you take an input, if that is larger
2080
04:01:02,900 --> 04:01:11,370
than 10, then you're here. If it is larger
than 20, then you are here. If it is not larger
2081
04:01:11,370 --> 04:01:16,521
than 20, then you're here. Okay. So let's
say it is larger than 20. If it is larger
2082
04:01:16,521 --> 04:01:21,940
than 20, then you are here further, if it
is larger than 30, then you are here. Otherwise,
2083
04:01:21,940 --> 04:01:28,601
you are here. And once and by the way, if
A is not larger than 10, then you are directly
2084
04:01:28,601 --> 04:01:35,640
here. Wow. So let's run this code. Let me
just scale it down so that you can see it
2085
04:01:35,640 --> 04:01:42,710
more. You can see more text. Let's see. So
let's run this. No errors. Great. So let's
2086
04:01:42,710 --> 04:01:49,890
say the number is let's say 25. So, what do
you expect the result. So the number is 25
2087
04:01:49,890 --> 04:01:54,740
is greater than 10 inside the top if it is
greater than 20 inside the nested if it is
2088
04:01:54,740 --> 04:01:59,840
smaller than or equal to 30. So inside the
else part of nested if off nested if and then
2089
04:01:59,840 --> 04:02:07,730
outside all the hips conditions. Great. Yeah.
You enjoyed that. I enjoyed that. rate. Okay,
2090
04:02:07,730 --> 04:02:13,650
so that's about the nested if one more thing
that I have already told you, but just let
2091
04:02:13,650 --> 04:02:19,640
me tell you the power of indentation. You
are here for example, in this particular if
2092
04:02:19,640 --> 04:02:24,870
condition, that's the if condition and that's
the nested if, and that's the else part of
2093
04:02:24,870 --> 04:02:33,180
this if if you move this L sport in in the
indentation or the alignment with this if
2094
04:02:33,180 --> 04:02:40,050
then this is else part of this if and this
is not the else part of this If so, remember
2095
04:02:40,050 --> 04:02:46,570
the power of indentation the this is the indentation
that defines which part belongs to what what
2096
04:02:46,570 --> 04:02:52,801
kind of block or structure in Python. In other
languages. Sometimes, for example, in c++,
2097
04:02:52,801 --> 04:02:59,010
they they normally use to write these curly
brackets to define a block and their indentation
2098
04:02:59,010 --> 04:03:03,210
doesn't really matter. But in Python, this
is the indentation that actually defines each
2099
04:03:03,210 --> 04:03:09,360
and everything. So, for example, this is a
crucial example if this else just moves backwards
2100
04:03:09,360 --> 04:03:17,480
and aligned with this f you get this else
with this if these two if an L structures,
2101
04:03:17,480 --> 04:03:23,780
this is still nested if without an L sport.
And if this else move somewhere in between
2102
04:03:23,780 --> 04:03:28,190
I mean this is not aligned with this if this
not aligned with this if you get a syntax
2103
04:03:28,190 --> 04:03:33,240
error because that is not a proper indentation.
So focus on indentation that is really really
2104
04:03:33,240 --> 04:03:39,910
important. Yeah, so although i have i've told
you that the indentation has already told
2105
04:03:39,910 --> 04:03:47,150
you but I just I just found to make a slide
over this elsewhere because that's important.
2106
04:03:47,150 --> 04:03:53,070
Sometimes you may get confused whether this
else belongs to this F or that F Well, the
2107
04:03:53,070 --> 04:04:00,900
indentation defines this LS belong to what?
Okay, I end this
2108
04:04:00,900 --> 04:04:12,011
control flow indentation here. So from next
video we are jumping toward loops. But before
2109
04:04:12,011 --> 04:04:20,710
loops, I just want to I just want to write
a lengthy program in F LS f there are combinations.
2110
04:04:20,710 --> 04:04:30,271
I just want to write a Jupiter program for
you to to get comfortable with F nested f
2111
04:04:30,271 --> 04:04:35,721
the conditions that are ands and ORS and nots
are stuff like so. So So in the next video
2112
04:04:35,721 --> 04:04:41,700
we will be practicing more on Jupiter for
if conditions and then from the next to next
2113
04:04:41,700 --> 04:04:48,390
video. We'll be jumping toward loops, the
very very powerful structure. Okay. Hope to
2114
04:04:48,390 --> 04:04:54,980
see you in the next video. Okay, so let's
just practice this if condition a little bit
2115
04:04:54,980 --> 04:05:01,490
more in this particular video and we are going
to achieve particular tasks. So let's design
2116
04:05:01,490 --> 04:05:09,521
some task here. By the way, this has comment,
comment, comment is, it starts from a hash
2117
04:05:09,521 --> 04:05:15,000
symbol. And that's a statement that will never
be executed. This just describes your code,
2118
04:05:15,000 --> 04:05:22,370
for example. So like it, like, it is not there.
But it is there as a text, but not as a code
2119
04:05:22,370 --> 04:05:32,561
file. Like hash sometimes represents. Comment
or description with a single line. If your
2120
04:05:32,561 --> 04:05:39,181
comment goes on multiple lines, it is good
to write a multi line comment. So that's single
2121
04:05:39,181 --> 04:05:47,570
line comment, for example, single line comment,
the multi line comments, they start with three
2122
04:05:47,570 --> 04:05:52,980
quotes, and then end with three chords. So
whatever you write inside, in these, in this
2123
04:05:52,980 --> 04:05:57,980
particular block, that's a multi line comment.
So let's describe our problem in this modal
2124
04:05:57,980 --> 04:06:05,061
line comments, because that's the problem
in form of text. And then we will be solving
2125
04:06:05,061 --> 04:06:11,900
that problem using using the code. So that's
just description of the problem, let's say
2126
04:06:11,900 --> 04:06:32,200
user will enter of loading point number. Number,
let's say 230 8.915. Let's see. Okay, your
2127
04:06:32,200 --> 04:06:42,021
task is, is to so let's just adjust more readable,
your task is to
2128
04:06:42,021 --> 04:07:00,790
find out the teacher integer, portion, integer
portion, before the decimal before the point,
2129
04:07:00,790 --> 04:07:10,700
let's say for the for the point, in this case,
in this case, it is 238. And then,
2130
04:07:10,700 --> 04:07:15,690
and
2131
04:07:15,690 --> 04:07:41,260
and then check whether if that teacher portion
is and even number or not. So just print yes
2132
04:07:41,260 --> 04:07:48,721
or no. So print even if it is even number,
otherwise, print odd. So that's the that's
2133
04:07:48,721 --> 04:07:53,150
the problem statement. That's the problem
that we are going to solve. And this is just
2134
04:07:53,150 --> 04:08:03,260
to commit now we are outside the command that's
a multi line comment. Yeah, so how to how
2135
04:08:03,260 --> 04:08:11,091
to solve that problem? How to solve that problem?
So let's start solving this problem. I'm going
2136
04:08:11,091 --> 04:08:16,340
to spend some time on this program just to
get comfortable with the if conditions, let's
2137
04:08:16,340 --> 04:08:24,150
say let's say that number is x is input, let
me convert that input
2138
04:08:24,150 --> 04:08:27,310
into our
2139
04:08:27,310 --> 04:08:41,479
real number. That's it. Okay, we're just assuming
that the user will enter a real number. It's
2140
04:08:41,479 --> 04:08:48,091
real number. real number might be I mean to
38.0, that's a real number or 238 itself,
2141
04:08:48,091 --> 04:08:52,690
that's also real number. That's okay. But
we're not assuming that the user will enter,
2142
04:08:52,690 --> 04:08:57,721
let's say some characters like ABC or stuff
like sort of just just assuming that. Okay,
2143
04:08:57,721 --> 04:09:04,170
now, assume that x contains real number, it
may be an integer. By default, maybe user
2144
04:09:04,170 --> 04:09:09,730
just enters 10. And that's it. So it may be
already an integer, then we have to check
2145
04:09:09,730 --> 04:09:21,780
whether that 10 is whether that 10 is even
or not, or the user may enter 11.7, or the
2146
04:09:21,780 --> 04:09:29,860
user may enter minus 34.7. Or the user may
enter just zero or user may enter just zero
2147
04:09:29,860 --> 04:09:36,521
point 30 535. There are a lot of possibilities
that a user come up with this exe can contain
2148
04:09:36,521 --> 04:09:45,010
any kind of number, and we have to check according
to. So how can we move let us just see, whether
2149
04:09:45,010 --> 04:09:54,760
that number let us just extract the decimal
portion, the portion before point. Let's just
2150
04:09:54,760 --> 04:10:01,350
extract that how can we extract that there
are two conditions First of all, let's see
2151
04:10:01,350 --> 04:10:12,010
if x is positive, then do what else do what?
So let's try this structure first. The facts
2152
04:10:12,010 --> 04:10:19,080
is positive, then what we have to do? And
if x is negative, then what we have to do?
2153
04:10:19,080 --> 04:10:31,420
So if x is positive, then what we do? We,
we just so, what should we do? I'm just stuck
2154
04:10:31,420 --> 04:10:38,310
here. How can we extract the, the decimal
portion, the portion without this particular
2155
04:10:38,310 --> 04:10:49,610
thing? How can we extract that? That's, that's
tricky. That's kind of tricky. Yeah. So any,
2156
04:10:49,610 --> 04:10:56,570
any ideas? I guess this? The the structure
I have, I'm using the let us just first think
2157
04:10:56,570 --> 04:11:02,470
that x is positive, just make our life easier.
And then if x is positive, it's a positive
2158
04:11:02,470 --> 04:11:09,770
number. How can we extract this portion out?
Just the number that is below? That is before
2159
04:11:09,770 --> 04:11:16,380
the decimal point, but what should we do?
can we can we can we apply apply around function?
2160
04:11:16,380 --> 04:11:28,971
Will that help? x? Will that help? helps.
Yes. But no round function? So let's say y
2161
04:11:28,971 --> 04:11:42,020
contains the rounded value of x then, so what?
Then how can extract How can we extract the
2162
04:11:42,020 --> 04:11:46,940
the the decimal portion, the portion the integer
portion? Or maybe there is a function that
2163
04:11:46,940 --> 04:11:52,990
actually round down? Let me check whether
there is a function float or not? No, float
2164
04:11:52,990 --> 04:12:01,070
is not a function, I guess. So let's say round
x. Okay, now y contains the rounded vol value
2165
04:12:01,070 --> 04:12:08,250
forever the Xs we are now assuming that x
is positive, okay, then what? Now, if, if
2166
04:12:08,250 --> 04:12:17,801
y is larger than x, that means we moved up.
Okay, we moved up, the round goes up. In that
2167
04:12:17,801 --> 04:12:29,110
case, what we do is we just subtract. So the
let me so we just subtract the integer portion.
2168
04:12:29,110 --> 04:12:37,570
So the let me in teacher portion, let's say
that's our variable name, then the integer
2169
04:12:37,570 --> 04:12:44,360
portion is simply y minus one is that correct?
Is that correct? If y is larger than x, then
2170
04:12:44,360 --> 04:12:50,970
integer portion is simply y minus one. For
example, for example, just Just think about
2171
04:12:50,970 --> 04:13:02,690
it, if When, when, for example, if the value
was 29.6, and the rounded value will become
2172
04:13:02,690 --> 04:13:10,990
30, so 30 minus one will be 29. There is what
we are what we are interested in. So, yeah,
2173
04:13:10,990 --> 04:13:20,310
so otherwise, if for example, else, else,
if y is not larger than x, then y itself is
2174
04:13:20,310 --> 04:13:22,570
an integer portion.
2175
04:13:22,570 --> 04:13:31,790
Y itself is an integer portion. Is that correct?
I mean, is that making sense to you? That
2176
04:13:31,790 --> 04:13:41,070
if for example, if if x is larger than effects,
larger than if the rounded value of x is larger
2177
04:13:41,070 --> 04:13:49,450
than larger than x itself, then we just subtract
one and we get the proportion. Otherwise,
2178
04:13:49,450 --> 04:13:55,740
the rounded value itself is the portion, just
just let's just run this, run this code for
2179
04:13:55,740 --> 04:14:01,660
now and check whether what whatever we have
done so far is correct or not. So after that,
2180
04:14:01,660 --> 04:14:08,320
just print, let's say the integer portion.
And teacher portion, let's just print that.
2181
04:14:08,320 --> 04:14:20,050
Okay. So enter a number. Let's say the number
is, let's say 25.3 45.367. Let's say, obviously,
2182
04:14:20,050 --> 04:14:26,450
the integer portion here is 25. So let's say
let's see our program returns 25. And now
2183
04:14:26,450 --> 04:14:35,181
Oh, the result is 25. magically Oh my god.
We found 25. Let's run it again. Let's run
2184
04:14:35,181 --> 04:14:52,751
it again. Just to see. Okay, let's run this
again. And order this time let's give it to
2185
04:14:52,751 --> 04:15:02,290
45.8. Okay, the integer portion is 45. But
when we will round We will get to 46 and 46
2186
04:15:02,290 --> 04:15:07,710
minus one, we will dive into this particular
if condition. Let's see. All the result is
2187
04:15:07,710 --> 04:15:16,340
45. We are we are still moving very bill.
Great. That's, that's great. So, okay, let's
2188
04:15:16,340 --> 04:15:26,630
play with it. Let's, let's give, let's give
0.2 the result should be zero, it is zero,
2189
04:15:26,630 --> 04:15:32,750
right? Let's run it again and give it let's
see, let's say four. That's it, the result
2190
04:15:32,750 --> 04:15:37,690
should be four now, it is four. Great. So,
we are working very well we have extracted
2191
04:15:37,690 --> 04:15:44,820
the integer portion as long as the number
was positive. Okay, right. What if the number
2192
04:15:44,820 --> 04:15:57,550
will be negative? Let's say that was true,
if that was true, so, that whole logic works,
2193
04:15:57,550 --> 04:16:13,770
if x was positive, so if x is positive, then
whole this logic just works okay, then else
2194
04:16:13,770 --> 04:16:18,820
What should we do? If x is positive, then
this logic works effects is not positive,
2195
04:16:18,820 --> 04:16:24,310
then what will happen? Then how can we find
out the integer portion because first we have
2196
04:16:24,310 --> 04:16:28,040
to find out the integer portion and then we
have to find out whether they are integer
2197
04:16:28,040 --> 04:16:32,330
portion is even or not finding out whether
they are indeed a portion is even or not might
2198
04:16:32,330 --> 04:16:38,430
be simpler. But first, we have to find out
the integer portion. So for example, let's
2199
04:16:38,430 --> 04:16:46,300
check the behavior of round function on negative
numbers, let's say around minus 9.3. So the
2200
04:16:46,300 --> 04:16:58,490
result is minus nine. Okay? If we say okay,
round, minus 9.6, the result will be minus
2201
04:16:58,490 --> 04:17:04,210
10. So it looks like the same as working in
the positive numbers. So round function is
2202
04:17:04,210 --> 04:17:11,260
actually working roughly the same way it should
work in the positive numbers. Okay. So what
2203
04:17:11,260 --> 04:17:21,340
should we do here? Any idea? Maybe, maybe
we first convert? Maybe you first convert,
2204
04:17:21,340 --> 04:17:31,130
by the way? Yeah, maybe first convert the
number, let's say y equals around x again,
2205
04:17:31,130 --> 04:17:39,030
like before, but then what? Then what? So
maybe this rounding helps the same way? Maybe
2206
04:17:39,030 --> 04:17:48,150
the rounding helps the same way. We should
extract this out from this here, because it
2207
04:17:48,150 --> 04:17:52,311
is going to work in the else part as well,
why to compute it, why white write this redundant
2208
04:17:52,311 --> 04:18:04,450
code? So why is round x let's say then if
y is greater than x, what should we do? If
2209
04:18:04,450 --> 04:18:13,330
it is negative y is greater than then what
would what will be the portion? It will be
2210
04:18:13,330 --> 04:18:18,851
the integer portion will be portion will be
what?
2211
04:18:18,851 --> 04:18:27,940
y minus one or one? y plus one? Yes, you got
the answer? That's y plus one. Great. And
2212
04:18:27,940 --> 04:18:44,970
else I guess we have in future portion. Equals
Whitesell, I guess, yes, I guess that's the
2213
04:18:44,970 --> 04:18:49,210
that's the good. That's cool. I guess that's
checked, by the way, but I guess that's the
2214
04:18:49,210 --> 04:18:56,270
code. By the way, this else part is, this
else part is same in both of these conditions.
2215
04:18:56,270 --> 04:19:02,810
So maybe, maybe we can combine this code and
write a more elegant code, but I guess this
2216
04:19:02,810 --> 04:19:08,320
would work. Let us just print the integer
portion, just to check whether we are working
2217
04:19:08,320 --> 04:19:19,450
well, so far or not. So let's enter let's
see 12.3 The result is 12th grade. So it did
2218
04:19:19,450 --> 04:19:25,770
not change our previous I guess our previous
logic. So let's say there is minus 9.8. Now
2219
04:19:25,770 --> 04:19:32,840
the integer portion should be minus nine,
oh, it is returning 10 Why is that? Why is
2220
04:19:32,840 --> 04:19:40,720
that? Oh my God, this should be changed when
it is round. It may go that way or when it
2221
04:19:40,720 --> 04:19:47,980
rounds it actually becomes lesser than 10.
Because when it rounds it goes up and it becomes
2222
04:19:47,980 --> 04:19:54,810
lesser than a negative word. This condition
should flip. Yeah. So we are making an error
2223
04:19:54,810 --> 04:20:02,600
here. Let's fix that. Okay, let's run this
again. And see Let's say minus nine point
2224
04:20:02,600 --> 04:20:11,811
minus nine d 3.2. Minus 93. Great. So then
we have let's see, let's run it again. Minus
2225
04:20:11,811 --> 04:20:21,450
8.9. minus eight. Yes, we are working perfectly
fine. Once we have integer portion with us,
2226
04:20:21,450 --> 04:20:31,860
we just right here. At the very end if integer
portion is your portion, remainder with two,
2227
04:20:31,860 --> 04:20:49,200
if that equals to zero, if that equals to
zero, Brent, even, otherwise, else, brand.
2228
04:20:49,200 --> 04:20:55,370
Art. That's it. That's the whole program.
Let's see. And let's see, how is it running?
2229
04:20:55,370 --> 04:21:09,490
Let's say 22.6. It's even, let's say minus
87.3. That's odd rate. So you see the power,
2230
04:21:09,490 --> 04:21:16,440
if condition and, and how can we think in
writing these programs and stuff like so?
2231
04:21:16,440 --> 04:21:21,140
That was a lengthier video, I know. But I
guess you get a very good look and feel of,
2232
04:21:21,140 --> 04:21:27,940
of if conditions and thinking and building
logic and all that stuff. So in the next video,
2233
04:21:27,940 --> 04:21:33,440
we will start loops. So that's a beautiful
structure, hope to see you in the next video,
2234
04:21:33,440 --> 04:21:40,880
the best way to understand loops is to think
about in a repetitive structure or repeating
2235
04:21:40,880 --> 04:21:46,850
structure. Let me let me give you an example.
And they will, we will dive into this code
2236
04:21:46,850 --> 04:21:54,470
in a while. The example is let's say a user
gives you a number, let's say integer number.
2237
04:21:54,470 --> 04:22:00,710
And you want to print all the numbers till
that number, let's say you start from one,
2238
04:22:00,710 --> 04:22:06,520
and you keep on moving and printing all the
numbers, as long as you reach that number.
2239
04:22:06,520 --> 04:22:13,020
So for example, if user enters, let's say,
five, your goal is to print one, then print
2240
04:22:13,020 --> 04:22:23,770
two, then print three, then print four, and
then stops, then stop just or, let's say if
2241
04:22:23,770 --> 04:22:33,440
user print, if user enter, let's say, three,
then you print one, you print two, and then
2242
04:22:33,440 --> 04:22:41,490
you stop. This is easy. If user enters in
n, we can just print, we could have written
2243
04:22:41,490 --> 04:22:51,900
this thing, print. Brent, I, let's initialize
a variable by with one, Brent I, and then
2244
04:22:51,900 --> 04:23:00,651
I equals two i plus one, or in Python, we
can write this quickly as i plus equals to
2245
04:23:00,651 --> 04:23:03,970
one that means I
2246
04:23:03,970 --> 04:23:10,860
that means in I store a plus one, this is
the short form of writing this. And then after
2247
04:23:10,860 --> 04:23:16,200
that, you just apply an if condition. For
example, here, you can apply an if condition
2248
04:23:16,200 --> 04:23:22,240
and say, Okay, if I is smaller than n, you
keep on printing, and after printing, you
2249
04:23:22,240 --> 04:23:28,000
just increment again this, then check the
if condition and keep on moving. Well, that
2250
04:23:28,000 --> 04:23:36,750
is visible if n is five, or n is three, what
if if n is let's say, if t 1000. In I mean,
2251
04:23:36,750 --> 04:23:41,730
you're writing all that structure again, and
again. And again. I mean, that's a lot of
2252
04:23:41,730 --> 04:23:46,730
code. Well, the loops are just a solution
for this kind of structure when you want to
2253
04:23:46,730 --> 04:23:53,100
perform the same kind of task again, and again,
the loop gives you the facility to do that.
2254
04:23:53,100 --> 04:24:01,060
For example, let's just consider the VI loop.
This is again a condition similar like a condition
2255
04:24:01,060 --> 04:24:07,780
in if condition like an if condition, you
evaluate this Boolean expression, then that's
2256
04:24:07,780 --> 04:24:12,770
an expression that results a boolean value.
While this condition is true, you will stay
2257
04:24:12,770 --> 04:24:20,261
in this block and after executing whole block
once you check this condition again, if this
2258
04:24:20,261 --> 04:24:25,330
condition is again true, you will dive into
this block again. Then check the condition
2259
04:24:25,330 --> 04:24:29,870
dive into the block then check the condition
dive into the block. As long as this condition
2260
04:24:29,870 --> 04:24:35,200
stays true, you stay in the block you you
move inside the block. Once this condition
2261
04:24:35,200 --> 04:24:42,020
is false, then you exit this while loop then
the loop terminates and you move on to the
2262
04:24:42,020 --> 04:24:46,860
further processing just like an if condition
just like if conditions if if the condition
2263
04:24:46,860 --> 04:24:52,521
becomes false, you accept that if condition
and you can move on, moved on. So in this
2264
04:24:52,521 --> 04:24:58,400
particular case, for example, if n is five,
let's say if n is five, user give an integer
2265
04:24:58,400 --> 04:25:02,820
number that is five I is equal to one, now
one is smaller than five, the condition is
2266
04:25:02,820 --> 04:25:08,260
true, we move inside, you print I, the value
of i is one. So that's what you print, you
2267
04:25:08,260 --> 04:25:13,850
print one, then you change a, you increment
i with one, that means i equals i plus one,
2268
04:25:13,850 --> 04:25:18,780
so I becomes two. Now the body of the loop
finishes, that's whole body of the loop, the
2269
04:25:18,780 --> 04:25:25,150
body of the loop can have many, many statements,
a whole block of code. Once I becomes two,
2270
04:25:25,150 --> 04:25:32,590
you move on and you check, okay? Two is smaller
than five, yes, it is true, you move inside
2271
04:25:32,590 --> 04:25:39,090
the block again, you print two, then you update
I, the loop body finishes. Once the loop body
2272
04:25:39,090 --> 04:25:43,280
finishes, you go and check the condition again,
whether that condition is still true or not,
2273
04:25:43,280 --> 04:25:48,600
it is still true i is three i is three is
smaller than five, yes, you move inside, you
2274
04:25:48,600 --> 04:25:54,320
print three, you update, I, you check the
condition four is smaller than five, yes,
2275
04:25:54,320 --> 04:26:00,200
you move inside you print four, and then you
update I and then you move on now five is
2276
04:26:00,200 --> 04:26:06,070
smaller than five false. Once the condition
is false, you will not dive into the body
2277
04:26:06,070 --> 04:26:12,770
of the loop, you will exit the loop and you
will print done. And that's it done. So this
2278
04:26:12,770 --> 04:26:19,080
loop becomes very, very, very handy. In in,
in, in applications that have representative
2279
04:26:19,080 --> 04:26:24,141
structures. And in most of the interesting
programs, most of the interesting problems,
2280
04:26:24,141 --> 04:26:32,690
these are the loops that play a very huge
role. So let's go to Jupiter just to get our
2281
04:26:32,690 --> 04:26:42,260
hands, get our hands on this loop. For example,
let's say x is again, that's the end or n,
2282
04:26:42,260 --> 04:26:57,430
let's take n and is in input. Let me make
this a little bigger, just do. Let's say that
2283
04:26:57,430 --> 04:27:07,690
input and input is a number, let's say n i
is your surgeon, let's say let's say one,
2284
04:27:07,690 --> 04:27:19,510
while I is smaller than n, you may have written
this parenthesis just to just to create the
2285
04:27:19,510 --> 04:27:27,250
readability just to make readability. And
otherwise I mean, this is also Okay, that's
2286
04:27:27,250 --> 04:27:34,250
perfectly fine. If as long as I is smaller
than n, keep doing the following you what
2287
04:27:34,250 --> 04:27:41,061
you do is bring, for example, the square of
I paint the square of I, that the square of
2288
04:27:41,061 --> 04:27:55,020
it, let's say, and then you say, Grant, for
example. This is a question number. And then
2289
04:27:55,020 --> 04:28:02,570
you just print I, that's the iteration number
I have the loop.
2290
04:28:02,570 --> 04:28:10,271
That's the equation number I this is just
the spring, this is just a string. And that's
2291
04:28:10,271 --> 04:28:16,620
our variable, its value will be printed. This
print function takes as many arguments as
2292
04:28:16,620 --> 04:28:22,260
you pass. So you can you can write a comma
here and continue whatever you want to print.
2293
04:28:22,260 --> 04:28:28,451
That's very flexible function. Okay, then
what you do you say, Okay, I plus equals to
2294
04:28:28,451 --> 04:28:35,750
one. By the way, this i plus equals to one
is the same as i equals i plus one. You see,
2295
04:28:35,750 --> 04:28:42,060
I have just commented here just to explain
what this is doing. If I just write i equals
2296
04:28:42,060 --> 04:28:49,620
i plus one that is also that is also correct
in Python, but that's kind of shorthand. Okay.
2297
04:28:49,620 --> 04:28:57,340
And that's it. Now, again, when I de indent,
I'm outside the loop, let's say sprint. Loop
2298
04:28:57,340 --> 04:29:08,110
done, for example. So that's the code for
example. So let's run this code. Let's run
2299
04:29:08,110 --> 04:29:20,220
this code. For example. Let's say n is equal
to five, then we have five. So this is one,
2300
04:29:20,220 --> 04:29:24,870
this is the aggression number one, then two
square is four, this is the aggression number
2301
04:29:24,870 --> 04:29:29,800
two, then three squared is nine, the aggression
number three, then four square is 16. This
2302
04:29:29,800 --> 04:29:34,390
is the iteration number four, and then the
loop finishes. That's it. That's the first
2303
04:29:34,390 --> 04:29:40,110
snapshot of the loop. We will continue from
here onwards in the next video and I will
2304
04:29:40,110 --> 04:29:49,079
show you more and more flavors of this loop.
So hold on and wait for the next video. Okay,
2305
04:29:49,079 --> 04:29:57,940
in the previous video, we saw a while loop
and we saw one. One program related to while
2306
04:29:57,940 --> 04:30:06,021
loop, just printing Just printing a bunch
of numbers till a particular number. Well,
2307
04:30:06,021 --> 04:30:12,610
when you are inside the body of the loop,
that's a whole new you can write whatever
2308
04:30:12,610 --> 04:30:16,990
you want to write, for example, you can you
can apply an if condition inside the body
2309
04:30:16,990 --> 04:30:23,070
and check that an at each iteration a particular
decision should be made or not. For example,
2310
04:30:23,070 --> 04:30:31,110
in this particular case, I'm going to print
I whenever I is an even number, so, I is some
2311
04:30:31,110 --> 04:30:37,940
number if it is even then printed, else pass
this pass statement for example, is just a
2312
04:30:37,940 --> 04:30:45,910
statement of saying that do nothing It is
just a shortcut of writing do nothing we could
2313
04:30:45,910 --> 04:30:52,400
have we could have omitted the whole else
part along with this pass and still the code
2314
04:30:52,400 --> 04:30:59,160
is equivalent but sometimes writing this past
make the code readable just so so writing
2315
04:30:59,160 --> 04:31:05,890
this boss statement just means do nothing
and just move on. If we omit else statement,
2316
04:31:05,890 --> 04:31:12,460
and we omit this boss, that's perfectly okay.
So, for example, let's try it on the score.
2317
04:31:12,460 --> 04:31:21,820
Let's say n is let's say n is five i equals
one one is less than five Yes, one is not
2318
04:31:21,820 --> 04:31:27,720
an even number. So go to the else part else
means boss, which means go on and then increment
2319
04:31:27,720 --> 04:31:33,850
i this print statement is outside the loop
this is this is aligned with this while it's
2320
04:31:33,850 --> 04:31:39,520
not inside the body of the loop otherwise,
it should have been intent indented inside
2321
04:31:39,520 --> 04:31:45,681
now i is incremented I becomes to now move
back to is smaller than five years. Two remainder
2322
04:31:45,681 --> 04:31:51,560
two is zero Yes. So brand two, so two will
be printed. Because if executed else will
2323
04:31:51,560 --> 04:31:57,650
not execute and I will increment because I
is not inside the if condition it is inside
2324
04:31:57,650 --> 04:32:04,430
the body of the loop. So I incremented I becomes
three you go back, three is smaller than five
2325
04:32:04,430 --> 04:32:13,479
years. Three, remainder with two is zero false.
So pass i i plus one, so I becomes four, four
2326
04:32:13,479 --> 04:32:19,960
is smaller than five years for remainder two
is zero, yes, so Brent four. So else will
2327
04:32:19,960 --> 04:32:28,940
not execute now increment i, once you increment
i you get, for example, I equals five, now
2328
04:32:28,940 --> 04:32:35,330
five is smaller than five false, so you go
out of the loop and you print down. And that's
2329
04:32:35,330 --> 04:32:42,690
what this code is. So, you can have if condition
inside the loop, you can have nested if inside
2330
04:32:42,690 --> 04:32:46,061
the loop
2331
04:32:46,061 --> 04:32:51,720
you can have loop inside the loop nested loops,
we will see examples of nested loops as well.
2332
04:32:51,720 --> 04:32:59,370
I mean, that's that's all allowed are sometimes
rarely required. Okay. So, next there are
2333
04:32:59,370 --> 04:33:05,830
two important statements that are there, one
is break one is continue, I want to focus
2334
04:33:05,830 --> 04:33:12,150
these statements because they have a deep
link with loops. A break statement where ever
2335
04:33:12,150 --> 04:33:19,020
written inside the body of the loop tells
that exit the loop immediately whenever this
2336
04:33:19,020 --> 04:33:25,910
brake is encountered, whenever this brake
executes, it exits the loop immediately and
2337
04:33:25,910 --> 04:33:34,980
brings you outside the body of the loop. That's
what it does break. So for example, if I becomes
2338
04:33:34,980 --> 04:33:41,980
if I becomes divisible by 17 and the remainder
becomes zero, you will print a break and then
2339
04:33:41,980 --> 04:33:46,721
when this break statement will execute you
will exit the loop immediately regardless
2340
04:33:46,721 --> 04:33:53,311
of what is the value of AI What are other
states wherever break exits the loop Okay
2341
04:33:53,311 --> 04:34:01,051
great. Now, the continue continue statements
continue statement wherever encountered continue
2342
04:34:01,051 --> 04:34:10,208
brings the next iteration loaded regardless
of the remaining remaining statements in the
2343
04:34:10,208 --> 04:34:15,618
loop for example, when this continue will
be executed, no matter how many statements
2344
04:34:15,618 --> 04:34:21,759
are there onwards that are there, in the body
of the loop, the loop will not finish its
2345
04:34:21,759 --> 04:34:26,550
iterations iteration by going through all
the remaining statements, but it will start
2346
04:34:26,551 --> 04:34:33,669
another iteration immediately. So continue
basically skips the remaining body of the
2347
04:34:33,669 --> 04:34:40,019
loop and starts another iteration. Here I
have written this. true true means while true
2348
04:34:40,020 --> 04:34:47,900
means always run. You might be thinking always
run it's an infinite loop will it will it
2349
04:34:47,900 --> 04:34:52,259
when we will exit the loop because this true
statement will always stay true. We're not
2350
04:34:52,259 --> 04:34:56,349
changing this true anymore. There is no condition
here. That's true. While true means always
2351
04:34:56,349 --> 04:35:01,550
go inside the loop but once where whenever
this Break his encounter, you're outside the
2352
04:35:01,551 --> 04:35:09,631
loop right away. And this break exists, the
loop does continue skips the remaining remaining
2353
04:35:09,631 --> 04:35:14,910
portion of the loop body and starts the new
iteration starts another iteration. So this
2354
04:35:14,910 --> 04:35:23,030
continue means start another iteration immediately
skip the rest of the stress of the statements.
2355
04:35:23,030 --> 04:35:29,669
So the rest of the statements inside the loop
body. Okay, so let's just practice this break
2356
04:35:29,669 --> 04:35:36,899
and continue with just just in Jupyter Notebook
to get a better look and feel of the loop.
2357
04:35:36,900 --> 04:35:45,730
So let's say we have, let's say again, let's
say n equals let's say 10. Or we might have
2358
04:35:45,730 --> 04:35:55,101
taken that as an input, let's say n is equal
to 10. While true, which means keep moving,
2359
04:35:55,101 --> 04:36:05,659
it might have taken some value here, I equals,
let's say one, while true, if I remainder
2360
04:36:05,660 --> 04:36:21,009
with, let's say, nine, if that is equal to
zero, then just break the loop tells ELS.
2361
04:36:21,009 --> 04:36:32,278
Else, what you do is really you increment
a else what you do is, if I is if I is not
2362
04:36:32,278 --> 04:36:41,419
divisible by nine, then what you do is i equals
i plus one, that's true. By the way, previously,
2363
04:36:41,419 --> 04:36:45,579
we we have written this way. So either way
is fine, whether you write a short form or
2364
04:36:45,580 --> 04:36:54,680
this form, so else this okay. And that's,
that's it, the loop finishes. That's the loop.
2365
04:36:54,680 --> 04:37:02,311
After the loop, you just write Okay, print,
the loop is done. So let's see, what's the
2366
04:37:02,311 --> 04:37:12,230
output? The output is done straightaway. And
the reason is, why it is Oh, one is not one
2367
04:37:12,230 --> 04:37:18,259
is divisible by nine, only then you could
have break. While true. Why? Why the loop?
2368
04:37:18,259 --> 04:37:23,979
Oh, it does not print anything, we could have
printed some statements so that we know that
2369
04:37:23,980 --> 04:37:36,520
we went inside the loop or not. Okay, so inside,
if so, for example, Brent.
2370
04:37:36,520 --> 04:37:43,721
Inside else. So let's run this again. Oh,
okay, great, inside sales, inside sales inside
2371
04:37:43,721 --> 04:37:50,780
sales inside rails, the first time it go inside,
if that time it breaks, and it goes out and
2372
04:37:50,780 --> 04:37:56,640
pants down. That's what this break statement
does. So let's see an application of continuous
2373
04:37:56,641 --> 04:38:06,980
statement. That's for example, just copy and
paste that code into another cell and see
2374
04:38:06,980 --> 04:38:18,359
how this continue works. So, let's say we
have a loop like so. So, what we say is like
2375
04:38:18,359 --> 04:38:33,690
this, if I is nine is not equal to zero. If
this is the case, if I is not divisible by
2376
04:38:33,690 --> 04:38:46,550
nine, what you do is you get take i plus equals
to one and then continue continue to the next
2377
04:38:46,551 --> 04:38:59,161
statement. And whatever else you write here
for example, brand something brand something
2378
04:38:59,161 --> 04:39:08,861
else something else whatever that is going
to be printed and what wants to continue will
2379
04:39:08,861 --> 04:39:18,971
will be encountered whenever this eye is whenever
this I divisible by nine is not true. If I
2380
04:39:18,971 --> 04:39:26,699
is then you continue once this AI is divisible
by nine for example, then you will not follow
2381
04:39:26,699 --> 04:39:34,938
then you will not dive into this if condition
only then these two statements will be printed.
2382
04:39:34,938 --> 04:39:41,292
Because this this continue will not allow
anything further that should happen. And once
2383
04:39:41,292 --> 04:39:48,560
these are printed, let's say we break our
loop right there, let's say so if for example
2384
04:39:48,560 --> 04:39:55,690
for the very first time one is not divisible
by nine, so I equals two. So continue these
2385
04:39:55,690 --> 04:40:00,900
three statements will not be executed the
next loop the next loop. The next one If condition
2386
04:40:00,900 --> 04:40:06,860
becomes false, this continue will not operate,
and then we print this statement, then only
2387
04:40:06,860 --> 04:40:11,020
then we will print this statement, and only
then we will break and we'll exit the loop
2388
04:40:11,020 --> 04:40:22,840
and print the data. So let's print here. Brent
inside, if so, let's run this code, let's
2389
04:40:22,840 --> 04:40:25,880
run this code and see what happens. That's
the good
2390
04:40:25,880 --> 04:40:35,320
I should I should just yeah, NASA better font,
let's run this code. So, when the code is
2391
04:40:35,320 --> 04:40:41,900
run inside if inside if you see when you when
you are inside if when you continue when when
2392
04:40:41,900 --> 04:40:48,190
this is the body of if condition when if condition
completes, it should print these two things,
2393
04:40:48,190 --> 04:40:56,660
but continue is telling the cursor to go back
to the next iteration and move on. And once
2394
04:40:56,660 --> 04:41:02,520
this if condition becomes false, only then
you get this distinct printed this thing printed
2395
04:41:02,520 --> 04:41:08,458
if this break was not there, you do you then
again was going to the while loop and you
2396
04:41:08,458 --> 04:41:13,230
will be running an infinite loop and then
you have done so that's what this continue
2397
04:41:13,230 --> 04:41:22,810
and break does. So, in the in the in the very
next video we will see another kind of loop
2398
04:41:22,810 --> 04:41:29,370
here we saw the while loop in the next video
we will see a for loop very powerful and very
2399
04:41:29,370 --> 04:41:36,060
famous kind of loop for it does almost the
same stuff as while loop while the while loop
2400
04:41:36,060 --> 04:41:41,708
runs based on a condition they fire the for
loop it runs based on contracts a counter
2401
04:41:41,708 --> 04:41:47,120
loop that many times it should run and so
on. So we will see the details of for loop
2402
04:41:47,120 --> 04:41:52,850
and the application The for loop in the next
video hope to see you in the next one. Okay
2403
04:41:52,850 --> 04:41:57,650
in this video we are going to discuss for
loop and other kind of loop in the previous
2404
04:41:57,650 --> 04:42:03,420
video we saw while loop although most of the
stuff almost all of the stuff can be achievable
2405
04:42:03,420 --> 04:42:09,362
through while loop and sometimes it becomes
handy to apply for loop. In this particular
2406
04:42:09,362 --> 04:42:17,192
example, I'm going to populate a list. So
before actually moving towards for loop let's
2407
04:42:17,192 --> 04:42:25,260
see very shortly what a list is, although
we are going to be or we are going to explore
2408
04:42:25,260 --> 04:42:30,070
this lesson in much more detail when we will
discuss the data structures module but just
2409
04:42:30,070 --> 04:42:34,100
for the sake of example, a list is a collection
of different kinds of elements for example
2410
04:42:34,100 --> 04:42:42,520
234, that's a list of three elements. So two
three and four the list can contains different
2411
04:42:42,520 --> 04:42:49,080
type values, for example two 3.4 and stuff
like so, we can access different elements
2412
04:42:49,080 --> 04:42:54,970
for example, L of zero means the very first
element the indexing This is called the index,
2413
04:42:54,970 --> 04:43:02,010
the index starts from zero then index one
is so if we print for example, Brent Elif
2414
04:43:02,010 --> 04:43:07,450
zero the result will the result that will
be printed will be two similarly we can append
2415
04:43:07,450 --> 04:43:17,420
more values inside a list append let's say
53 and list after this append operation, the
2416
04:43:17,420 --> 04:43:26,260
list will be having these values 234 53 we
can remove delete, update and do a lot of
2417
04:43:26,260 --> 04:43:31,880
stuff we will see lists in detail, but just
for this example, just think that list is
2418
04:43:31,880 --> 04:43:37,330
collection of a lot of elements and we can
add insert more elements we can delete elements,
2419
04:43:37,330 --> 04:43:41,780
we can change elements and so on. Or we can
just initialize the list with just an empty
2420
04:43:41,780 --> 04:43:48,050
list and start inserting elements one by one
and expanding that list. Okay. Now, this is
2421
04:43:48,050 --> 04:43:56,080
an empty list for example, and four is just
a variable for i in this range isn't it greater
2422
04:43:56,080 --> 04:44:03,160
range then means sequentially give a number
one by one starting from zero start from zero
2423
04:44:03,160 --> 04:44:09,360
a gift num give numbers one by one for example,
first time give zero I will contain zero second
2424
04:44:09,360 --> 04:44:14,790
time give 1/3 time give two and so on after
every equation the range will give another
2425
04:44:14,790 --> 04:44:21,000
number as long as the numbers they are smaller
than 10. So, the last number that this range
2426
04:44:21,000 --> 04:44:26,580
will return will be nine. So whatever this
is written inside is not included and it starts
2427
04:44:26,580 --> 04:44:35,680
from zero. So as long as I is in this range
is lower than 10 as long as that you that
2428
04:44:35,680 --> 04:44:40,770
the body of the loop just like the body of
the while loop. So first time I will be zero
2429
04:44:40,770 --> 04:44:47,120
and zero is smaller than 10 Okay, you print
i i plus one and abandon the square of that
2430
04:44:47,120 --> 04:44:52,600
in a list. Then next time this range will
automatically return the next number into
2431
04:44:52,600 --> 04:45:00,220
I. Now next time I will contain one next time
I will contain two Next time I will continue
2432
04:45:00,220 --> 04:45:06,470
In three, four or 5678 and nine, once the
value of AI becomes nine, that's the last
2433
04:45:06,470 --> 04:45:12,660
iteration of this body of the loop. And after
that the loop finishes. So let's just write
2434
04:45:12,660 --> 04:45:19,280
on this very very first time I will be zero
when the loop enters its body very first time
2435
04:45:19,280 --> 04:45:24,570
I will be zero and one will be printed because
we are printing i plus one, at that time the
2436
04:45:24,570 --> 04:45:30,208
list and the empty list will be having one
number which is zero square. So list will
2437
04:45:30,208 --> 04:45:37,022
be having just one number zero, because zero
square, so, next time I will be one and we
2438
04:45:37,022 --> 04:45:43,690
will print two and the list will contain one
square which is one, next time I will be three
2439
04:45:43,690 --> 04:45:50,110
we will I will be two we will print three
and we will be having a square of two which
2440
04:45:50,110 --> 04:45:59,772
is four, and so on till so until 10 here,
when I will be nine we will print print 10.
2441
04:45:59,772 --> 04:46:07,040
And in this list, we will be having nine square
which is 81, I guess, and after that the loop
2442
04:46:07,040 --> 04:46:10,170
finishes and we will be out of this loop.
2443
04:46:10,170 --> 04:46:16,270
Okay, let's see this. Let's see example of
this in, in Jupiter just to get more comfortable
2444
04:46:16,270 --> 04:46:24,980
with with list as well as the for loop. So
let's see, let's say we have an empty list,
2445
04:46:24,980 --> 04:46:31,130
let's say an empty list. Just to consider
a list like this L is just a variable, you
2446
04:46:31,130 --> 04:46:39,570
can write another variable a name, that's
a variable name L. Okay. So for i in range,
2447
04:46:39,570 --> 04:46:46,960
in is a keyword range is a function in is
a keyword, i in range. For example, let's
2448
04:46:46,960 --> 04:46:56,120
say then, what you do is you brand, your brand
i plus one or whatever you want to do, that's
2449
04:46:56,120 --> 04:47:02,130
the body of the loop, and Eldad a band, that's
a function of the lists, we will see that
2450
04:47:02,130 --> 04:47:10,861
in detail in the data structure sessions.
Okay, and that's it, the loop finishes. When
2451
04:47:10,861 --> 04:47:17,430
you finish the loop, just print the whole
list. So let's print the list. And you can
2452
04:47:17,430 --> 04:47:25,640
see the result 1-234-567-8910. And that's
the these are the values in the list. As as
2453
04:47:25,640 --> 04:47:31,660
I mentioned earlier, all the little the values.
By the way, this range function actually,
2454
04:47:31,660 --> 04:47:39,200
if What if we want it to jump more than just
one, for example, b we want it to start from
2455
04:47:39,200 --> 04:47:45,793
zero, it reaches 10. And let's say we want
two jumps to be taken as two rather than one
2456
04:47:45,793 --> 04:47:51,600
and one. So the very first time so that's
the start location. That's the end location
2457
04:47:51,600 --> 04:47:55,850
which is not included start location is included
and location is not included. And that's a
2458
04:47:55,850 --> 04:48:01,830
step size. So very first time I will be one
you move inside, then a jump of two will be
2459
04:48:01,830 --> 04:48:08,820
taken the next time I will be so very first
time the AI will be zero, then you move inside
2460
04:48:08,820 --> 04:48:13,820
then the jump of two, then you move inside
then a jump of two then you move inside as
2461
04:48:13,820 --> 04:48:19,430
long as you stay smaller than 10 you will
move inside the loop body of the loop. So
2462
04:48:19,430 --> 04:48:27,330
let's see what now printed let's print just
I rather than i plus one there was an error
2463
04:48:27,330 --> 04:48:36,030
was the error 00 the range function does not
have colons, it has actually commas. Sorry,
2464
04:48:36,030 --> 04:48:44,270
my mistake. I was just a MATLAB user one.
So MATLAB actually has this colon things.
2465
04:48:44,270 --> 04:48:51,500
So I was just confusing MATLAB notation with
this. Okay, great. So so first time i was
2466
04:48:51,500 --> 04:48:56,660
zero, next time a jump of two, I becomes two.
Next aim to jump off to AI becomes four, then
2467
04:48:56,660 --> 04:49:01,840
I become six, then I becomes eight. And next
time I becomes 10. But 10 is not included.
2468
04:49:01,840 --> 04:49:10,110
So you're out of the loop. And that's the
squares that you got. It is not necessary
2469
04:49:10,110 --> 04:49:16,090
that you always start from zero, you can start
from one and you can j take a jump for example
2470
04:49:16,090 --> 04:49:21,112
the jump of three. And it's not necessary
that you just reach them you can reach for
2471
04:49:21,112 --> 04:49:26,602
example 20 it's up to you it's completely
your choice. And in that case, you have this
2472
04:49:26,602 --> 04:49:33,740
kind of vibrations. So this range function
really is helpful for creating over over a
2473
04:49:33,740 --> 04:49:40,591
loop body or a structure. Okay, great. So
that was introduction of for loop and we have
2474
04:49:40,591 --> 04:49:49,340
iterated here on on our list we just have
actually populated a list using for loops.
2475
04:49:49,340 --> 04:49:56,940
Okay In the next video we will see more details
of this for loop and more fun stuff. Okay,
2476
04:49:56,940 --> 04:50:03,800
hope to see you in the next video. Last time,
we saw four In the last video, and magically
2477
04:50:03,800 --> 04:50:10,430
this else has something to do with for loop
in Python. Well this else clause makes sense
2478
04:50:10,430 --> 04:50:18,110
for F. But in for loop it hardly makes sense.
But let me let me let me try to make sense
2479
04:50:18,110 --> 04:50:24,840
of else clause for follow there is an else
part of for loop as well in Python, not in
2480
04:50:24,840 --> 04:50:29,481
other languages. I don't know any other language
that has this L spark maybe there is some
2481
04:50:29,481 --> 04:50:32,140
but I don't know.
2482
04:50:32,140 --> 04:50:39,780
So this else part in Python, particularly
in follow, this else part or else that was
2483
04:50:39,780 --> 04:50:48,220
blocked will only execute if four completes
its iterations. For example, this is a set
2484
04:50:48,220 --> 04:50:55,130
a set like a list is is a collection list
is defined by square brackets set is defined
2485
04:50:55,130 --> 04:51:01,540
by curly brackets, the set is just similar
like the set in mathematics, we will see the
2486
04:51:01,540 --> 04:51:08,650
set lists tuples dictionaries and many of
these data structures in detail in data structures
2487
04:51:08,650 --> 04:51:12,330
portion, but just I have introduced this,
just consider this set has three elements
2488
04:51:12,330 --> 04:51:20,280
Apple 4.9, and Jerry. Apple is one object
or one data. 4.9 is one data, which is a floating
2489
04:51:20,280 --> 04:51:25,292
point data and Jerry is one data which is
a string data. Okay, so this S has three elements,
2490
04:51:25,292 --> 04:51:31,790
three different elements. So now for x in
this set, as long as x is in the set, the
2491
04:51:31,790 --> 04:51:37,520
very first time the x will be Apple, so it
will print Apple, next time x will contain
2492
04:51:37,520 --> 04:51:45,050
a 4.9 as long as so I create over this set,
as long as x is inside the set big elements
2493
04:51:45,050 --> 04:51:52,450
one by one, and just print them all. Okay,
we expect that when x is Apple, when the very
2494
04:51:52,450 --> 04:51:57,890
first time x will be Apple, it will print
Apple next time x will be 4.9 it will print
2495
04:51:57,890 --> 04:52:02,660
4.9. Next time x will be cherry it will print
cherry, and the loop ends because there is
2496
04:52:02,660 --> 04:52:09,680
no item in sets to iterate over. Because the
loop finishes it's complete iteration there
2497
04:52:09,680 --> 04:52:14,720
are expected three iterations and the loop
finishes those now the else part will execute
2498
04:52:14,720 --> 04:52:19,470
and you will say okay, loop completed. So
iterations. Well, you will be wondering in
2499
04:52:19,470 --> 04:52:26,600
what case the else will not else will not
execute. If you apply any brake statement
2500
04:52:26,600 --> 04:52:33,660
inside the loop body, which means you forcefully
you forcefully remove some of the iterations
2501
04:52:33,660 --> 04:52:40,900
that were going to be executed but the loop
did not complete it did not complete citations,
2502
04:52:40,900 --> 04:52:48,700
then the L spot will not run. So let's see
an example in in in Jupiter to get a good
2503
04:52:48,700 --> 04:52:57,708
grip on this else. Okay, let's define a set
S. S is a variable name. You can have any
2504
04:52:57,708 --> 04:53:08,030
variable name that say it Apple, or let's
say 4.9 I guess and then we was having, let's
2505
04:53:08,030 --> 04:53:17,782
say, Sherry, if if these Spelling's are correct,
I guess jelly. Okay, then for x in PES, as
2506
04:53:17,782 --> 04:53:34,300
long as x is ns Brand X. Fine ELLs rant, when
you finish the law terminates with success,
2507
04:53:34,300 --> 04:53:39,650
or all iterations it completed all its iterations.
And this is a statement that is completely
2508
04:53:39,650 --> 04:53:52,240
outside the loop. side the loop, so let's
run this. So you can see Apple 4.9 cherry
2509
04:53:52,240 --> 04:53:59,270
loop terminates with success outside the loop.
Okay. Now you might be thinking in what case
2510
04:53:59,270 --> 04:54:09,350
this else will not execute. Okay, if, for
example, as long as x is an N, if I say okay,
2511
04:54:09,350 --> 04:54:16,060
let's say I take a counter here, I equals
one, that's a counter, let's say, and every
2512
04:54:16,060 --> 04:54:31,220
time I just increment i, i plus equals one,
and then I check if i is equal to three. If
2513
04:54:31,220 --> 04:54:37,340
y is equal to three, then just break. Let's
say
2514
04:54:37,340 --> 04:54:47,830
else just for readability else was now this
else is else of this four. And this else is
2515
04:54:47,830 --> 04:54:53,792
else of this if and this POS statement is
just a statement for doing nothing. Now what
2516
04:54:53,792 --> 04:55:00,470
you do when is equal to one you Brent this
i plus equals I becomes two two is equal to
2517
04:55:00,470 --> 04:55:07,622
three false, so you pass you move on. Next
time, x will print 4.9, I will become three
2518
04:55:07,622 --> 04:55:11,841
and three is equal to three, that's correct,
the break will execute, which means the loop
2519
04:55:11,841 --> 04:55:17,830
should have one more iteration, but the break
just disrupt that one more iteration that
2520
04:55:17,830 --> 04:55:23,500
should be there, because the loop could not
complete its iteration due to this certain
2521
04:55:23,500 --> 04:55:28,450
condition, this else part of the loop will
not execute, and you will go directly outside
2522
04:55:28,450 --> 04:55:33,790
this loop. So let's run this code and see
the result. So you can see this apple four
2523
04:55:33,790 --> 04:55:41,810
by nine outside the loop. I would recommend
although this else is there for for loop,
2524
04:55:41,810 --> 04:55:49,850
but I would recommend to avoid using ELS in
the beginning, I mean, you may be confusing
2525
04:55:49,850 --> 04:55:54,350
this else By the way, there is a there is
a mistake here, this l should be ended with
2526
04:55:54,350 --> 04:56:00,770
a colon here, okay. So I would recommend to
not use LS clause for a for loop in the beginning
2527
04:56:00,770 --> 04:56:07,210
until you you really need it. Because you
may confuse this else with the with the L
2528
04:56:07,210 --> 04:56:11,270
of F condition. And you may think something
else and the program behave in a different
2529
04:56:11,270 --> 04:56:20,210
way. So either way, if you want to use LS
LS for a for loop is there in Python. Okay,
2530
04:56:20,210 --> 04:56:27,380
just one more example of for loop. And here
we use dictionary, I'm introducing some data
2531
04:56:27,380 --> 04:56:31,690
structures here just for fun, we will see
these data structures in detail later on.
2532
04:56:31,690 --> 04:56:37,772
So dictionary, that's a key value period like
set, but one item is consists of two numbers,
2533
04:56:37,772 --> 04:56:42,772
that's called a key. And that is called a
value. That's a key. And that's a value like
2534
04:56:42,772 --> 04:56:51,130
a dictionary, we have key and values. So now
as long as x is an X, X represents two key
2535
04:56:51,130 --> 04:56:59,430
and d is our dictionary and D off x represents
to whatever value that x points to, for example,
2536
04:56:59,430 --> 04:57:04,532
Apple is a key that points to 44. Cherry is
a key that points to gain. For example, if
2537
04:57:04,532 --> 04:57:15,530
we're ID, apples, apple, the result will be
44. Similarly, d of Jerry, the result will
2538
04:57:15,530 --> 04:57:21,952
be game. Okay, so let's I create over this
dictionary using this for loop. All am I showing
2539
04:57:21,952 --> 04:57:27,740
you that this for loop is very, very handy
of creating over different data structures
2540
04:57:27,740 --> 04:57:34,480
and a lot of data and stuff. Whereas file
while loop is more handy and checking the
2541
04:57:34,480 --> 04:57:39,650
conditions and stuff. Although you can do
all the stuff using while loop you can always
2542
04:57:39,650 --> 04:57:46,261
stuff using for loop but one is better over
the other insert in certain situations. So
2543
04:57:46,261 --> 04:57:55,270
that's let's let's just run this for a dictionary.
Let's say I have a dictionary D. It's defined
2544
04:57:55,270 --> 04:58:04,980
like a set, let's say my key is a and my value
is 10. Let's say my key is B and value is
2545
04:58:04,980 --> 04:58:18,270
minus 19. And let's say my key is C and my
value is let's say ABC, let's say that's my
2546
04:58:18,270 --> 04:58:30,630
dictionary. So for x in the Brent the key
as well as the value of that key. So now you
2547
04:58:30,630 --> 04:58:35,203
can see the key is a the value of Stan The
key is B the value is minus 90 in the key
2548
04:58:35,203 --> 04:58:43,650
of C the values ABC. So this far loop is really
really handy and iterated over a lot of data
2549
04:58:43,650 --> 04:58:50,110
structures and stuff although it has other
applications as well but this is handy. Okay
2550
04:58:50,110 --> 04:58:56,730
great. So that's about loops for loops. And
while loops These are two kinds of loops in
2551
04:58:56,730 --> 04:59:00,281
important loop these are two important kind
of loops and they are in
2552
04:59:00,281 --> 04:59:08,760
Python, in the next video I will directly
go to Jupiter and Jupiter notebook and we
2553
04:59:08,760 --> 04:59:14,530
will be practicing for this for loops or while
loops. We will be practicing the loops we
2554
04:59:14,530 --> 04:59:19,600
will be doing actually examples of nested
loops we will be actually solving a problem
2555
04:59:19,600 --> 04:59:23,920
like we did in the if conditions we solve
the problem Previously, we wrote a code for
2556
04:59:23,920 --> 04:59:30,980
it. Here we will also write a code and we
will be get a good grip on the loops. So hope
2557
04:59:30,980 --> 04:59:36,320
to see you in the next video we will solve
a problem in Jupyter Notebook directly. Okay,
2558
04:59:36,320 --> 04:59:42,160
hope to see you in the next video. Okay, welcome
back. In this particular video we are going
2559
04:59:42,160 --> 04:59:47,980
to practice for loops are basically loops.
So let's have a problem statement. First,
2560
04:59:47,980 --> 04:59:52,110
what problem we are going to solve let's have
comments. And the problem we are going to
2561
04:59:52,110 --> 05:00:09,488
solve is let's define given a list of of numbers,
numbers. For example, I II, let's say 124
2562
05:00:09,488 --> 05:00:30,620
minus five, a 7932, like this, make another
list making another list that contains all
2563
05:00:30,620 --> 05:00:52,090
the items in sorted order from minimum to
maximum, ie, your result will be another list.
2564
05:00:52,090 --> 05:01:00,100
Like, in this particular case, we will be
having minus five, which is smallest, then
2565
05:01:00,100 --> 05:01:06,888
we will be having one, then we'll be having
two, then we'll be having two, then we will
2566
05:01:06,888 --> 05:01:13,110
be having two, then we'll be having three.
So all items, but in minimum to maximum sorted
2567
05:01:13,110 --> 05:01:18,790
order, then we having I guess, four, then
we'll be having seven, and then we'll be having
2568
05:01:18,790 --> 05:01:25,532
nine. So that's your, that should be your
output in another list. So assuming this list
2569
05:01:25,532 --> 05:01:30,840
is available to you, or any list is available
to you assume this list is available to you.
2570
05:01:30,840 --> 05:01:36,380
So how to solve that problem? Let's start.
Okay, let's assume that the list is available.
2571
05:01:36,380 --> 05:01:47,100
That's it, this is the list we are going to
sort. Let's say this is available. Okay. Okay.
2572
05:01:47,100 --> 05:01:55,740
So, what should be the logic? What should
be the logic? How can we solve that problem?
2573
05:01:55,740 --> 05:02:05,250
This is, this is an easy looking problem,
but it is not so easy. Let us first right.
2574
05:02:05,250 --> 05:02:10,660
Let us just simplify this problem to just
finding out a minimum from the list. Let's
2575
05:02:10,660 --> 05:02:15,600
say we are given a list and we just want to
find out minimum number one a minimum from
2576
05:02:15,600 --> 05:02:24,080
the list. So how can we move that. So let's
say M is some number. So M is the very first
2577
05:02:24,080 --> 05:02:29,512
value of the list, let's MSP our variable,
let's say that's the first value. And what
2578
05:02:29,512 --> 05:02:47,760
we do is for i in the for i n L, as long as
I is an L, if I AI is smaller than m, then
2579
05:02:47,760 --> 05:02:59,080
if AI is smaller than m, then m should contain
AI. Otherwise do nothing. That's it. So at
2580
05:02:59,080 --> 05:03:07,880
the end, rentas m, then this m at the end.
So, Brent, the minimum number, that's great.
2581
05:03:07,880 --> 05:03:22,010
So so that's the nasty, basically. So yeah,
that's the that's how we will find out just
2582
05:03:22,010 --> 05:03:27,900
the minimum value. So let's run this code.
And the minimum is minus five available to
2583
05:03:27,900 --> 05:03:35,520
us. What if we want to store the minimum value
as well as the position of that value? For
2584
05:03:35,520 --> 05:03:42,990
example, we not only want to just find out
what is the minimum number, we also want to
2585
05:03:42,990 --> 05:03:48,400
find out at what index for example, here 012,
and three, at the third index, we found the
2586
05:03:48,400 --> 05:03:53,890
minimum, what if we're interested in the index
as well. So let's say for the very beginning,
2587
05:03:53,890 --> 05:03:57,330
the index is zero. And then what we do is
2588
05:03:57,330 --> 05:04:07,200
we moved on and we say, okay, we maintain
a counter, let's say a counter is C equals
2589
05:04:07,200 --> 05:04:17,230
c equals zero, for example, right now, and
C, just plus equals to one, that's a counter
2590
05:04:17,230 --> 05:04:26,740
and then this ID x is just that C, whatever
that c is. So whatever that index is, when
2591
05:04:26,740 --> 05:04:34,080
we find this C, that index is also there.
So let's print the index as well as the minimum
2592
05:04:34,080 --> 05:04:40,780
value. So okay, so at the position three,
at index three, we found the minimum value,
2593
05:04:40,780 --> 05:04:49,352
okay, now we have written kind of a code block
that helps us finding out the minimum value.
2594
05:04:49,352 --> 05:04:57,500
How can we actually how can we actually do
how can we act? So the basic logic is you
2595
05:04:57,500 --> 05:05:05,800
find the minimum value and swap the that value
with the very first value, okay, great. And
2596
05:05:05,800 --> 05:05:12,202
then move the loop next time find out the
minimum value from the remaining list and
2597
05:05:12,202 --> 05:05:17,862
swap that minimum value with the second value.
Next time you find the minimum value, as long
2598
05:05:17,862 --> 05:05:23,990
as the position and swap that with the third
value and so on. So do that stuff and just
2599
05:05:23,990 --> 05:05:29,900
rearrange the same list using this but, but
how can the so that's the logic find out the
2600
05:05:29,900 --> 05:05:35,440
minimum value. So happened with the first
value and then start from two till end start
2601
05:05:35,440 --> 05:05:40,950
from start from the remaining values, find
the minimum so appid with the first value
2602
05:05:40,950 --> 05:05:46,840
of the remaining list, then reduce the list
step by step and you will be having a sorted
2603
05:05:46,840 --> 05:05:55,530
order, but how to start with how to find out
like this how to how to do that. So, any idea
2604
05:05:55,530 --> 05:06:01,070
and we are going to so for example, in this
particular case, if I want to swap the list,
2605
05:06:01,070 --> 05:06:10,480
what I will do is I will say okay, swap with
zero at the at the at the zero, so, I will
2606
05:06:10,480 --> 05:06:18,520
contain a temporary variable, temporary variable
will contain the value of zero, this zero,
2607
05:06:18,520 --> 05:06:29,750
so what I will do is at least zero, right
the minimum value and the minimum value. So
2608
05:06:29,750 --> 05:06:35,640
at zero you write the minimum value, but at
this particular index, from there, we found
2609
05:06:35,640 --> 05:06:45,440
the minimum value, just place the just place
the the value at the very beginning. So in
2610
05:06:45,440 --> 05:06:50,660
after that, after that operation, the minimum
will be at the first position, or the zeroeth
2611
05:06:50,660 --> 05:06:54,840
index, and that value will be some minimum
value will be swapped with the very first
2612
05:06:54,840 --> 05:07:01,330
value. So let's run this code and see what
a list looks like after that good. So you
2613
05:07:01,330 --> 05:07:07,120
see, for example, the minimum value is swept
by the first value, whatever the first value
2614
05:07:07,120 --> 05:07:12,270
was, but we want to do that progressively
for for the rest of the list, we want to find
2615
05:07:12,270 --> 05:07:16,872
out the minimum and follow up with the first
one for the rest of the list and keep on moving.
2616
05:07:16,872 --> 05:07:27,470
How can we do that? So yeah, that's, that's,
so let me define four. So let me first in
2617
05:07:27,470 --> 05:07:39,230
depth a bit, let's say control right bases
that will indent all my code. So for j in
2618
05:07:39,230 --> 05:07:47,140
range, length of the list, whatever the length
of list, let's say for G is that so what I
2619
05:07:47,140 --> 05:08:03,930
do is M is the gf value the index right now
is J and the C is also C is also the Convert
2620
05:08:03,930 --> 05:08:11,780
C is also starts from J, okay, great. Now,
we want it to start with two now we want this
2621
05:08:11,780 --> 05:08:24,780
I to start from J and move onwards here. So
let's say i in range, start from G and go
2622
05:08:24,780 --> 05:08:33,192
till length of L, one by one, take the step
of one. Okay, great. So what next? Now the
2623
05:08:33,192 --> 05:08:43,300
value will be L of I, rather than simply L
of I rather than simply I in that case, you
2624
05:08:43,300 --> 05:08:46,180
do this.
2625
05:08:46,180 --> 05:08:54,790
Okay, and the index is just C. Okay, great.
Keep on keep on introducing this index again,
2626
05:08:54,790 --> 05:09:04,610
after this loop, what you do is you pick the
gf value, you slap the gf value with the minimum.
2627
05:09:04,610 --> 05:09:12,970
And you do that. And that's it, you keep on
moving and offer after the outer loop finishes.
2628
05:09:12,970 --> 05:09:19,780
If you branch your list, you will be having
the list sorted or at least we hope so. So
2629
05:09:19,780 --> 05:09:23,540
maybe there is a bug in the code or maybe
there is a problem in the code. But we hope
2630
05:09:23,540 --> 05:09:27,770
this will work. What we are doing progressively
By the way, this is a nested loop. This is
2631
05:09:27,770 --> 05:09:33,180
a loop inside the loop and that's and then
we have an if condition inside the nested
2632
05:09:33,180 --> 05:09:42,120
loop. Loop inside the loop. Great. Let's see
how it how it works. If there is no Oh there
2633
05:09:42,120 --> 05:09:48,290
is an error length of range. Oh, we haven't
write a colon there. Don't forget this colon.
2634
05:09:48,290 --> 05:09:55,940
That's a problem. Oh, we have a sorted order.
Oh my god. We have a result with us. You see
2635
05:09:55,940 --> 05:10:02,040
the applications of this. Oh, one three is
missing. We were is three, we have two threes
2636
05:10:02,040 --> 05:10:07,600
Oh, the output we have written here is wrong,
there is no two threes there is only one three.
2637
05:10:07,600 --> 05:10:14,190
So you have sorted a list. If you remember,
we have written a similar kind of code in
2638
05:10:14,190 --> 05:10:18,870
the problem. So problem solving session very
earlier, where we solve this problem using
2639
05:10:18,870 --> 05:10:25,262
selection sort, but they are we just wrote
a pseudocode. And here we have a code much
2640
05:10:25,262 --> 05:10:31,590
simpler than actually the Python code. If
the problem was just sorting there are built
2641
05:10:31,590 --> 05:10:36,440
in functions to do that, but I'm just telling
you how these loops and if conditions and
2642
05:10:36,440 --> 05:10:43,360
all that stuff can be used to communicate
with each other to match with each other to
2643
05:10:43,360 --> 05:10:49,280
to actually perform a problem solving task
when given a problem. Although we will see
2644
05:10:49,280 --> 05:10:53,410
later on in Python, most of the problem solving
tasks, I mean many more of them, there are
2645
05:10:53,410 --> 05:10:57,570
a built in function for those that are available
functions for those you need not write all
2646
05:10:57,570 --> 05:11:02,350
that stuff, but to mastering to to master
any programming language, you have to go through
2647
05:11:02,350 --> 05:11:08,390
these constructs. So that for a new problem,
or for a very large, complicated kind of problem,
2648
05:11:08,390 --> 05:11:14,640
eventually you you may need these kind of
structures with you. So mastering these structures
2649
05:11:14,640 --> 05:11:20,110
is really essential for problem solving and
programming in general. So okay, that's about
2650
05:11:20,110 --> 05:11:27,210
the loops and if conditions and control. So,
all of that, in the next video, I will I will
2651
05:11:27,210 --> 05:11:31,990
start talking about functions. So you have
seen this L e m data function, you have seen
2652
05:11:31,990 --> 05:11:37,692
this range, that's that's function idolater.
Although you have seen around function, you
2653
05:11:37,692 --> 05:11:42,910
have seen def mode, you have seen print function,
what if we want to write our own function?
2654
05:11:42,910 --> 05:11:47,860
How can we do that? From the next video, I'm
going to show you how can we write our own
2655
05:11:47,860 --> 05:11:54,560
function? Wow, isn't that great? That's great.
So hope to see you in the next video. In this
2656
05:11:54,560 --> 05:12:02,740
video, I will talk about functions. A very
powerful construct in almost every programming
2657
05:12:02,740 --> 05:12:08,670
language. Python also supports functions.
What a function is, let me let me describe
2658
05:12:08,670 --> 05:12:14,070
the let me describe the need of the function
by a scenario. Let me give you a scenario.
2659
05:12:14,070 --> 05:12:21,000
The scenario is let's say you are writing
a very lengthy program, the program requires
2660
05:12:21,000 --> 05:12:29,360
to print particular messages whenever needed,
for example, you need to print this particular
2661
05:12:29,360 --> 05:12:38,050
message the task, the task was successful,
let's say you need to print this. And then
2662
05:12:38,050 --> 05:12:44,340
you have to print moving to the next task
maybe to to inform somebody maybe in to inform
2663
05:12:44,340 --> 05:12:49,250
your client. And then you have to ask, okay,
send me the next task. Because I am done with
2664
05:12:49,250 --> 05:12:54,208
the previous task, let's say you want to print
this, or maybe you want to print more or do
2665
05:12:54,208 --> 05:12:58,452
some more stuff. And let's say you want to
do this again. And again, whenever needed.
2666
05:12:58,452 --> 05:13:03,692
Somewhere, whenever you complete a particular
task or something, you want to print all these
2667
05:13:03,692 --> 05:13:09,650
messages, and then somewhere else, whenever
a particular event occurs, you need to print
2668
05:13:09,650 --> 05:13:15,360
all these messages again. Now one way to do
that is to write just these print statements
2669
05:13:15,360 --> 05:13:21,330
whenever needed in the program. One way is
if you want to perform a task and the task
2670
05:13:21,330 --> 05:13:27,440
has a lot of coding, maybe maybe maybe a very
small amount of coding or maybe a very large
2671
05:13:27,440 --> 05:13:32,070
amount or magnitude of the coding. In this
case, we have just three statements, but maybe
2672
05:13:32,070 --> 05:13:36,690
we have a task that we want to perform again
and again and it is really a very lengthy
2673
05:13:36,690 --> 05:13:38,970
task in terms of the coding.
2674
05:13:38,970 --> 05:13:47,240
So, one way to do that is to just write all
the coding in coding somewhere and define
2675
05:13:47,240 --> 05:13:54,372
a function and that function means the function
contain all the tasks that you need to perform,
2676
05:13:54,372 --> 05:14:00,530
whenever you need to perform that particular
task. Just in your coding, just call this
2677
05:14:00,530 --> 05:14:06,570
one statement, just this one statement, and
the whole task that is written under this
2678
05:14:06,570 --> 05:14:15,250
under this content maintaining this as a heading
that will execute automatically I mean, however,
2679
05:14:15,250 --> 05:14:20,410
I mean, that task that is under this heading
may be very lengthy may be short, may may
2680
05:14:20,410 --> 05:14:26,510
be complicated, may be simple one or anything,
but the need is we want to perform this task
2681
05:14:26,510 --> 05:14:31,290
whenever we need. And we do not write to code
this again and again we do not write to code
2682
05:14:31,290 --> 05:14:36,800
we do not write to we do not want to write
the same lines of codes again and again and
2683
05:14:36,800 --> 05:14:43,430
again. And again in our program. Just write
this particular lines of code once define
2684
05:14:43,430 --> 05:14:49,452
a function, just like a task. Whenever you
need to perform that task, just call the heading
2685
05:14:49,452 --> 05:14:55,080
or the name of the function. And the whole
task under that function will execute functions
2686
05:14:55,080 --> 05:15:00,030
in almost all programming languages. They
do that even in mathematics. They do that
2687
05:15:00,030 --> 05:15:05,542
In Python, the syntax of defining function
is you if you want to define a function, you
2688
05:15:05,542 --> 05:15:13,431
have to first start with D E F meaning definition
or defining, then you need to write the name
2689
05:15:13,431 --> 05:15:19,050
of that function the name of that function
name a function and name a variable has resemblance,
2690
05:15:19,050 --> 05:15:25,950
I mean, the name of functions should be descriptive,
it should, it should portray what the function
2691
05:15:25,950 --> 05:15:30,410
actually is doing. So, it is good to write
it is good to suggest the names of the functions
2692
05:15:30,410 --> 05:15:35,692
that are very descriptive to make the code
readable and manageable. So, here I have written
2693
05:15:35,692 --> 05:15:40,110
the function name is sprint success, you can
write any name, then you start parenthesis
2694
05:15:40,110 --> 05:15:44,220
then you end parenthesis and then you write
a colon like you have written the colon for
2695
05:15:44,220 --> 05:15:51,320
if conditions are for loops or any other constructs.
And then you do indent like the body of the
2696
05:15:51,320 --> 05:15:54,950
for loop like the body of the if condition,
this is the body of the function, body of
2697
05:15:54,950 --> 05:16:00,250
the function is all should all be aligned,
then you write all the tasks, all the coding
2698
05:16:00,250 --> 05:16:05,950
that you need to be performed whenever this
function is invoked or called, this body can
2699
05:16:05,950 --> 05:16:11,250
contain if conditions for loops inside, I
mean, this can have a whole lot of coding
2700
05:16:11,250 --> 05:16:16,862
inside it. And whenever you will call this
function, whenever you will type this command,
2701
05:16:16,862 --> 05:16:22,130
wherever in your coding, the whole task under
this will be executed automatically again
2702
05:16:22,130 --> 05:16:28,830
and again whenever you like. So, let's take
a look of defining our first function in Jupyter.
2703
05:16:28,830 --> 05:16:41,610
notebook. Let's just I guess, yes. So, yeah,
so, that's our notebook, we were populating
2704
05:16:41,610 --> 05:16:46,750
that notebook. So by the way, if you if you
want to know where this notebook is located,
2705
05:16:46,750 --> 05:16:53,910
if I want to, for example, invoke that notebook
again, when you will run your Jupyter Notebook
2706
05:16:53,910 --> 05:16:58,720
from the Anaconda prompt, you will be having
all the files that you are working on. And
2707
05:16:58,720 --> 05:17:03,980
one file is for example, this you just click
on that, and your file one or more files,
2708
05:17:03,980 --> 05:17:10,590
whatever you want to open up that will open
up in the Jupyter. notebook. Yes, so it is
2709
05:17:10,590 --> 05:17:17,430
opening up, it's a lengthy file, so it may
take may take a second. Okay. Let me just
2710
05:17:17,430 --> 05:17:25,650
take a better zoom level, just to Okay, so
we were working on that notebook, let's define
2711
05:17:25,650 --> 05:17:39,100
our first function, let's say D, F, define.
Let's say the function name is Brent. Success.
2712
05:17:39,100 --> 05:17:56,690
That's a, that's a syntax, then press enter,
Brent, I am done. Then Brent, send me another
2713
05:17:56,690 --> 05:18:04,020
task. Let's see. And that's it. Let's say
that's the, that's the body of the function,
2714
05:18:04,020 --> 05:18:10,850
the body of the function here contains only
two statements, okay, then you run this, you
2715
05:18:10,850 --> 05:18:16,640
run this command, just like Shift Enter, you
run this. So that
2716
05:18:16,640 --> 05:18:20,958
it is it is reported in the symbol table,
there is a symbol table inside the Python
2717
05:18:20,958 --> 05:18:25,970
maintaining Python is maintaining all the
variables all the function information inside.
2718
05:18:25,970 --> 05:18:31,280
So once you run this cell, then the then this
print success function will be registered
2719
05:18:31,280 --> 05:18:35,930
to Python. So that whenever you want to call
this function, again, it will be available.
2720
05:18:35,930 --> 05:18:40,911
Now if you want to perform this task, let's
say you want to perform, let's say you want
2721
05:18:40,911 --> 05:18:46,458
to perform this task whenever you want. So
you just call this function, this is called
2722
05:18:46,458 --> 05:18:52,540
calling of the function. whatever I'm doing
now, when success and that's it, you press
2723
05:18:52,540 --> 05:18:59,440
Shift Enter, and the all the statements that
are under this will be executed. And you do
2724
05:18:59,440 --> 05:19:07,202
some other stuff, let's say three plus eight
that is that is 11 do some other stuff. And
2725
05:19:07,202 --> 05:19:17,100
afterwards, if you want to do the same process
again, then you call this function again and
2726
05:19:17,100 --> 05:19:22,160
all the coding inside the function will be
executed it is very, very handy. If a particular
2727
05:19:22,160 --> 05:19:28,380
task if you want to perform that task repeatedly,
it is good to just write one code for that
2728
05:19:28,380 --> 05:19:35,900
task in a function and then just invoke function
whenever you need. It supplies a lot of managing
2729
05:19:35,900 --> 05:19:41,700
power, a lot of debugging power if you have
an error for example, inside the function,
2730
05:19:41,700 --> 05:19:46,960
you just go to the code we just go to the
code of the function itself and fix the error
2731
05:19:46,960 --> 05:19:52,692
and come back You need not to you need not
to go all over the code if you have not defined
2732
05:19:52,692 --> 05:19:58,220
the function and you have called these lines
of codes everywhere inside your main code,
2733
05:19:58,220 --> 05:20:04,792
then it will become very difficult to handle
And function actually provides a lot of a
2734
05:20:04,792 --> 05:20:10,690
lot of simplicity of managing and readability
and, and a modular approach in that sense.
2735
05:20:10,690 --> 05:20:18,500
So that was our first. That was our first
function. We will be talking about more, we'll
2736
05:20:18,500 --> 05:20:23,900
be talking more about this functions in the
next video. So hope to see you in the next
2737
05:20:23,900 --> 05:20:33,560
video. The function name should be descriptive,
that's okay. But it is further important sometimes
2738
05:20:33,560 --> 05:20:39,530
to have a documentation of the function sometimes
called the doc string, the doc string allows
2739
05:20:39,530 --> 05:20:46,250
you to write the description of the function.
But that description will never be executed,
2740
05:20:46,250 --> 05:20:52,920
it will be available whenever you need help.
Or you need to know what this function does.
2741
05:20:52,920 --> 05:20:56,900
Sometimes it happens your function can contain
a lot of code, for example, you have a particular
2742
05:20:56,900 --> 05:21:07,280
function, let's say, fun, let's say it contains
def, fun, and it does a lot of a lot of complicated
2743
05:21:07,280 --> 05:21:15,770
stuff inside. And it is sometimes required
to know what this function actually is doing.
2744
05:21:15,770 --> 05:21:21,910
So this document string is one way of describing
what the function is doing. You might be thinking
2745
05:21:21,910 --> 05:21:27,530
that if you're writing this document string
inside the where the where the coding of the
2746
05:21:27,530 --> 05:21:32,360
function should be written, we should open
up that the coding file and see what the function
2747
05:21:32,360 --> 05:21:37,071
is doing, or should we actually open up this
function implementation where the function
2748
05:21:37,071 --> 05:21:42,110
code is written. And then we have to read
what the function is doing. Actually, Python
2749
05:21:42,110 --> 05:21:46,970
gives you another power. If you have written
the document string inside, that should be
2750
05:21:46,970 --> 05:21:52,770
a top statement before the first coding statement.
Whatever description you want, as a document
2751
05:21:52,770 --> 05:21:57,750
string, it will be available without actually
opening up with without actually seeing what's
2752
05:21:57,750 --> 05:22:01,542
inside the funk without actually opening up
the file that contains the implementation
2753
05:22:01,542 --> 05:22:09,030
of this function. Let's see, let's see. Two
in Jupyter, notebook imore, completely whatever
2754
05:22:09,030 --> 05:22:19,220
I'm saying right now. So for example, let's
define a function. def print success. to let's
2755
05:22:19,220 --> 05:22:27,130
say the function name, this function is print
success to the function name is print success
2756
05:22:27,130 --> 05:22:33,610
two, although it's not a very descriptive
name, but the specimens are also not correct,
2757
05:22:33,610 --> 05:22:39,680
but that's fine. Print success to here I just
define a document Strank. The document string
2758
05:22:39,680 --> 05:22:45,390
may contain maybe just in one line, or it
may be a multi line, it is like a multi line
2759
05:22:45,390 --> 05:22:51,890
comment, or maybe a single line comment if
you want. But it starts with the three quotes
2760
05:22:51,890 --> 05:23:02,780
and ends with three quotes. Let's say I write
here this function is doing nothing except
2761
05:23:02,780 --> 05:23:15,970
renting. message, printing a message, let's
say full stop. And then I further define let's
2762
05:23:15,970 --> 05:23:23,640
say I define more in saying that that message
is
2763
05:23:23,640 --> 05:23:31,910
Hello, let's say, let's say are any description
you want for this function. Now, this is a
2764
05:23:31,910 --> 05:23:35,600
document string, and it will be available
whenever you need. Now here are the coding
2765
05:23:35,600 --> 05:23:42,960
starts, let's say you, right according here,
and again, hello, let's and you run this code.
2766
05:23:42,960 --> 05:23:48,150
Now, let's say we are not seeing this function
we are we are not available with this function.
2767
05:23:48,150 --> 05:23:53,950
We are not available with the code of this
function. And we want to know what this function
2768
05:23:53,950 --> 05:24:01,410
actually does. First of all, we can just write
if we write pri, and just press tab, the tab
2769
05:24:01,410 --> 05:24:07,860
will allow us to access all the functions
that are available with prefix pri. So let's
2770
05:24:07,860 --> 05:24:18,630
say we go to print success, brand success.
Brain success here brain success, as should
2771
05:24:18,630 --> 05:24:27,971
be capital, Brent success, let's say so print
success to let's say and we write a question
2772
05:24:27,971 --> 05:24:34,150
mark in front of it, and then just press Shift
Enter, it will pull the document string it
2773
05:24:34,150 --> 05:24:40,730
will pull the document strength whatever we
have written and we will get to know what
2774
05:24:40,730 --> 05:24:47,690
actually this this is doing. So this document
string actually does a lot of job further
2775
05:24:47,690 --> 05:24:53,160
if we I mean this is this is kind of whenever
we need to know what a function is doing.
2776
05:24:53,160 --> 05:24:57,631
The document string is one way to just go
and check what is what is happening. Right
2777
05:24:57,631 --> 05:25:02,510
now this function implementation is in front
of us But in several times, the function implementation
2778
05:25:02,510 --> 05:25:06,958
will not be in front of us several times,
we will be accessing functions that other
2779
05:25:06,958 --> 05:25:11,128
people have written in their libraries. And
we need to know what those functions are doing.
2780
05:25:11,128 --> 05:25:15,890
So document string is one very, very healthy
way of describing our function. And I will
2781
05:25:15,890 --> 05:25:21,782
recommend to make your habit writing document
strings, every time you write a function.
2782
05:25:21,782 --> 05:25:26,860
I was telling you that if you write a double
question mark, then it will not only pull
2783
05:25:26,860 --> 05:25:31,650
the document string for you, it will pull
the whole implementation as well. So now if
2784
05:25:31,650 --> 05:25:37,880
you see you, they said the document string,
and that's the implementation. So whole implementation
2785
05:25:37,880 --> 05:25:42,800
will be available, if you want. And this is
true for the functions that are that are,
2786
05:25:42,800 --> 05:25:47,050
that are the functions that are third party
functions, or some other person have written
2787
05:25:47,050 --> 05:25:52,760
that function and so on. For example, you
know, a function length, we call that function
2788
05:25:52,760 --> 05:25:58,372
several times. So let's let let's, let's see,
also the document string is returned, the
2789
05:25:58,372 --> 05:26:02,810
number of items in our container, that length
function is not written by us, somebody has
2790
05:26:02,810 --> 05:26:08,570
written that function that's a built in function,
by the way. And we can, this document string
2791
05:26:08,570 --> 05:26:13,080
tells us, okay, what this function is doing,
we don't have the implementation of that function,
2792
05:26:13,080 --> 05:26:21,980
obviously, somebody have written that function.
And, and if we write the double, then we should
2793
05:26:21,980 --> 05:26:28,900
get an implementation as long as the implementation
is not in c++, I haven't told you that a lot
2794
05:26:28,900 --> 05:26:34,042
of a lot of implementation of Python itself
has been done in C and some other languages
2795
05:26:34,042 --> 05:26:40,120
have C mostly. So several built in functions,
because of because of their speed, they are
2796
05:26:40,120 --> 05:26:45,340
implemented in C, and if you, if you want
to get their implementation, they get their
2797
05:26:45,340 --> 05:26:50,470
code, the code will not be available for most
of the functions. So that's so whenever you
2798
05:26:50,470 --> 05:26:54,980
write a double question mark, and the answer
is the same as a single question mark, that's
2799
05:26:54,980 --> 05:26:59,208
an indication that this particular function
is not written in plain Python, it is written
2800
05:26:59,208 --> 05:27:05,110
in some other language and is used in Python.
That's, in other words, the diversity or flexibility
2801
05:27:05,110 --> 05:27:11,542
of Python, you can engage multiple languages
inside, Okay, one more thing, I can write
2802
05:27:11,542 --> 05:27:17,240
Help, help command and I can get this Brent
success
2803
05:27:17,240 --> 05:27:30,480
success too. And the help of print success
to by just typing this help command. So, this
2804
05:27:30,480 --> 05:27:37,000
help will tell us, you see the Help is telling
us the document strike I mean, this help on
2805
05:27:37,000 --> 05:27:41,628
this function, if and this and this is the
function we have written, this is the function
2806
05:27:41,628 --> 05:27:46,630
we have written, this function is doing nothing
except whatever description we are giving
2807
05:27:46,630 --> 05:27:52,080
there. If, at some time, if we are supplying
this function to somebody, or making a package
2808
05:27:52,080 --> 05:27:56,970
of a lot of functions, that we are writing
these documents, strings will help to get
2809
05:27:56,970 --> 05:28:02,510
to know how to use these functions. By just
knowing the function name, we can, this document
2810
05:28:02,510 --> 05:28:08,032
string actually tells us how the what the
function is doing. While great Oh, by the
2811
05:28:08,032 --> 05:28:11,590
way, we haven't called this function yet,
we are just playing with the document string,
2812
05:28:11,590 --> 05:28:17,442
let's call the function print. Now we know
what the function is doing. let's print, let's
2813
05:28:17,442 --> 05:28:22,780
call this function. And whatever written inside
the function will be called See, this is only
2814
05:28:22,780 --> 05:28:32,890
called this is just acting as a comment and
it is basically a comment. Yeah. Okay, great.
2815
05:28:32,890 --> 05:28:38,590
Stay with us. There is much more about function
that we are going to tell you. Hope to see
2816
05:28:38,590 --> 05:28:45,120
you in the next video. Okay, in the last video,
we saw document strength. Or you might be
2817
05:28:45,120 --> 05:28:53,140
thinking, what is power of this function,
if it is doing some static task? Well, in
2818
05:28:53,140 --> 05:28:58,128
this video, I'm going to tell you that the
function can the coding or the behavior of
2819
05:28:58,128 --> 05:29:03,660
the function can be dynamic, based on based
on the arguments based on some properties
2820
05:29:03,660 --> 05:29:09,530
that you will be defining at the call time.
For example, the function has in almost all
2821
05:29:09,530 --> 05:29:13,490
programming languages, the functions, the
most interesting functions are the function
2822
05:29:13,490 --> 05:29:19,440
that receives an argument. And an argument
is just considered an argument just as a variable
2823
05:29:19,440 --> 05:29:26,330
and performs its task according to that to
that arguments. argument. Just take a single
2824
05:29:26,330 --> 05:29:31,760
simple example. Let's say rather than having
a function print success, we have a function
2825
05:29:31,760 --> 05:29:37,878
print message, and it it prints whatever message
it receives. And at the call time, for example,
2826
05:29:37,878 --> 05:29:49,110
we call this function like so print message.
And let's say we call this as, let's say,
2827
05:29:49,110 --> 05:29:56,458
success. Let's say now success will be printed.
Next time we call the function and we give
2828
05:29:56,458 --> 05:30:06,550
another argument maybe in a string, let's
say so 74 errors, let's see, that will be
2829
05:30:06,550 --> 05:30:11,780
that will be printed or anything, I mean,
anything that you supply will be printed.
2830
05:30:11,780 --> 05:30:20,458
Wow, isn't that great? I mean one function.
And you might be thinking the plain print
2831
05:30:20,458 --> 05:30:25,950
function does that what's the power of this?
Well, I'm just telling you the function of
2832
05:30:25,950 --> 05:30:30,250
the function does not only contain one line,
I mean, it can be a whole task depending upon
2833
05:30:30,250 --> 05:30:36,160
this input argument. And the whole task will
perform dynamically based on based on what
2834
05:30:36,160 --> 05:30:42,352
input argument you are supplying there. You
are noticing one one thing that I that I just
2835
05:30:42,352 --> 05:30:50,622
forgot, what is that thing I define this function?
I guess everything is fine. I just have just
2836
05:30:50,622 --> 05:30:54,610
missed something Oh, document string, I should
have written document string. Although document
2837
05:30:54,610 --> 05:30:58,860
string is not essential. If you do not write
document string, it's perfectly okay. The
2838
05:30:58,860 --> 05:31:03,440
function will run but it's a good practice.
It's an it's a good habit to always write
2839
05:31:03,440 --> 05:31:09,290
a document string. Okay, let's see the power
of input arguments by again, going to our
2840
05:31:09,290 --> 05:31:17,140
good friend Jupyter Notebook. Okay, so let's
see. Let's say we define a function define
2841
05:31:17,140 --> 05:31:26,280
Brent grant message, let's say, edit receives
an argument message. And this argument is
2842
05:31:26,280 --> 05:31:35,400
just a variable, it's just a variable. And
let's say we say okay, print message or further,
2843
05:31:35,400 --> 05:31:47,780
let's say you say, if is in stance message
spraying, if this is spraying, then simply
2844
05:31:47,780 --> 05:32:18,730
then simply branded. If this is not a string,
then just say okay, brand, your input argument
2845
05:32:18,730 --> 05:32:34,522
is not a string. And then you say, Okay, here
is what you have, slide. And then you say,
2846
05:32:34,522 --> 05:32:42,840
okay, whatever you have slide, just see, okay,
message. And that's it, that's it, that's
2847
05:32:42,840 --> 05:32:56,550
the function, we might have written a document
screen for it. The function rents the message
2848
05:32:56,550 --> 05:33:17,442
supplied by the user, or brains, that message
is not in the form of strength. While Don't
2849
05:33:17,442 --> 05:33:22,300
worry, we have to see the strings in detail,
we will see the sprint function in detail
2850
05:33:22,300 --> 05:33:28,420
as well, because the sprint has a lot of lot
to do with strings. So so just for now, I
2851
05:33:28,420 --> 05:33:35,800
mean, that's our function print message, let's
say if the message is of string type, this
2852
05:33:35,800 --> 05:33:39,950
string does not good, this is this should
be simply str this should not be that is instant
2853
05:33:39,950 --> 05:33:46,400
steak like this, your input argument is not
a string here is what you have supplied. Here
2854
05:33:46,400 --> 05:33:56,970
is what you have. So here, we can, we can
say here is here is here is the type
2855
05:33:56,970 --> 05:33:59,708
of what
2856
05:33:59,708 --> 05:34:12,310
you have supplied. And then we can just print
the Type, Type MSC. So the goal here is to
2857
05:34:12,310 --> 05:34:18,910
just create a function that prints a message
if that message is in plain string form. If
2858
05:34:18,910 --> 05:34:25,022
it is not a string, then it prints that okay,
you're the whatever you have signed is not
2859
05:34:25,022 --> 05:34:29,320
a string, it is not a proper message in string
form. Let's say this print message function
2860
05:34:29,320 --> 05:34:36,270
receives a string, let's say that's our logic
or something. So let's run this. First of
2861
05:34:36,270 --> 05:34:46,510
all, let's see what it does help rent message.
So the function prints the message supplied
2862
05:34:46,510 --> 05:34:57,452
by the user. We can access the same help by
question mark if you want and it gives us
2863
05:34:57,452 --> 05:35:03,360
the document string If however, we want The
implementation as well, then we write readable
2864
05:35:03,360 --> 05:35:10,410
code and implementation is also available.
While grade Python is really great. Okay,
2865
05:35:10,410 --> 05:35:22,640
let's call this function. Let's call this
function, Brent, message. And whatever you
2866
05:35:22,640 --> 05:35:31,010
want to print, let's say, this is the message.
This is the message, let's say you want to
2867
05:35:31,010 --> 05:35:36,628
print this. And this is the message that's
printed. Okay, now, let's say you call this
2868
05:35:36,628 --> 05:35:43,550
function again some time, and you supply 23.
And it will say your input argument is not
2869
05:35:43,550 --> 05:35:51,910
a string, here is the type of what you have
supplied, it's an integer type rate, you can
2870
05:35:51,910 --> 05:35:55,690
you can have, you can have, you can call this
function in the following way, let's say you
2871
05:35:55,690 --> 05:35:59,020
define a variable y, and the variable y contains
2872
05:35:59,020 --> 05:36:00,570
Hello.
2873
05:36:00,570 --> 05:36:03,690
Hello there.
2874
05:36:03,690 --> 05:36:16,030
That's it, that's your, and then you called,
then you call this function on y. And it will
2875
05:36:16,030 --> 05:36:24,940
print hello there, because y is also a string.
Great. So that's how you can you can you can,
2876
05:36:24,940 --> 05:36:29,760
you can pass different arguments and instruct
the function, how should it behave without
2877
05:36:29,760 --> 05:36:35,330
actually writing the whole logic of the task
again, and again, if written all the logic,
2878
05:36:35,330 --> 05:36:40,300
once, actually, this is actually the logic
starts from here. That's what the task is
2879
05:36:40,300 --> 05:36:44,900
to, that's what the task you want to perform.
And you need not write this again. And again,
2880
05:36:44,900 --> 05:36:49,880
whenever you need this kind of stuff, you
just call that function supplied arguments,
2881
05:36:49,880 --> 05:36:58,250
and it will behave accordingly you want. Great.
So you might be thinking, the function only
2882
05:36:58,250 --> 05:37:03,942
receives one argument, maybe we want to supply
more than one arguments, maybe, maybe two
2883
05:37:03,942 --> 05:37:08,692
arguments, maybe three, maybe four, maybe
five, and maybe we want to supply several
2884
05:37:08,692 --> 05:37:15,878
arguments. And we want to do some task based
on the values of those arguments, or those
2885
05:37:15,878 --> 05:37:23,361
variables. So in the next video, I'm going
to show you multiple arguments. Okay. Hope
2886
05:37:23,361 --> 05:37:29,410
to see you in the next video. So in the previous
video, we saw we can define a function, and
2887
05:37:29,410 --> 05:37:34,200
we can supply input argument to it. And in
this video, we are going to see that we can
2888
05:37:34,200 --> 05:37:40,410
actually send more than one arguments to the
function these arguments are just variables,
2889
05:37:40,410 --> 05:37:44,591
these are just variables, whatever value we
will supply to these dynamically, because
2890
05:37:44,591 --> 05:37:50,630
Python is dynamic dynamically typed dynamically
they are type will be defined. And for example,
2891
05:37:50,630 --> 05:37:56,542
here we have supplied just two variables,
and we just printed them, but based based
2892
05:37:56,542 --> 05:38:03,310
on supplying more than one input arguments,
and based on what logic we are going to perform,
2893
05:38:03,310 --> 05:38:12,420
we can do anything, we can do anything. So
guess by thumbs, allows us to supply multiple
2894
05:38:12,420 --> 05:38:20,070
input arguments to a function and and we can,
we can just perform all the tasks according
2895
05:38:20,070 --> 05:38:25,400
to whatever logic we are going to do with
that. So let's go to our friend Jupyter Notebook
2896
05:38:25,400 --> 05:38:34,900
and see an example of a function with multiple
input arguments. Let's say the function the
2897
05:38:34,900 --> 05:38:45,042
B define a function, let's say, my power,
let's say, my power, my power, let's say,
2898
05:38:45,042 --> 05:38:49,960
you remember there is a POW function in in
Python that's a built in function. I'm going
2899
05:38:49,960 --> 05:39:06,780
to write my own function, let's say it contains
a and b. Well, document string. My, this function
2900
05:39:06,780 --> 05:39:09,300
computes
2901
05:39:09,300 --> 05:39:11,830
power
2902
05:39:11,830 --> 05:39:22,400
just like built built in power function. Great.
That's the document screen. Okay. Now what
2903
05:39:22,400 --> 05:39:29,960
we want to do is we want to print Okay, let's
let's, let's create another variable, see,
2904
05:39:29,960 --> 05:39:39,030
that is a power B. Okay, then we print this
C, and we are done. That's it. That's our
2905
05:39:39,030 --> 05:39:46,430
goal. So we register that function by just
just calling the job by just pressing the
2906
05:39:46,430 --> 05:39:55,570
shift enter in Jupyter Notebook. And now we
check what this function does. Well, this
2907
05:39:55,570 --> 05:40:01,000
function can be horsepower, just like built
in power function. Okay, just to Just to remind
2908
05:40:01,000 --> 05:40:05,870
you again and again, the importance of document
strength, I'm writing this again and again,
2909
05:40:05,870 --> 05:40:15,400
let's run this function, my power, let's say
three ways to recover for illness. So the
2910
05:40:15,400 --> 05:40:22,500
result is 81. Oh my god. So whenever, by the
way, if you don't have POW function with you,
2911
05:40:22,500 --> 05:40:27,020
although you have, you can you can create
your function and whenever you want to use,
2912
05:40:27,020 --> 05:40:38,270
you can use your function, not a big deal.
By the way, what if you? What if you What
2913
05:40:38,270 --> 05:40:45,070
if, let's say, you can, you can define a function
with more than two arguments to find, let's
2914
05:40:45,070 --> 05:40:56,310
say, display types. That's it, that's your
function display types. And all you know,
2915
05:40:56,310 --> 05:41:06,080
is our check arguments, let's say, check our
x. That's it, that's your function, and A,
2916
05:41:06,080 --> 05:41:13,860
B, C, D, let's say E, these are the input
arguments. And let's say, at some tasks, you
2917
05:41:13,860 --> 05:41:19,192
want to know whether all the five variables
that you're working in somewhere, whether
2918
05:41:19,192 --> 05:41:24,850
all of them are numeric values or not. If
they're not numeric values, you're not moving
2919
05:41:24,850 --> 05:41:30,050
on, and you're doing something because you
were extra, let's say you're, let's say you're
2920
05:41:30,050 --> 05:41:35,240
taking input from somewhere reading from a
file or whatever. And you need to, you need
2921
05:41:35,240 --> 05:41:41,260
to check before moving on whether A, B, C,
D, and E, whether they are in sore floats.
2922
05:41:41,260 --> 05:41:47,730
Otherwise, if if if any of them is not into
float, then you're not processing, then you're
2923
05:41:47,730 --> 05:41:52,531
not moving on, and you're going to check the
input arguments again, and so on. These kind
2924
05:41:52,531 --> 05:41:57,340
of functions are there because whenever you
call certain, whenever you want to do processing
2925
05:41:57,340 --> 05:42:01,430
on data, sometimes it is required to check
the type of the data whether the data is supplied
2926
05:42:01,430 --> 05:42:07,930
in a way that you were expecting and so on.
So let's have this function check Oryx. I'm
2927
05:42:07,930 --> 05:42:12,240
not writing document string here, I guess,
I've told you enough to write document string
2928
05:42:12,240 --> 05:42:30,350
again and again. So let's see. If is instance.
A, if is instance int float? If that is true?
2929
05:42:30,350 --> 05:42:40,940
And
2930
05:42:40,940 --> 05:42:49,490
is it let's just have three variables just
to just to focus on if is instance, a then
2931
05:42:49,490 --> 05:43:07,670
B. and
is instance see if all of them are? If all
2932
05:43:07,670 --> 05:43:20,910
of them are? If all of them are integers or
floats, then do something then let's say Brent,
2933
05:43:20,910 --> 05:43:32,690
a plus b, plus C, maybe, or a plus b plus
c, raised to the power to just print their
2934
05:43:32,690 --> 05:43:42,193
square, let's say else are if they are if
they are all integers or floats, then do some
2935
05:43:42,193 --> 05:43:52,250
interesting task here some task. Otherwise,
you can say okay, print,
2936
05:43:52,250 --> 05:44:11,282
air. The input arguments are not of the expected.
But it's fine. You have this function, let's
2937
05:44:11,282 --> 05:44:15,430
say, let's call this function.
2938
05:44:15,430 --> 05:44:25,290
The function was check arcs. So let's check
arcs, check. arcs, check arcs, let's say three,
2939
05:44:25,290 --> 05:44:35,440
four, or five. So now you have all of them
are great. Let's say you have jet arcs. And
2940
05:44:35,440 --> 05:44:38,570
you call this check ARDS.
2941
05:44:38,570 --> 05:44:41,010
On,
2942
05:44:41,010 --> 05:44:51,850
let's say, three, four, but this five is a
string, let's say, Gee. Now we'll be having
2943
05:44:51,850 --> 05:44:57,458
an error. The input arguments are not all
of the expected types. One of them or more
2944
05:44:57,458 --> 05:45:06,780
of them or whatever. Yeah one more thing the
this function is expecting three arguments
2945
05:45:06,780 --> 05:45:12,800
if you call this function by less than three
or more than three arguments you'll be getting
2946
05:45:12,800 --> 05:45:18,780
an error for example three four although this
function is accepting three arguments, you're
2947
05:45:18,780 --> 05:45:23,550
calling it with just two you're getting an
error because you have not specified all the
2948
05:45:23,550 --> 05:45:28,420
arguments that the function is requiring although
the the arguments that you have supplied they
2949
05:45:28,420 --> 05:45:33,840
are of the type that it is expecting, but
you have not supplied the the number of arguments
2950
05:45:33,840 --> 05:45:41,872
that the function is expecting. Similarly,
if you call this function by more than three
2951
05:45:41,872 --> 05:45:46,628
arguments, although it requires three arguments,
you again will get an error, because it is
2952
05:45:46,628 --> 05:45:55,840
expecting three arguments and you have not
supplied three arguments. later on. In later
2953
05:45:55,840 --> 05:46:02,610
on, we will see how to write a function that
accepts a variable number of arguments, we
2954
05:46:02,610 --> 05:46:06,820
will see that but right now, in this particular
way, if you write the function, if you define
2955
05:46:06,820 --> 05:46:13,850
the function in this particular way, you have
to define the arguments the number of whatever
2956
05:46:13,850 --> 05:46:18,790
the number of arguments it is expecting, you
have to supply exactly as many. Otherwise
2957
05:46:18,790 --> 05:46:28,250
you are getting an error. Okay, so that's
about the multiple arguments. Okay, what next?
2958
05:46:28,250 --> 05:46:37,000
Well, next time, in the next video, we will
see that what is the what's the importance
2959
05:46:37,000 --> 05:46:43,470
of order of these input arguments? What will
happen if I just swapped message to win message
2960
05:46:43,470 --> 05:46:50,530
one? Will that will that change the behavior?
Or is there any order? With the first mess?
2961
05:46:50,530 --> 05:46:54,690
The first variable, the second variable, third
variable? Is there any ordering inside the
2962
05:46:54,690 --> 05:47:01,090
input arguments? Yeah, there is. So let's
see in the next video, in the last video,
2963
05:47:01,090 --> 05:47:07,220
we saw, how can we pass multiple How can we
define a function with more than one input
2964
05:47:07,220 --> 05:47:12,520
arguments, it is important to know that the
order of the input argument is really, really
2965
05:47:12,520 --> 05:47:18,500
important. So whatever argument at the call
time, for example, if you call this particular
2966
05:47:18,500 --> 05:47:23,000
function, the name of the function is f, that's
not a great name, you should have a name that
2967
05:47:23,000 --> 05:47:30,590
a descriptive but I recommend write good names,
let's say this is f, that's a function and
2968
05:47:30,590 --> 05:47:36,610
the very first variable is C to the second
variable c one, the third variable is C three.
2969
05:47:36,610 --> 05:47:43,770
Now you let's say call this function like
like this, let's say two, four and nine, what
2970
05:47:43,770 --> 05:47:50,470
will happen is this too will be copied in
C two, this four will be copied in this C
2971
05:47:50,470 --> 05:47:59,070
one and this nine will be copied in this C
three. Now, C two has a value two, c one has
2972
05:47:59,070 --> 05:48:06,420
a value four and C three has a value of nine.
If you change the symbols or the variables
2973
05:48:06,420 --> 05:48:12,660
order here, whatever order you have written
there, the first value that is passed at the
2974
05:48:12,660 --> 05:48:18,390
call time will be passed to the first variable
whatever the name of the first variable is,
2975
05:48:18,390 --> 05:48:25,120
the second value at the call time is copied
in the second symbol, whatever the name of
2976
05:48:25,120 --> 05:48:33,320
the symbol is. So, this ordering is really
really important. One way to work one workaround
2977
05:48:33,320 --> 05:48:39,612
for this is at the call time, you actually
define the variable names and their values.
2978
05:48:39,612 --> 05:48:46,260
For example, you call you call F and you say
okay c one has this particular value, but
2979
05:48:46,260 --> 05:48:53,090
this way you need to know that there is the
symbol name in definition is exactly c one.
2980
05:48:53,090 --> 05:49:00,280
So, C one has this value, C two has this value,
C three has this value, once you at the call
2981
05:49:00,280 --> 05:49:06,730
time, if you have defined your variable names
along with their values, then you are order
2982
05:49:06,730 --> 05:49:15,170
free. Now you change whatever whatever if
for example, you call this way c two is b,
2983
05:49:15,170 --> 05:49:24,420
c one is a now no matter in what order you
have called these,
2984
05:49:24,420 --> 05:49:31,700
this C one is going to be copied in C one,
the C two is going to be copied in C two and
2985
05:49:31,700 --> 05:49:38,000
C three is going to be copied in C three for
the functions that has many more arguments,
2986
05:49:38,000 --> 05:49:43,622
it is it is good to it is good to call the
function in this particular way. If there
2987
05:49:43,622 --> 05:49:50,350
is a chance that calling a function in a different
order may may may become confusing and stuff
2988
05:49:50,350 --> 05:49:57,530
like so. This actually gives you more grip
on this ordering issue. if if if you're if
2989
05:49:57,530 --> 05:50:02,270
you're happy with if you're very smart and
When you say Ok, I will always supply in a
2990
05:50:02,270 --> 05:50:07,850
particular order, I will always read the document
string first, and then I will call that function,
2991
05:50:07,850 --> 05:50:13,112
that's okay. Otherwise, this is also a feature
that is available at the call time, you assign
2992
05:50:13,112 --> 05:50:19,150
the values of the functions that are there
at the definition time. And now no matter
2993
05:50:19,150 --> 05:50:23,780
in what order you are calling that function,
see one occurs at third position c two occurs
2994
05:50:23,780 --> 05:50:30,670
at first position, the relative values will
be copied according to their names. So and
2995
05:50:30,670 --> 05:50:34,910
that's a good feature. That's a very good
feature. Let's see, for example, a running
2996
05:50:34,910 --> 05:50:43,020
example of this in Python. In Jupyter, notebook,
okay, define, let's say function f, let's
2997
05:50:43,020 --> 05:50:55,192
say it receives a, b, and c, let's say three
values. And let's say prints. A, is that's
2998
05:50:55,192 --> 05:51:15,971
it, Sprint, a, is a. And you'll say okay,
B is B. And then it prints Okay. See, C, C
2999
05:51:15,971 --> 05:51:25,170
is, whatever the value of c is, that's the
C, okay? Now, let's call this function f,
3000
05:51:25,170 --> 05:51:36,220
with, let's say, two, three, and game. So,
they will say, okay, a is to B is three, C
3001
05:51:36,220 --> 05:51:45,480
is game, fine, great. Now, this tool will
be copied in a no matter what if we if we
3002
05:51:45,480 --> 05:51:51,772
change this, if we change this calling order,
for example, if we if we change this order,
3003
05:51:51,772 --> 05:52:00,900
we just we just moved to we just moved to
this particular order, we just say okay, this
3004
05:52:00,900 --> 05:52:11,920
is three, this is game, this is to be called
like, so now three will be copied in a game
3005
05:52:11,920 --> 05:52:19,900
will be copied in B and two will be competency.
And that, if if if that is the behavior you
3006
05:52:19,900 --> 05:52:24,830
want, then you are good to go. Otherwise,
it is it is handy to call the function in
3007
05:52:24,830 --> 05:52:40,378
the following ways just fix, okay, a is a
is to fine. B is three. And C is let's say
3008
05:52:40,378 --> 05:52:45,650
again, if you want these numbers, now, if
you call a function like so, that will happen.
3009
05:52:45,650 --> 05:52:53,602
Now, if you change the order, no matter what
order of add the calling time you come up
3010
05:52:53,602 --> 05:53:02,670
with, it will stay the same. For example,
you go and say okay, C is at the first position.
3011
05:53:02,670 --> 05:53:10,050
And a is at the second position, let's say
two, and B is at the third position three,
3012
05:53:10,050 --> 05:53:15,000
the output will stay the same. And that's
a, that's a beautiful, that's a beautiful
3013
05:53:15,000 --> 05:53:23,550
thing. So that's one way of handling with
the order. If you if if you think at call
3014
05:53:23,550 --> 05:53:29,010
time it is important to define the variable
names, but it has one problem that you need
3015
05:53:29,010 --> 05:53:35,350
to know you need to know exact variable names.
If the variable name is C one there, you need
3016
05:53:35,350 --> 05:53:41,830
to know what it's see one, you need not to
I mean the C one matches with C it must match
3017
05:53:41,830 --> 05:53:49,220
with C one, C two must match with C two and
so on. So you need to know these names. Okay,
3018
05:53:49,220 --> 05:53:57,340
great. In the upcoming videos, more features
of functions are are going to are going to
3019
05:53:57,340 --> 05:54:03,400
be discussed. So stay with us hope to see
you in the next video. So we in the last video,
3020
05:54:03,400 --> 05:54:09,852
we saw the ordering of input arguments in
a function.
3021
05:54:09,852 --> 05:54:15,708
And we saw a fix to it. I mean, if you if
you if there is a chance that you may miss
3022
05:54:15,708 --> 05:54:21,150
a proper order, there is a way to fix that
we saw that in the last video. Here, we have
3023
05:54:21,150 --> 05:54:29,700
another another thing to discuss this x variable
x input argument This is the variable that
3024
05:54:29,700 --> 05:54:35,950
is defined inside a function although the
value it receives is copied from somewhere
3025
05:54:35,950 --> 05:54:40,180
else, but it is defined inside the function
that is also the function variable or the
3026
05:54:40,180 --> 05:54:44,490
or the variable that is in the scope of the
function inside the function in the body of
3027
05:54:44,490 --> 05:54:50,362
the function something like so it may be handy.
For example, let's say you want you you compute
3028
05:54:50,362 --> 05:54:56,270
something you do some processing on your inputs.
And whatever the result is you save that result
3029
05:54:56,270 --> 05:55:01,590
in another variable. And let's say now you
need the value of this variable. to do some
3030
05:55:01,590 --> 05:55:06,702
further process, let's say, what you do is
let's say in a call time, that's let's say
3031
05:55:06,702 --> 05:55:11,020
this is the this of the function and say,
This is the complete function. And let's say
3032
05:55:11,020 --> 05:55:18,401
a is equal to 12. And B is equal to, let's
say seven. And let's say you call the function
3033
05:55:18,401 --> 05:55:26,060
add a, b, now the value of a will be copied
in x, the value of d will be copied in Y,
3034
05:55:26,060 --> 05:55:35,010
okay, and now, you need the Sum of a and b,
to be received here, in a variable, you want
3035
05:55:35,010 --> 05:55:40,800
a variable in which the results should be
saved. For example, let's say a variable is
3036
05:55:40,800 --> 05:55:50,200
D, let's say, and then you want to do some
more processing on D, let's say d doublestar
3037
05:55:50,200 --> 05:55:58,840
five, mod three, and maybe you need to apply
an if condition on that if that equals to
3038
05:55:58,840 --> 05:56:05,700
zero, then do some stuff otherwise, so let's
say you need this variable out, what will
3039
05:56:05,700 --> 05:56:11,760
happen is this C variable is not accessible
outside this function. And the reason is the
3040
05:56:11,760 --> 05:56:16,280
C is defined inside the function when the
function body completes its execution, the
3041
05:56:16,280 --> 05:56:23,612
C is lost sees no more available, C is defined
when the function call has been made, when
3042
05:56:23,612 --> 05:56:31,180
the when when you're executing the statement
C is defined and a memory location was created
3043
05:56:31,180 --> 05:56:36,880
in a C sometimes called the function space
in the memory or process space that is created
3044
05:56:36,880 --> 05:56:42,020
in memory. But once all the body of the function
executes all the functions that were inside
3045
05:56:42,020 --> 05:56:48,740
the variable they are lost, what how can you
How can you receive this value? How can you
3046
05:56:48,740 --> 05:56:56,330
receive the value inside see outside this
function? So, that is, that is question in
3047
05:56:56,330 --> 05:57:00,840
this slide, how can we do that further,
3048
05:57:00,840 --> 05:57:08,730
this particular function can access all the
variables that are not defined in this function,
3049
05:57:08,730 --> 05:57:13,810
but that are available outside this function
and are defined already. For example, let's
3050
05:57:13,810 --> 05:57:22,128
say I have a function, f. And the function
is let's say I have a function f. And so if
3051
05:57:22,128 --> 05:57:27,530
this function is defined, like so f, let's
say F is your function, and it has to find
3052
05:57:27,530 --> 05:57:36,730
like D, E, F, and that's it. And here it prints
let's say, some variable, let's say a. Let's
3053
05:57:36,730 --> 05:57:43,570
now now you know this a variable is no longer
in F not even defined in F, but as long as
3054
05:57:43,570 --> 05:57:49,900
this a variable is defined, before calling
F for example, that's the cell where we are
3055
05:57:49,900 --> 05:57:56,230
writing the code and we say okay, a is equal
to seven, and then we just call this F, because
3056
05:57:56,230 --> 05:58:03,500
a was available before calling f a will is
accessible here. So, the functions the variables
3057
05:58:03,500 --> 05:58:10,570
that are available before the call, they are
available inside the functions, but the variables
3058
05:58:10,570 --> 05:58:16,310
that are defined inside the functions, they
are not available outside. That's the problem
3059
05:58:16,310 --> 05:58:22,390
further, if we define this ad here is equal
to two now, this a is sometimes called the
3060
05:58:22,390 --> 05:58:28,010
local variable or the function where the variable
there is local to the function. Now, this
3061
05:58:28,010 --> 05:58:35,340
a is is is defined inside the function and
all the accesses to a will access this value
3062
05:58:35,340 --> 05:58:40,910
to rather than the sound considered sound
has a separate location in memory, and this
3063
05:58:40,910 --> 05:58:46,520
too has a separate location and memory, both
have names a, but this a will only be referred
3064
05:58:46,520 --> 05:58:53,022
to when the function is executing, after the
after the execution of the function completes
3065
05:58:53,022 --> 05:58:57,980
this has gone from the from the memory and
this will still be available, the seven will
3066
05:58:57,980 --> 05:59:04,628
still be available. So it is good to know
and by the way, if a was not defined here,
3067
05:59:04,628 --> 05:59:10,040
and you still call F, then either you will
be getting an error, or this a might be a
3068
05:59:10,040 --> 05:59:15,000
global variable or available in some package
that you have already loaded or stuff like
3069
05:59:15,000 --> 05:59:20,750
so, in that case, this eight will be accessed
if it's a global variable or accessible. So,
3070
05:59:20,750 --> 05:59:26,200
it is good to know the the scope of the variables
inside the function because when you're calling
3071
05:59:26,200 --> 05:59:33,430
them what functions if this if x is already
defined, for example, if x is already defined
3072
05:59:33,430 --> 05:59:42,050
like 34 and then this x is 34, as long as
this x is not defined here, if x is defined
3073
05:59:42,050 --> 05:59:46,628
here, this is this x actually is the local
copy and that will be accessed inside the
3074
05:59:46,628 --> 05:59:52,480
function. Once the function is gone again
x will be 34. So, it is good to know the local
3075
05:59:52,480 --> 05:59:59,230
copies or or the function space itself. The
but but the problem here is how to access
3076
05:59:59,230 --> 06:00:03,820
them. This variable the value of this variable
outside the function, because this is completely
3077
06:00:03,820 --> 06:00:06,580
defined inside
3078
06:00:06,580 --> 06:00:13,970
how to access that? Well, well, there is a
fix, and that fix is called the return statement.
3079
06:00:13,970 --> 06:00:20,450
If you write the return statement, for example,
you return this value. So x plus y, you might
3080
06:00:20,450 --> 06:00:25,720
have saved these values, you might have saved
these values, for example, C equals x plus
3081
06:00:25,720 --> 06:00:32,030
y, that's okay. And then you say, okay, return,
see, what will happen is wherever you have
3082
06:00:32,030 --> 06:00:40,580
called this function, d equals add, let's
do three. Now, this value, this value C, which
3083
06:00:40,580 --> 06:00:46,290
in this particular case is five, that value
will be returned in D, and all the properties
3084
06:00:46,290 --> 06:00:52,890
of this variables are returned in D. So just
like the C is copied in D, and this is available
3085
06:00:52,890 --> 06:00:59,780
further, whatever you want to do with this
D. Okay, so yeah, so return statement is there.
3086
06:00:59,780 --> 06:01:05,970
So, in the next video, we will actually code
this in Jupyter Notebook and see the return
3087
06:01:05,970 --> 06:01:10,560
statement running and we will see the scope
of the variables and all that in Jupyter Notebook.
3088
06:01:10,560 --> 06:01:18,060
So hope to see you in the next video. In the
last video, we saw a scope of a variable particularly
3089
06:01:18,060 --> 06:01:24,720
if a function if a variable is defined inside
a function, is it accessible outside the function
3090
06:01:24,720 --> 06:01:31,090
and if a variable is defined outside the function,
is it accessible inside the function and vice
3091
06:01:31,090 --> 06:01:35,180
versa? and so on. So we discussed those kinds
of things, which is sometimes called school
3092
06:01:35,180 --> 06:01:41,640
scope of a variable. And further, we discussed
what if we want, what if we want a value of
3093
06:01:41,640 --> 06:01:46,640
the function that is computed value value
of some variable or some result that is computed
3094
06:01:46,640 --> 06:01:52,970
inside a function? What if we want that to
be accessed outside, outside the function?
3095
06:01:52,970 --> 06:01:59,180
So we discussed that in detail in the last
video, so let's see all those concepts in
3096
06:01:59,180 --> 06:02:08,720
a running form in Jupyter. notebook. So let's
see how it works. So first of all, let's define
3097
06:02:08,720 --> 06:02:18,520
variables, let's define a function, let's
say define, let's say, my ad. And let's say
3098
06:02:18,520 --> 06:02:29,490
it receives two arguments, let's say a and
b. And then let's say C is a plus b, let's
3099
06:02:29,490 --> 06:02:39,780
say that C are our c value, that's a c value
or some value, whatever, whatever you want
3100
06:02:39,780 --> 06:02:46,350
to call that value, some value. That's it.
Let's say we did, we did that. Now we want
3101
06:02:46,350 --> 06:02:58,300
to access that some value from outside the
function. paint some value. By the way, let's
3102
06:02:58,300 --> 06:03:06,020
first call this function, let's say my app,
add four values, let's say two, three. So
3103
06:03:06,020 --> 06:03:13,770
two will be copied in a three will be copied
in B. So then, let's access let's try to access
3104
06:03:13,770 --> 06:03:21,170
this value, some value, it will throw an error.
And the reason is this variable, some value
3105
06:03:21,170 --> 06:03:25,980
is not accessible outside this function. What
if we want to access because this is defined
3106
06:03:25,980 --> 06:03:32,331
inside the function? What if we want to access
this? I mean, what if we want to compute some
3107
06:03:32,331 --> 06:03:37,690
result and then use that result outside the
function? So the way out, as discussed in
3108
06:03:37,690 --> 06:03:46,590
the last video is return statement. Return
Value. And now if we call that again, let
3109
06:03:46,590 --> 06:03:55,032
me let me go if we call that again. Now, what
we haven't actually registered, by the way,
3110
06:03:55,032 --> 06:04:00,520
remember this, that's, that's a common error
I got in that era, a lot of a lot many times.
3111
06:04:00,520 --> 06:04:05,400
If you change the implementation of the function,
you have to rerun that cell, you have to register
3112
06:04:05,400 --> 06:04:11,990
the updated copy of the function to the Python,
otherwise, you will be getting errors. Probably,
3113
06:04:11,990 --> 06:04:18,870
yeah. What's the problem here? Now, when somebody
Oh, we, oh, there's somebody is still not
3114
06:04:18,870 --> 06:04:24,190
still not accessible. Because some value is
not is not accessible it is it is a variable
3115
06:04:24,190 --> 06:04:29,872
defined inside the function it is scope in,
its the scope of this variable, is just the
3116
06:04:29,872 --> 06:04:38,810
body of the function. So let's receive this
output in a variable D. And then let's just
3117
06:04:38,810 --> 06:04:49,708
print D and D is five. Great. So one more
thing. Let's say we define a variable here,
3118
06:04:49,708 --> 06:04:58,128
of variable outside the function, let's say
that's a label name. That's a very lengthy
3119
06:04:58,128 --> 06:05:02,300
name, but let's say that's the name variable.
Well outside the function that saves value
3120
06:05:02,300 --> 06:05:07,260
is three. And then
3121
06:05:07,260 --> 06:05:14,470
then let's define another function somewhere.
Let's see, let's define another function down
3122
06:05:14,470 --> 06:05:29,100
somewhere, let's say define F, maybe G, and
it receives nothing, but it prints this, that's
3123
06:05:29,100 --> 06:05:37,940
a variable. out side the function. And that's
it. That's it, that's a function. Now, when
3124
06:05:37,940 --> 06:05:44,010
we call this function, this variable outside
the function that is accessible inside the
3125
06:05:44,010 --> 06:05:52,720
function. So so and and, and if this function,
and if this variable is not defined inside
3126
06:05:52,720 --> 06:05:57,540
here, and if there is this is defined somewhere
else, and it is global or accessible, it will
3127
06:05:57,540 --> 06:06:06,920
still be accessible. However, if we define
a function with the same name, let's say variable,
3128
06:06:06,920 --> 06:06:15,390
outside, outside the function, let's say five,
now, this function will print five, if we
3129
06:06:15,390 --> 06:06:20,220
because that's the local variable, that's
the local variable in the function. Now, this
3130
06:06:20,220 --> 06:06:28,208
will be accessed in this print statement.
Let's see. Now the result will be five. But
3131
06:06:28,208 --> 06:06:39,420
if you print the variable outside, now the
value will be three, because this variable,
3132
06:06:39,420 --> 06:06:43,910
this particular variable that was inside the
function, it got destroyed when the function
3133
06:06:43,910 --> 06:06:51,630
finishes. And this is available again. So
yeah, so you need to know, by the way, it's
3134
06:06:51,630 --> 06:06:57,260
a good practice whenever you want to, whenever
you want to access a particular variable inside,
3135
06:06:57,260 --> 06:07:02,720
it is a good practice to pass that variable
as input argument to minimize the confusions
3136
06:07:02,720 --> 06:07:07,570
because this can create a lot of confusions.
So it's a good practice, although the feature
3137
06:07:07,570 --> 06:07:14,720
is available and sometimes useful as well.
But it is always recommended to pass the values
3138
06:07:14,720 --> 06:07:20,830
as input arguments that whatever you want
to access inside the function. Okay, so one
3139
06:07:20,830 --> 06:07:29,600
more thing, this, this function g is returning
nothing. For example, it is not returning
3140
06:07:29,600 --> 06:07:34,750
anything, it is just printing, let's say something,
let's say it is not printing anything, let's
3141
06:07:34,750 --> 06:07:40,250
say, let's say this is a comment, let's say
it is not printing anything. So this, and
3142
06:07:40,250 --> 06:07:47,372
then we call this and that's it. So it has
no return value. By the way, in Python, even
3143
06:07:47,372 --> 06:07:53,970
if you even if any function, even if a function
does not return anything, it still returns
3144
06:07:53,970 --> 06:08:00,550
a value, which is called none, which you can
see here. So in Python, a function always
3145
06:08:00,550 --> 06:08:07,780
returns a value. If you write a return statement
explicitly, it returns that if you do not
3146
06:08:07,780 --> 06:08:14,122
write return statement, when the function
body finishes, it automatically returns none.
3147
06:08:14,122 --> 06:08:18,740
Let's see the type of this output. What is
the type of this output? What is the type
3148
06:08:18,740 --> 06:08:24,730
of this man, what kind of data type is this?
Let's see. It's an n type, I mean, that's
3149
06:08:24,730 --> 06:08:33,300
a type in Python. So downs are non type, output,
how fancy Well, one more thing, the return
3150
06:08:33,300 --> 06:08:39,430
statement is not only used to return a particular
value, if you for example, in a particular
3151
06:08:39,430 --> 06:08:47,340
function, let me write a function here. Let's
say d f, that's the function is H. And then
3152
06:08:47,340 --> 06:08:55,202
inside that function, you do something, let's
say print, a, let's say then you define a
3153
06:08:55,202 --> 06:09:02,880
variable, let's say a equals to three, let's
say, then B equals let's say five, and then
3154
06:09:02,880 --> 06:09:13,600
you add those values A and B. And then you
do some other stuff, let's say plant something.
3155
06:09:13,600 --> 06:09:19,100
And then you just write a return statement
without any output or I mean it is not returning
3156
06:09:19,100 --> 06:09:27,042
anything. You can still you can still I mean
continue writing the function body more and
3157
06:09:27,042 --> 06:09:34,250
more. But what happens is whenever the first
return will be encountered,
3158
06:09:34,250 --> 06:09:40,090
the function returns from there. So the effective
body of the function is just that the function
3159
06:09:40,090 --> 06:09:45,458
returns right from there. If you return a
particular value for example C, you can receive
3160
06:09:45,458 --> 06:09:50,690
that value outside the function. If you do
not return anything, just type a return statement.
3161
06:09:50,690 --> 06:09:57,378
That means exit the function right away. It
works like the break statement and loop. Remember
3162
06:09:57,378 --> 06:10:02,300
the break statement it It resembles to break
Excitement bulletin means just exit the function
3163
06:10:02,300 --> 06:10:08,500
right away, no problem. And by the way, when
return is called the default return value
3164
06:10:08,500 --> 06:10:13,620
that is returned is none type if the return
is called without, without an argument here,
3165
06:10:13,620 --> 06:10:23,542
so for example, let's run this function. Let's
see. And let's call that function Ah, yeah.
3166
06:10:23,542 --> 06:10:30,700
So it prints a, then it brings something and
then it returns. And it returns, for example.
3167
06:10:30,700 --> 06:10:43,640
It returns nothing but anon. It returns or
not. And if you didn't see, for example, saying,
3168
06:10:43,640 --> 06:10:44,640
then it returns
3169
06:10:44,640 --> 06:10:53,390
a C, value of C, which is eight. And this
time this type, the return value is no longer
3170
06:10:53,390 --> 06:11:03,430
none type, it is probably an integer type.
Let's see. Yeah, here. So it's indeed a type
3171
06:11:03,430 --> 06:11:09,490
Make sense? Yeah. So return statement has
two purposes, one, you can return a value,
3172
06:11:09,490 --> 06:11:15,750
two, you can return, you can just return the
control, you can just exit the function like
3173
06:11:15,750 --> 06:11:21,820
the break and loops. Just Just one more thing.
return statement can return multiple values.
3174
06:11:21,820 --> 06:11:31,420
For example, let's say we have defined a function,
let's say J. Let's say G, G, we already have
3175
06:11:31,420 --> 06:11:37,330
defined, we can redefine it. But let's say
our is our function. And we just have a equals
3176
06:11:37,330 --> 06:11:50,192
five, b equals seven, and D equals let's say
something. And then we just return them a,
3177
06:11:50,192 --> 06:11:58,810
b, and A, D, and D. So return statement can
return multiple values in a sequence. Now,
3178
06:11:58,810 --> 06:12:07,100
if you receive those values, let's say X,
Y and Z equals r, so a will be copied in a
3179
06:12:07,100 --> 06:12:14,490
is a first return value, it will be returned
in X, it will be copied in x, b will be copied
3180
06:12:14,490 --> 06:12:21,770
in y, and D will be copied in z just as a
sequence as you as you keep the sequence in
3181
06:12:21,770 --> 06:12:25,600
the return statement, if you change the sequence
and return statement accordingly. So whatever
3182
06:12:25,600 --> 06:12:29,852
the first value here is the first value here,
whatever the second value, here is the second
3183
06:12:29,852 --> 06:12:38,931
value here, and so on. So let's run this and
just print all these things X, Y, and Z. So
3184
06:12:38,931 --> 06:12:44,043
yeah, five salmon and something. So this return
statement is really powerful. I mean, it can
3185
06:12:44,043 --> 06:12:49,620
return multiple, not all the languages, actually,
not all the languages, they have feature to
3186
06:12:49,620 --> 06:12:55,280
return multiple values. But Python does have
feature to return more than one values. And
3187
06:12:55,280 --> 06:12:59,362
more than one values of any type A can have
different types, you can have different types,
3188
06:12:59,362 --> 06:13:07,230
you can have different type, and so on. So
that's about the that's about the return statement,
3189
06:13:07,230 --> 06:13:13,790
as well as the variable scope. And whether
you can access a variable that is outside
3190
06:13:13,790 --> 06:13:18,282
the function or inside the function, and so
on, and all that kind of things. In the next
3191
06:13:18,282 --> 06:13:24,600
video, we will talk about what if we want
to access arbitrary number of input arguments.
3192
06:13:24,600 --> 06:13:29,220
I mean, we do not know how many arguments
will be there inside. But no matter how many
3193
06:13:29,220 --> 06:13:33,520
arguments a particular user is giving, let's
say we want to write an add function. Just
3194
06:13:33,520 --> 06:13:37,650
Just to give you an example, let's say you
want to write an add function that says define
3195
06:13:37,650 --> 06:13:46,000
add that say add to another function, add
two. Let's say it receives an arbitrary number
3196
06:13:46,000 --> 06:13:53,550
of arguments. D in I don't know how many and
it has some implementation, then anybody who
3197
06:13:53,550 --> 06:14:00,950
wants to call this add to it, if that person
gives two or two arguments, then just two
3198
06:14:00,950 --> 06:14:05,362
should be added. If the person gives three
arguments, then three should be added. I mean,
3199
06:14:05,362 --> 06:14:11,430
the person can give arbitrary number of arguments.
How can we handle that because because the
3200
06:14:11,430 --> 06:14:17,300
caller the this is the call, this is the call,
the caller can give five arguments, six arguments,
3201
06:14:17,300 --> 06:14:21,550
seven arguments. And earlier we saw in the
definition, the total number of variables
3202
06:14:21,550 --> 06:14:27,690
when we specify, we have to pass those many
arguments for sure. If a single argument is
3203
06:14:27,690 --> 06:14:32,170
missing, or a single argument is just more
than the specified number of variables, we
3204
06:14:32,170 --> 06:14:36,860
will be getting an error. But how can we handle
the situation where we have an arbitrary or
3205
06:14:36,860 --> 06:14:44,810
variable number of input arguments? How can
we handle that? So to answer this, or to get,
3206
06:14:44,810 --> 06:14:50,830
how can we do that? See our next video? It's
coming. In the last video we were talking
3207
06:14:50,830 --> 06:14:56,780
about how can we handle arbitrary number of
input arguments. For example, let's let's
3208
06:14:56,780 --> 06:15:02,660
say we want to write an add function. That
should be a To add any number of let's say
3209
06:15:02,660 --> 06:15:08,760
integer or floating point numbers that are
passed in. Remember last time, we discussed
3210
06:15:08,760 --> 06:15:13,930
in an earlier video, that when you are defining
a function, the total number of variables
3211
06:15:13,930 --> 06:15:18,850
that you are defining, you have to pause exactly
those many input arguments. Otherwise, you're
3212
06:15:18,850 --> 06:15:24,960
getting an error. But but this may be required
some time that we want to add a universal
3213
06:15:24,960 --> 06:15:30,940
kind of add function that has that has capacity
to receive any number of arguments. But no
3214
06:15:30,940 --> 06:15:36,379
matter how many arguments it receives, it,
just add them all and return the result. Such
3215
06:15:36,379 --> 06:15:41,370
a function, if available will be very, very
helpful. Because sometimes we might be calling
3216
06:15:41,370 --> 06:15:47,340
that function by just two arguments. Sometimes
we might be adding might be calling that function
3217
06:15:47,340 --> 06:15:48,940
with, let's say,
3218
06:15:48,940 --> 06:15:56,080
three arguments, and sometimes more arguments
or less arguments and so on. How can we have
3219
06:15:56,080 --> 06:16:03,080
this kind of feature available, but the implementation
is just one time implementation? Well, Python
3220
06:16:03,080 --> 06:16:09,270
have a very, very easy way of handling this
arbitrary or variable number of inputs. And
3221
06:16:09,270 --> 06:16:13,820
the way you do that is when you receive when
you are defining a function, you just write
3222
06:16:13,820 --> 06:16:21,128
a star, and then just Brent let's say, one
variable name, let's say arcs. And then after
3223
06:16:21,128 --> 06:16:27,580
that, this arts will act like a list. And
I mean, it will be having a lot of properties
3224
06:16:27,580 --> 06:16:34,792
are this arts has a property, this this x
like list, so all the arguments that you will
3225
06:16:34,792 --> 06:16:40,958
send in will be received like, like you're
receiving those in a in one list. And all
3226
06:16:40,958 --> 06:16:46,750
elements, which are the arguments in the list,
they are accessed by different indices, we
3227
06:16:46,750 --> 06:16:52,460
will see lists in detail later on. But right
now just think it is a collect all the collection,
3228
06:16:52,460 --> 06:16:59,730
it is received by indices, for example, the
ARDS, the very first element is indexed by
3229
06:16:59,730 --> 06:17:06,970
zero, it is at the zero location. At the zero
location, there is a three at first location,
3230
06:17:06,970 --> 06:17:11,651
for example, the location index number one,
which is actually the second look, the four
3231
06:17:11,651 --> 06:17:16,980
will be copied at this and so on. Now, no
matter how many arguments you pass a list,
3232
06:17:16,980 --> 06:17:23,680
it will be of that size, and there is a function
length le n that is handy to just check how
3233
06:17:23,680 --> 06:17:28,560
many arguments are there. Now if you pass
two arguments, the arcs will, the length of
3234
06:17:28,560 --> 06:17:32,110
the arc will be two, if you have three, if
you have passed three arguments, the length
3235
06:17:32,110 --> 06:17:37,490
of the arts will be three and so on. No matter
how many arguments you pass this arcs, it
3236
06:17:37,490 --> 06:17:42,240
will receive all them in one by one and all
the elements in that arc will be indexed by
3237
06:17:42,240 --> 06:17:49,080
012, starting from zero until the length of
the arcs. So see, for example, here, they
3238
06:17:49,080 --> 06:17:56,050
said the sum sum equals zero, let's, let's
say we want to add all these for i in range.
3239
06:17:56,050 --> 06:18:01,750
And inside range, we just give the length
of arcs for this example 12345, the length
3240
06:18:01,750 --> 06:18:08,110
of arg is five. So I will start from zero
till till four, because five is not included.
3241
06:18:08,110 --> 06:18:14,440
So the very first time I will be zero, and
our eggs in subscript zero is actually the
3242
06:18:14,440 --> 06:18:20,340
value value of the first variable, which is
three, so three is added to zero, then next
3243
06:18:20,340 --> 06:18:26,720
time, I will be one and add the position one
four is located. So three plus equals four,
3244
06:18:26,720 --> 06:18:30,920
which means three equals three plus four,
a sum equals whatever the some previous value
3245
06:18:30,920 --> 06:18:36,650
of the sum plus for the next time, the value
of i will be four, you know how this loop
3246
06:18:36,650 --> 06:18:42,230
works, we discussed the loop and loops in
detail. And as you move on, you actually explore
3247
06:18:42,230 --> 06:18:49,870
all these numbers. And this variable sum actually
contain the sum of all the variables. Now
3248
06:18:49,870 --> 06:18:55,170
you can return the sum and that at this particular
function acts like a universal guide a function
3249
06:18:55,170 --> 06:19:01,330
that receives arbitrary number of arguments.
How cool is that? Let's see in Jupyter Notebook
3250
06:19:01,330 --> 06:19:08,480
to get more convinced how it works. So let's
say we have define, let's say we have any
3251
06:19:08,480 --> 06:19:21,020
function, my ad, they might add, let's say
that function might add powerful, that's universal
3252
06:19:21,020 --> 06:19:28,860
or universal. Universal might add universal,
and it received receives star whatever the
3253
06:19:28,860 --> 06:19:34,360
variable name is, that you can read, you can
write the name arcs or you can write any other
3254
06:19:34,360 --> 06:19:41,440
other variable limits. This is this is just
this is just a name of a variable. Okay, then
3255
06:19:41,440 --> 06:19:48,721
let's say we have let's say we have s equals
zero, which is some, then we just apply a
3256
06:19:48,721 --> 06:19:57,830
loop. I guess you know, the loops we have
lengthy discussion on loops, in range, length,
3257
06:19:57,830 --> 06:20:05,270
that's a built in function length arcs. Okay,
then what should we do s plus equals r x
3258
06:20:05,270 --> 06:20:13,690
i, which means access all the elements one
by one. And this is again the same as S is
3259
06:20:13,690 --> 06:20:21,850
equal to s plus r x i. Either way you write
this way or that way, both ways are fine.
3260
06:20:21,850 --> 06:20:27,990
Then when the loop finishes, s contains the
Psalm, just return it, and you are done. Wow.
3261
06:20:27,990 --> 06:20:34,700
Now, let's call this add function, my add
universal. And let's call this function as
3262
06:20:34,700 --> 06:20:43,470
two, four and five for these, and let's just
print the result. Let's just print the result.
3263
06:20:43,470 --> 06:20:50,620
Okay, the result is 11. Well, because two
plus four plus five is 11. Now let's call
3264
06:20:50,620 --> 06:21:02,620
this function for let's say, for for, let's
say, five arguments. It works. It adds all
3265
06:21:02,620 --> 06:21:13,620
these five numbers. Wow, that is great. I
mean, now we can add any, we have one function,
3266
06:21:13,620 --> 06:21:19,390
we need not write a function for two arguments,
and then another function for three arguments,
3267
06:21:19,390 --> 06:21:23,360
then another function for four arguments and
so on. Depending upon the number of arguments,
3268
06:21:23,360 --> 06:21:29,060
we need not to write separate functions. We
have just one function working in all scenarios.
3269
06:21:29,060 --> 06:21:38,032
While so, yeah. That's doable. I've done in
front of you. No problem. Yeah, Python allows
3270
06:21:38,032 --> 06:21:40,128
this.
3271
06:21:40,128 --> 06:21:48,030
Yeah. In the next video, we are going to see
how can we actually handle the same kind of
3272
06:21:48,030 --> 06:21:56,700
scenario. But we want to handle the sequence
of the input variables in a very controlled
3273
06:21:56,700 --> 06:22:01,390
way. Remember, in some of the previous this
this year, in this order of input arguments,
3274
06:22:01,390 --> 06:22:06,378
remember that we receive three arguments and
we pass the three arguments in a very controlled
3275
06:22:06,378 --> 06:22:11,570
way. And then whatever these are, we don't
care whatever the order here if we don't care,
3276
06:22:11,570 --> 06:22:17,390
what if we want to fix the issue? Or we want
to become more careful for input argument
3277
06:22:17,390 --> 06:22:24,470
orderings. But then we also want the arbitrary
number of arguments. How can we do that? Yeah,
3278
06:22:24,470 --> 06:22:29,790
wait for the next video. And I will show you
how can you do that? In the last video, I
3279
06:22:29,790 --> 06:22:36,260
promised you that I will show you how can
you achieve the ordering of the input variables,
3280
06:22:36,260 --> 06:22:41,580
but still having the arbitrary number of them.
Remember, this looks like much familiar to
3281
06:22:41,580 --> 06:22:48,510
you, that's a call that can be made to a function.
And remember, the function definition in some
3282
06:22:48,510 --> 06:22:54,400
previous slide was like C one, C two, and
C three maybe. And then something. What if
3283
06:22:54,400 --> 06:22:59,510
we want an arbitrary number of arguments to
be passed, but we want their control. For
3284
06:22:59,510 --> 06:23:06,292
example, let's say this particular variable
symbol name that acts as a key, that's a variable
3285
06:23:06,292 --> 06:23:11,270
name, and that's the value. So let me call
the variable name as a key. And let's This
3286
06:23:11,270 --> 06:23:15,458
is the value that is copied in the variable.
That's another key that's a value, that's
3287
06:23:15,458 --> 06:23:19,612
another key that's a value and so on, what
if we have a lot of key value pairs? What
3288
06:23:19,612 --> 06:23:25,750
if we have a lot of them. And we also want
to check which value is of what key, let's
3289
06:23:25,750 --> 06:23:30,420
say we want to specify those. But we want
to specify an arbitrary number of them. Let's
3290
06:23:30,420 --> 06:23:34,710
say here, for example, there are only three,
let's say we want to pass five of them, six
3291
06:23:34,710 --> 06:23:41,548
of them, and then we want our function to
perform accordingly. No matter how many input
3292
06:23:41,548 --> 06:23:46,710
arguments it received. Yeah, and and maybe
inside the function, we may have applied a
3293
06:23:46,710 --> 06:23:52,640
check that if the key value is C one, then
do this processing, if the key value is C
3294
06:23:52,640 --> 06:23:58,030
two, then do that kind of processing and so
on, let's say, based on different variable
3295
06:23:58,030 --> 06:24:05,020
symbol names, we want to process the value
differently, how can we achieve that, and
3296
06:24:05,020 --> 06:24:11,610
still having the need that these number of
variables can be can can be in a variable,
3297
06:24:11,610 --> 06:24:16,570
variable length, they can be an arbitrary
number of those. So Python gives you again,
3298
06:24:16,570 --> 06:24:22,370
a very, very simple way. Rather than writing
a simple single star, you write a double star,
3299
06:24:22,370 --> 06:24:30,110
and then you receive in whatever variable
name. And now in this double double star means
3300
06:24:30,110 --> 06:24:36,820
you are receiving a key value pair list. It's
a list of key value pairs. We will see that
3301
06:24:36,820 --> 06:24:41,440
that resembles two that resembles to a data
structure in Python called dictionary. We
3302
06:24:41,440 --> 06:24:46,708
will see dictionary later on in detail but
right now just just consider that this input
3303
06:24:46,708 --> 06:24:53,580
argument this input variable C, it contains
a, it contains a list of key values pairs,
3304
06:24:53,580 --> 06:24:58,720
and then you just you can just iterate over
the sea you can just apply a for loop to check
3305
06:24:58,720 --> 06:25:05,220
the contents of this Remember, we have actually
done that kind of thing in the, in the portion
3306
06:25:05,220 --> 06:25:11,310
of loops. Yeah, here. Remember that was a
key. And that was a value that was a key that
3307
06:25:11,310 --> 06:25:17,950
was a value. And we did that thing, we could
explore the we were able to explore the dictionary,
3308
06:25:17,950 --> 06:25:25,060
just just using for loop. Yeah, it's the same
thing here. It's not exactly but you can think
3309
06:25:25,060 --> 06:25:29,720
of that that's exactly the same thing. So
you can explore that, that see looks like
3310
06:25:29,720 --> 06:25:33,980
a dictionary. Now this is key, this is value,
this is key, this is value. This is key, this
3311
06:25:33,980 --> 06:25:42,490
has value, you can this x points, the first
key, then C of x point to the value based
3312
06:25:42,490 --> 06:25:48,260
on the based on the key x, and then x point
to the second key, then the second value and
3313
06:25:48,260 --> 06:25:53,840
so on you that that is very simple procedure,
you're just printing all the dictionary, but
3314
06:25:53,840 --> 06:26:00,100
you can, you're printing all the variable
names and the values, but you can do very
3315
06:26:00,100 --> 06:26:05,980
complicated processing, if you want to, let's
go to our friend Jupyter Notebook to just
3316
06:26:05,980 --> 06:26:12,601
get convinced that this indeed works. Let's
see. So let's define a function first. So
3317
06:26:12,601 --> 06:26:18,810
d f, that's the function name is Brent, all
3318
06:26:18,810 --> 06:26:32,410
variable, variables, and values. So that might
be a function name. While that's lengthy one,
3319
06:26:32,410 --> 06:26:40,890
but descriptor one, maybe we can make it more
descriptive, paint all the variable, variable
3320
06:26:40,890 --> 06:26:48,070
names and values, while that's more descriptive
a guess. So it receives, let's say, doublestar.
3321
06:26:48,070 --> 06:26:54,030
Any variable, let's say the variable name
is again, let's say arcs or anything, whatever
3322
06:26:54,030 --> 06:27:11,760
you want, then what we do is for x in orgs,
just Brent, let's say, variable name is just
3323
06:27:11,760 --> 06:27:34,370
Brent x, and then the sprint x and then just
continue, and value is value is our eggs of
3324
06:27:34,370 --> 06:27:40,790
x. So let's say you, you done this, you did
this. So the variable name is this, and the
3325
06:27:40,790 --> 06:27:48,548
value is this, okay, and you want to do this
for all, all the all the variable and value
3326
06:27:48,548 --> 06:27:58,560
pairs that you that you send at the call time.
So now let's call this brand, all variable
3327
06:27:58,560 --> 06:28:02,910
names and values. And let's call this let's
say the variable first variable name, let's
3328
06:28:02,910 --> 06:28:10,890
say is a, and its value is three. The second
variable name is let's say B, its value is
3329
06:28:10,890 --> 06:28:20,220
capital B, let's say the third Will you third
variable name is C, its value is CCC. And
3330
06:28:20,220 --> 06:28:24,570
let's say the fourth variable name, I mean,
you can define an arbitrary number of arguments
3331
06:28:24,570 --> 06:28:32,298
here. Wow, that's amazing. That's the fourth
variable name is why its value is 6.7. And
3332
06:28:32,298 --> 06:28:39,580
further notice, you can you can pass variable
and value all have different types, I'm in
3333
06:28:39,580 --> 06:28:47,170
different number of them. And and much more.
Yeah, you can do that. So let's call this
3334
06:28:47,170 --> 06:28:53,708
function by just having four variables and
their values. Let's see what we got. So well,
3335
06:28:53,708 --> 06:28:58,150
variable name is a and the value is three
variable name is B, and the value is B, variable
3336
06:28:58,150 --> 06:29:06,702
name is C and the values CCC, variable name
is why and value is 6.7. You can give an arbitrary
3337
06:29:06,702 --> 06:29:13,470
lampi list here if you want. And Python just
allows you to do that. And it allows you to
3338
06:29:13,470 --> 06:29:18,980
do that in a very, very simple way. That's
amazing. That's amazing. I mean, that's, that's
3339
06:29:18,980 --> 06:29:26,740
why a high level language or radio, a powerful
language should should have a feature. So
3340
06:29:26,740 --> 06:29:31,660
Python does have this feature. I'm really
amazed. I'm really, really astonished by time.
3341
06:29:31,660 --> 06:29:37,730
By the way, I'm not saying the other languages
don't have this. several languages actually
3342
06:29:37,730 --> 06:29:43,620
support this kind of feature, but Python supports
it in a very easy way. It's very easy to do
3343
06:29:43,620 --> 06:29:51,530
that. I mean, it's not not a rocket science.
Yeah. Okay, so now we have had an arbitrary
3344
06:29:51,530 --> 06:29:55,780
number of arguments even when the ordering
is really controlled.
3345
06:29:55,780 --> 06:30:02,420
We have one or two more videos on functions.
Just to explain a bit more than we will, then
3346
06:30:02,420 --> 06:30:06,200
we will practice on Jupyter Notebook, we'll
practice we will play with these functions
3347
06:30:06,200 --> 06:30:11,630
a lot. And we will be calling one function
inside the other function and so on, we will
3348
06:30:11,630 --> 06:30:17,130
be having one better program just just program
and noodle Jupyter Notebook just to get comfortable
3349
06:30:17,130 --> 06:30:21,770
with this functions. But before that, let's
have one or two more things to discuss about
3350
06:30:21,770 --> 06:30:27,330
the functions. Yeah, let's see. So I hope
to see you in the next video. Okay, I really
3351
06:30:27,330 --> 06:30:34,120
want to talk about these default values for
a function as well, because that's important
3352
06:30:34,120 --> 06:30:42,782
and mostly needed. The default value is a
value of the input variable that you assign
3353
06:30:42,782 --> 06:30:48,340
well, while you are defining a function, and
if the value is, for example, if you call
3354
06:30:48,340 --> 06:30:55,190
this F, with let's say, the input value three,
then three will be copied in the sum and the
3355
06:30:55,190 --> 06:31:00,250
print will be three. But if you call this
function without the input, then this value
3356
06:31:00,250 --> 06:31:05,282
acts as as if you have passed this. So this
is the default value if you do not supply
3357
06:31:05,282 --> 06:31:09,900
the value, this is the value that is going
to operate. And by the way, you can have multiple
3358
06:31:09,900 --> 06:31:14,490
variables with default values, some variables
with default value is defined some variables.
3359
06:31:14,490 --> 06:31:19,878
With default variables, a default value is
not defined, and so on. So you can have this
3360
06:31:19,878 --> 06:31:25,980
one here must be taken here that the default
value, when you actually define the function,
3361
06:31:25,980 --> 06:31:30,350
and you compile this function, actually, you
you run the cell shift enter in Jupyter Notebook.
3362
06:31:30,350 --> 06:31:37,720
At that very time, this variable is assigned
this value at that particular time, it is
3363
06:31:37,720 --> 06:31:43,330
not assigned at the call time. So sum equals
to zero is already there, when you actually
3364
06:31:43,330 --> 06:31:49,120
press Shift Enter for a cell that contains
this code.
3365
06:31:49,120 --> 06:31:54,640
Now later on, if you pass a value, that value
will be overwritten on some, if you don't
3366
06:31:54,640 --> 06:32:00,900
pass the value zero will go on, it looks like
very easy, but one care that I want to mention
3367
06:32:00,900 --> 06:32:06,980
here that I haven't mentioned earlier, in
Python, there are certain variables that are
3368
06:32:06,980 --> 06:32:12,040
that are referenced rather than copied, I
will discuss the referencing in the copying
3369
06:32:12,040 --> 06:32:18,010
data in detail in data structures. But let
me just tell you 111 example, let's say you
3370
06:32:18,010 --> 06:32:24,110
define a list, let's say one, two, and three.
And then what you do you copy this list into
3371
06:32:24,110 --> 06:32:32,350
another variable, let's say l two, what will
happen is in the memory, this list in a particular
3372
06:32:32,350 --> 06:32:36,680
way, this is not the exact view of the memory,
I'm just showing you, let's say this is the
3373
06:32:36,680 --> 06:32:42,340
particular memory layout for which this L
is pointing to this L is label for that l
3374
06:32:42,340 --> 06:32:48,010
two is also labeled for that, which means
actually in memory, this is not the copy of
3375
06:32:48,010 --> 06:32:52,878
the structure that is made, I mean this is
not like in variables. For example, if a is
3376
06:32:52,878 --> 06:33:01,032
equal to three and b is equal to a, a will
be a will be a position in memory, and B will
3377
06:33:01,032 --> 06:33:05,920
be a separate position in memory. That is
what a view of the memory in ordinary variables
3378
06:33:05,920 --> 06:33:11,620
are. But there are certain variables in memory
just for memory efficient and cost efficiency
3379
06:33:11,620 --> 06:33:17,350
and time. People have people have designed
these data structures in a way that when you
3380
06:33:17,350 --> 06:33:23,000
copy them, when you just assign a variable
to another variable, the memory view doesn't
3381
06:33:23,000 --> 06:33:28,250
change the just it's it's another name for
the same for the same for the same memory
3382
06:33:28,250 --> 06:33:34,890
location. So what happens is if you change
any value, and let's say l two, let's say
3383
06:33:34,890 --> 06:33:40,920
l two, at the very, the zeros and add the
zero index, let's say you change that by minus
3384
06:33:40,920 --> 06:33:46,942
nine, the because it is the same view in memory
that changes minus nine. And now if you print
3385
06:33:46,942 --> 06:33:51,160
the elements of L rather than l two, you will
get the changed value, you will see the change
3386
06:33:51,160 --> 06:33:57,820
value. And that happens. Now why that is important
in terms of these default values here for
3387
06:33:57,820 --> 06:34:04,650
the function. The reason is, if you are accepting
a list, let's say the default is a list, and
3388
06:34:04,650 --> 06:34:09,470
you're accepting a list and you are also defining
some default value for the list. If that's
3389
06:34:09,470 --> 06:34:15,780
your definition, let's say then this list
this default value is assigned at the ad the
3390
06:34:15,780 --> 06:34:22,490
very first at the very first time, and this
L is really a local variable inside inside
3391
06:34:22,490 --> 06:34:31,410
the inside the memory. Now when once this
cell is run, not the call time at the at the
3392
06:34:31,410 --> 06:34:36,470
sowhat call the compile time, when the cell
is run this L is assigned this and that just
3393
06:34:36,470 --> 06:34:42,430
happens once. Now if you call this list with
some other list let's say l to let's say two
3394
06:34:42,430 --> 06:34:49,230
three and four. Then if you call this L two,
l two will go there it will be copied in L
3395
06:34:49,230 --> 06:34:56,950
and everything is fine, but don't then expect
this the contents of L to to stay same as
3396
06:34:56,950 --> 06:35:03,471
staying l because l is this default. values,
they are assigned just once. And they stay
3397
06:35:03,471 --> 06:35:08,390
as it is, every time you call the function,
they don't change. They are not assigned at
3398
06:35:08,390 --> 06:35:13,020
the call time they are assigned at the compile
time and they stay fixed. So that care must
3399
06:35:13,020 --> 06:35:17,958
be taken. I will show you that example that
particular example, in Jupyter Notebook shortly
3400
06:35:17,958 --> 06:35:22,570
at this, this might be confusing right now,
because we have not defined, we have not seen
3401
06:35:22,570 --> 06:35:28,820
lists in detail. But I just want to make this
point. I just want to mention this because
3402
06:35:28,820 --> 06:35:33,040
that's important difference with ordinary
variables that I mean default values, just,
3403
06:35:33,040 --> 06:35:38,792
I mean, just like like a value. And if you
don't supply a value, the default value just
3404
06:35:38,792 --> 06:35:44,720
works. But with the variable that are referenced
by variables, you may expect something else.
3405
06:35:44,720 --> 06:35:50,331
And the Python function behaves maybe differently.
And that's because these default values they
3406
06:35:50,331 --> 06:35:55,800
are assigned at compile time they are not
are compiled time. Actually, this is not a
3407
06:35:55,800 --> 06:36:00,810
compiled language, I should not use the word
compiled compiled again. And again, just think
3408
06:36:00,810 --> 06:36:05,452
when we define this function, and we run the
cell at that particular time, the default
3409
06:36:05,452 --> 06:36:13,230
value is assigned. And the default value never
changes. It stays fixed. Yeah. So and I will
3410
06:36:13,230 --> 06:36:18,620
show you that example. Why don't we move to
Jupyter Notebook and see that example? Yeah.
3411
06:36:18,620 --> 06:36:25,220
So or why don't we do that in the next video?
What do you think? This video, okay, same
3412
06:36:25,220 --> 06:36:32,550
with you. Okay, let's go to Jupiter and mode
notebook and see the default values. For example,
3413
06:36:32,550 --> 06:36:34,930
let's see.
3414
06:36:34,930 --> 06:36:43,860
Let's say we have define a function, let's
say GG, and the default value s is equal to
3415
06:36:43,860 --> 06:36:51,190
four, let's say that's a default value. And
we want to print let's say s, if available.
3416
06:36:51,190 --> 06:36:56,810
From the call time, if not available, then
four will be printed. Now we print now right
3417
06:36:56,810 --> 06:37:04,090
now we are going to print, now we are going
to press Shift Enter at that time, S is assigned
3418
06:37:04,090 --> 06:37:14,622
to for S has no value for it is assigned there.
Now we call GG, let's say and we call GG without
3419
06:37:14,622 --> 06:37:20,330
input arguments. Now the four will be printed.
If we call this GG with some input argument,
3420
06:37:20,330 --> 06:37:26,450
let's say 56. Now the 56 will be printed,
no problem, everything is fine. Let's see
3421
06:37:26,450 --> 06:37:34,580
about the lists. For example, let's say the
list is, let's say 123, that list, and then
3422
06:37:34,580 --> 06:37:42,960
l two is simply let's say l two is L, then
what we do is we change the contents of L
3423
06:37:42,960 --> 06:37:48,560
two, let's say we change the very first value
in L two, and we place that values minus nine,
3424
06:37:48,560 --> 06:37:55,390
and then we print L. Now, you might be expecting
that l is a different thing, l two is a different
3425
06:37:55,390 --> 06:37:59,750
thing. Because l and l two, they both are
pointing to the same memory. This, the content
3426
06:37:59,750 --> 06:38:06,000
through l two actually changes the memory
view and l also changes and that gives the
3427
06:38:06,000 --> 06:38:12,880
result minus nine in L. Well, the behavior
that I want to show you is different in the
3428
06:38:12,880 --> 06:38:19,700
default values. When we when we talk about
for example, let's say we define a function,
3429
06:38:19,700 --> 06:38:26,860
f f and it accepts a list and the default
value is empty list, or the default value
3430
06:38:26,860 --> 06:38:33,810
is let's say one, two, that's the default
value, let's say if, if no list is passed,
3431
06:38:33,810 --> 06:38:41,460
the default list is one two. Now, in this
particular scenario, if we just print, so
3432
06:38:41,460 --> 06:38:50,440
for example, for i in the list, brand, I let's
say we just print all the list. That's it.
3433
06:38:50,440 --> 06:38:56,350
Now we will press Shift Enter, and at this
time this L is assigned this value, and that's
3434
06:38:56,350 --> 06:39:02,430
a default value that never, that is not going
to change. Now let's say we have an L tool
3435
06:39:02,430 --> 06:39:10,470
that is simply let's say two, three and four,
or let's say 12, three and four. And what
3436
06:39:10,470 --> 06:39:21,880
we do is we call F and we just press Shift
Enter. Now, why don't we call f f without
3437
06:39:21,880 --> 06:39:31,680
anything. So, the default list is printed,
if we call this f f with L to the L two will
3438
06:39:31,680 --> 06:39:42,320
be printed. Now the notice that this L two
actually is copied in this L because we supplied
3439
06:39:42,320 --> 06:39:51,958
it. So l and l two you may tend to think that
l is now also pointing to L to an L has also
3440
06:39:51,958 --> 06:39:58,990
the same contents as l two. So if next time
because because of the behavior of these lists
3441
06:39:58,990 --> 06:40:04,208
because they are by Reference. Next time you
make you make might be thinking that because
3442
06:40:04,208 --> 06:40:12,628
l two is past there, so l two L is also L,
L two is copied in L in a memory view way
3443
06:40:12,628 --> 06:40:20,310
layout. So l has also the same data as l two
and next time, if we call this function without
3444
06:40:20,310 --> 06:40:25,450
input arguments, then l might be pointing
out to L two values. So, 12 three and four
3445
06:40:25,450 --> 06:40:30,260
might be printed, but that is not going to
happen, the default values they never change.
3446
06:40:30,260 --> 06:40:38,200
So, again, you will be getting one, two, so,
the behavior of these Reference Type variables,
3447
06:40:38,200 --> 06:40:43,790
that is different ordinarily, but when you
do that in in the default value structure,
3448
06:40:43,790 --> 06:40:49,220
that, that, that might work in a different
way. And the reason is, you, you must know
3449
06:40:49,220 --> 06:40:55,550
that these default values they're assigned
at, at the time when the function is created,
3450
06:40:55,550 --> 06:41:00,550
not at the function when the function is called.
And they are not going to change whatsoever.
3451
06:41:00,550 --> 06:41:05,810
So, so that was about the default value. And
by the way, the default if it was a simple
3452
06:41:05,810 --> 06:41:14,610
concept, I guess I have made it too complicated
by telling you layers and default values and
3453
06:41:14,610 --> 06:41:20,622
creation of these variables, at what time
and at the call time, I made this complicated,
3454
06:41:20,622 --> 06:41:27,708
I guess, I shouldn't have told you the list
values and all that stuff. But but that's
3455
06:41:27,708 --> 06:41:31,840
true. And in whatever I have told you is true.
Maybe I have told you in a very complicated
3456
06:41:31,840 --> 06:41:37,458
way, but it's true. Yeah. Okay.
3457
06:41:37,458 --> 06:41:43,140
One more video on the functions and then we
will be practicing functions in detail on
3458
06:41:43,140 --> 06:41:47,870
on Jupyter notebooks. So just be or one more
video with me. Hope to see you in the next
3459
06:41:47,870 --> 06:41:57,350
video. Okay, this is probably the last video
on on the functions. Yeah, we will, we will
3460
06:41:57,350 --> 06:42:02,730
be having one more video. But but that will
be like coding and practicing all the concepts
3461
06:42:02,730 --> 06:42:08,720
that we learn about the functions not? Not
something not not new theoretical concepts.
3462
06:42:08,720 --> 06:42:17,298
Yeah. So let me ask you a question to actually,
to actually make you understand about this
3463
06:42:17,298 --> 06:42:24,140
slide. Let me go to the Jupiter and ask you
about a few questions. Let's say you have,
3464
06:42:24,140 --> 06:42:30,140
let's say, let's say you have this particular
function, and you, let's say my ad, my ad
3465
06:42:30,140 --> 06:42:34,780
universal, let's say we have written that
function, maybe two or three or three videos
3466
06:42:34,780 --> 06:42:39,461
before, let's say you have this function,
you have written this function, and you are
3467
06:42:39,461 --> 06:42:45,560
very, very excited, wow, what kind of masterpiece
you have generated, it can add an arbitrary
3468
06:42:45,560 --> 06:42:53,140
number of values pass in it well, but this
particular function is written inside this
3469
06:42:53,140 --> 06:42:58,560
particular file, which is mastering Python
zero to hero. Later on, let's say two or three
3470
06:42:58,560 --> 06:43:04,720
months later, you are writing some code for
some, some project or you are doing something
3471
06:43:04,720 --> 06:43:10,020
somewhere and you are writing code, and there
you just needed.
3472
06:43:10,020 --> 06:43:15,730
You just needed a, you just needed a code
for adding a lot of a lot of values together.
3473
06:43:15,730 --> 06:43:21,720
And then you just remember, oh, I have written
some function somewhere. How can you use that
3474
06:43:21,720 --> 06:43:27,660
function? One way is to just go back to that
file mastering Python zero to hero, and just
3475
06:43:27,660 --> 06:43:34,060
copy this function, this particular this code
and paste in the new file, run that, register
3476
06:43:34,060 --> 06:43:41,700
that and then call that happy. What if you
want to use let's say, 100 different functions,
3477
06:43:41,700 --> 06:43:45,930
let's say you have written a lot of functions
in a lot of different files. And now you want
3478
06:43:45,930 --> 06:43:53,350
to use all of them. And, and let's say this
is a repetitive kind of demand several times
3479
06:43:53,350 --> 06:43:58,048
you notice that this usually happens that
this particular kind of function, you require
3480
06:43:58,048 --> 06:44:04,900
almost every almost in every project, let's
say a set of maybe 50, or 60 functions that
3481
06:44:04,900 --> 06:44:11,380
are that are required always, one way to do
that, as I told you is to jump just copy paste
3482
06:44:11,380 --> 06:44:17,150
those functions in every file, run them and
do that. Another way is to just just I mean,
3483
06:44:17,150 --> 06:44:23,500
make a module a file of containing just those
functions. And whenever any of those functions
3484
06:44:23,500 --> 06:44:31,120
is required, just import that module into
your coding file, which has one line of code
3485
06:44:31,120 --> 06:44:36,628
and then access all the functions as if they
were they were they were actually available
3486
06:44:36,628 --> 06:44:46,560
in in the port file that you are working on.
So that's about the that's about making modules
3487
06:44:46,560 --> 06:44:53,800
of so module is basically a Python file that
contains functions that you want to use in
3488
06:44:53,800 --> 06:45:01,150
several different coding projects or the functions
that you don't want to write in your the functions.
3489
06:45:01,150 --> 06:45:05,458
Having the implementation that you don't want
to write in your grant coding file, so you
3490
06:45:05,458 --> 06:45:09,790
can have several of those functions stayed
somewhere else in a different directory they
3491
06:45:09,790 --> 06:45:15,660
are residing there, whenever you want to use
any of them, you just import the whole module
3492
06:45:15,660 --> 06:45:21,951
and use the functions. So, so module is just
a Python file that can that can contain a
3493
06:45:21,951 --> 06:45:27,510
code for you that whenever you want to use,
you can use it. Normally it contains functions
3494
06:45:27,510 --> 06:45:33,048
maybe more than one function and several functions.
Normally, it contains functions that you repetitively
3495
06:45:33,048 --> 06:45:37,710
use, and that you have written once in very
careful way. And then now you want to use
3496
06:45:37,710 --> 06:45:43,298
it again and again in several different ways.
You need not to write the function definition,
3497
06:45:43,298 --> 06:45:49,290
in every coding file you need, you just make
one coding file, or that that is the most
3498
06:45:49,290 --> 06:45:54,430
important for you, that is called a module
where wherever you want to use any of those
3499
06:45:54,430 --> 06:46:01,660
functions that are there in that module, you
can call it, you can use it. So that's about
3500
06:46:01,660 --> 06:46:07,940
the modules we are going to make. I'm going
to show you one example of making module and
3501
06:46:07,940 --> 06:46:15,770
how to use that. But but to use the module,
we need to actually specify the path where
3502
06:46:15,770 --> 06:46:24,420
the module actually resides using this cess
module. So and then we have to do some this
3503
06:46:24,420 --> 06:46:30,800
import kind of commands. And then I mean,
there is some work that we need to do to actually
3504
06:46:30,800 --> 06:46:36,378
get this module running in our code. So in
the next video, I'm going to tell you what
3505
06:46:36,378 --> 06:46:41,510
that extra work, very little amount of work
what that extra work you have to do. So here,
3506
06:46:41,510 --> 06:46:47,920
for example, my funks.py, that's my Python
file, and it contains these two functions.
3507
06:46:47,920 --> 06:46:52,628
And let's say I want to use one of these have
both of these functions in some other file,
3508
06:46:52,628 --> 06:46:58,290
and that file contains this particular code.
So in the next video, I will show you how
3509
06:46:58,290 --> 06:47:08,610
to how to actually make and use the modules.
Yeah, so hope to see you in the next video.
3510
06:47:08,610 --> 06:47:14,510
Okay, in the last video, I told you about
modules module is just a Python file that
3511
06:47:14,510 --> 06:47:20,720
can contain a code that can be used anywhere,
if you want normally, that module. Normally,
3512
06:47:20,720 --> 06:47:25,910
the modules, they contain a lot of functions,
but they can contain variables and other values,
3513
06:47:25,910 --> 06:47:36,690
and so on. So think about file myfonts.py,
that contain this, these two functions, and
3514
06:47:36,690 --> 06:47:41,110
think about a different file, maybe Jupiter,
maybe you're working in a Jupyter Notebook.
3515
06:47:41,110 --> 06:47:46,510
And now you want to use these two functions.
So you first have to import another module
3516
06:47:46,510 --> 06:47:52,620
call the system module says you have to have
you have to make this path available. There
3517
06:47:52,620 --> 06:47:57,285
are a lot of built in modules that are already
there in the path all the already there in
3518
06:47:57,285 --> 06:48:04,170
the search path. When you want to call a function,
it is written in some module that is already
3519
06:48:04,170 --> 06:48:08,270
in the search path. If you're making your
modules, you have to either
3520
06:48:08,270 --> 06:48:17,128
either copy those, those modules into the
modules that are built in or if you want to
3521
06:48:17,128 --> 06:48:22,250
maintain them separately somewhere else, then
you have to add the path of these in the search
3522
06:48:22,250 --> 06:48:29,660
path as well. And the way to actually insert
this path is sis dot path dot append. And
3523
06:48:29,660 --> 06:48:35,530
then you actually write the the path of the
directory where this module file one or more
3524
06:48:35,530 --> 06:48:42,230
files are located. Once this is added to the
path, now you can write the import. And you
3525
06:48:42,230 --> 06:48:50,730
can import your file and your file as it is
or you can import your file with some other
3526
06:48:50,730 --> 06:48:55,782
name if you want, you can rename that on the
fly if you want. Once this is imported, now
3527
06:48:55,782 --> 06:49:00,550
you can use all the functions like the built
in functions, the implementation of these
3528
06:49:00,550 --> 06:49:06,230
functions are not there in your coding file,
you are just using those and you can now import
3529
06:49:06,230 --> 06:49:13,140
this module into some other file and use their
and so on. for, for, for for very large kind
3530
06:49:13,140 --> 06:49:20,420
of projects. It is good to make modules. Actually
it is better to make packages, which is actually
3531
06:49:20,420 --> 06:49:27,620
the directory structures that contain modules.
But modules at least are really good too,
3532
06:49:27,620 --> 06:49:32,380
for maintaining a large amount, of course,
or actually the functions that you want to
3533
06:49:32,380 --> 06:49:40,390
use again and again. So let's just let's let's
make a module, why not? So let's make a module.
3534
06:49:40,390 --> 06:49:45,940
Let's say let's go to Jupyter Notebook. Let's
create another file. Let's create another
3535
06:49:45,940 --> 06:50:01,820
file, let's say new Python three and let's
let's name this file as my IE let's say let's
3536
06:50:01,820 --> 06:50:11,730
let's name this file as my universal, let's
let's use underscores my universal functions.
3537
06:50:11,730 --> 06:50:17,150
Let's classify the name. Let's create another
notebook. Right now it's just a notebook that's
3538
06:50:17,150 --> 06:50:25,660
defined some functions. Let's say we want
to define one function as jack, all orgs.
3539
06:50:25,660 --> 06:50:34,640
Let's say that's the function it receives,
let's say,
3540
06:50:34,640 --> 06:50:43,700
let's say it receives a dictionary like input.
And then it checks the date, let's say check,
3541
06:50:43,700 --> 06:50:56,958
set check type of all arcs. And let's say,
let's say you write a function check, if not
3542
06:50:56,958 --> 06:51:08,570
numeric, let's say, let's say you want to
write a function that that just accepts a
3543
06:51:08,570 --> 06:51:14,820
lot of arguments. And you want to check whether
any one thought, if any one of them is not
3544
06:51:14,820 --> 06:51:21,230
numeric, you want to return let's say, a flag.
Otherwise, you want to return a true, let's
3545
06:51:21,230 --> 06:51:28,510
say, so for example, you may you may need
this function in several places. Let's say
3546
06:51:28,510 --> 06:51:34,080
in in your core, you're expecting numerical
inputs. And if the input is, and let's say
3547
06:51:34,080 --> 06:51:37,940
there are a lot of variables that you are
working on if and if any one of them is not
3548
06:51:37,940 --> 06:51:44,490
numeric, you might want to check all the all
the variables and their values. One way of
3549
06:51:44,490 --> 06:51:52,130
doing that is just to create a list. And that's
it. I mean, that's and and you may have several
3550
06:51:52,130 --> 06:51:58,610
of those, I mean, you can check all of them.
And maybe here, maybe here, we do not need
3551
06:51:58,610 --> 06:52:04,580
the dictionary kind of argument. So maybe
we just are happy with just one. So let's
3552
06:52:04,580 --> 06:52:14,570
say for so the output, let's say output is
let's say, R or the return value that value.
3553
06:52:14,570 --> 06:52:24,510
Let's say that is already true. And we will
say okay, for x in ARDS, let's say for x in
3554
06:52:24,510 --> 06:52:44,750
arcs. If x if is in stance, x is and float,
if that is true, then we are happy. But if
3555
06:52:44,750 --> 06:52:51,860
that is not true, if that is not true, then
there is a trouble, then we say okay, if this
3556
06:52:51,860 --> 06:53:00,490
is not true for any value, then we just return.
False. Okay, we just return false. I mean,
3557
06:53:00,490 --> 06:53:06,690
we need not to break anything, we just return
false return means return, whatever. Otherwise,
3558
06:53:06,690 --> 06:53:14,410
if we finish this loop, if the loop finishes
successfully, and there is no return statement
3559
06:53:14,410 --> 06:53:21,460
that is called already, then we return, maybe
true, we need to do not need Actually, this
3560
06:53:21,460 --> 06:53:27,298
variable. Let's see. So this function will
return true if all the variables are either
3561
06:53:27,298 --> 06:53:34,200
int or float. If any of them is not of this
type, this function returns false. Well, we
3562
06:53:34,200 --> 06:53:39,990
can have another we can have another function,
maybe we can write several function, the same
3563
06:53:39,990 --> 06:53:49,872
cell or in different cells. Either way, define
let's say another function, universal. Or
3564
06:53:49,872 --> 06:54:01,220
add all values, let's add all that's in Numerix,
and all numerix. And it also contains, let's
3565
06:54:01,220 --> 06:54:08,310
say, arcs. And the goal of this function is
just to add all the values and return the
3566
06:54:08,310 --> 06:54:21,340
sum. So let's say s equals zero for x in for
x in ogs, as plus equals to tax, and that's
3567
06:54:21,340 --> 06:54:27,170
it, then return us, let's say these are two
functions. And maybe one more the name of
3568
06:54:27,170 --> 06:54:33,458
this, or some some variable, let's say you,
I mean, these are two functions. Now we are
3569
06:54:33,458 --> 06:54:41,930
out of the function we are writing something
else. Let's say my name let's say that's a
3570
06:54:41,930 --> 06:54:47,390
variable, my name this, this does not this
my name variable does not belong to any of
3571
06:54:47,390 --> 06:54:56,930
these functions. And my name is Python. Course
let's say that's my. So that's it. That's
3572
06:54:56,930 --> 06:55:04,820
file with name my universal functions. So
what we do is we download this file as a.pi
3573
06:55:04,820 --> 06:55:11,981
file.pi file. So what we do really is the
Go to File, let me just zoom this out so that
3574
06:55:11,981 --> 06:55:18,190
you can see the download options. We go to
File Menu, we download this, as we download
3575
06:55:18,190 --> 06:55:19,190
this as
3576
06:55:19,190 --> 06:55:30,000
we download this as well as by file, so Python
file. So let's download this, or we can write
3577
06:55:30,000 --> 06:55:37,240
this Python file as in some other editor if
we want. So open folder, there is a Python
3578
06:55:37,240 --> 06:55:46,730
file here, copy it. Now copy that file. And
now you're free to go to any, for example,
3579
06:55:46,730 --> 06:55:55,958
any, any folder if you want, just, for example,
you go to somewhere in your directory, and
3580
06:55:55,958 --> 06:56:00,830
make a new directory, maybe, maybe you want
to make another directory. For example, go
3581
06:56:00,830 --> 06:56:12,560
and make a directory, maybe in D, let's say,
or maybe an E, let's say or maybe in C somewhere
3582
06:56:12,560 --> 06:56:18,140
and then make a module anywhere. For example,
in C, make a new folder, call that folder
3583
06:56:18,140 --> 06:56:30,190
as my, or any name, whatever name you want,
for example, my module or let's say utils,
3584
06:56:30,190 --> 06:56:36,470
for example, utilities or whatever name, I
mean, let's let's call it as, let's call it
3585
06:56:36,470 --> 06:56:45,160
as ABC, for example, ABC, whatever. And you
just made that and just copy that Python file
3586
06:56:45,160 --> 06:57:00,770
here, my universal functions.by. Now, if you
go back, if you go back to your there, there
3587
06:57:00,770 --> 06:57:08,702
is a Jupiter, here is a Jupiter. Now you go
back to your code, this is your file, go back
3588
06:57:08,702 --> 06:57:17,640
to your code, let's say this file is no longer
here. And what you do is you import Sis, that's
3589
06:57:17,640 --> 06:57:27,548
a system module and says dot path dot bend.
Right the path here where the module is located.
3590
06:57:27,548 --> 06:57:35,180
So the module right now is located at ABC,
this is the part of the module. Once done,
3591
06:57:35,180 --> 06:57:41,270
you can import what what was the name of the
module, you need to know that that was my
3592
06:57:41,270 --> 06:57:59,370
my word. So I just I just don't remember the
name, let's import my universal functions.
3593
06:57:59,370 --> 06:58:06,200
How it appears, actually, when I when I have
Eric this part, then this import command and
3594
06:58:06,200 --> 06:58:12,790
after the dab completion, just fetches that
file. So that that that name might be very
3595
06:58:12,790 --> 06:58:20,040
lengthy. So you can rename that as let's say,
my apps or whatever name you want. So you
3596
06:58:20,040 --> 06:58:25,810
import that once you have imported that. Now
you can use the functions if you want, for
3597
06:58:25,810 --> 06:58:33,680
example, you can check the implementation
of my efs.if, you see dot add Numerix, you
3598
06:58:33,680 --> 06:58:39,000
want to check the implementation of that.
Here, this remember this file is no longer
3599
06:58:39,000 --> 06:58:44,450
in this particular file is located somewhere
else. And you can call this function like
3600
06:58:44,450 --> 06:58:55,740
like the built in functions, my apps dot add
all numerix. And you can have for example,
3601
06:58:55,740 --> 06:59:05,980
let's say accepts the input arguments, let's
say 234. All that says six. And that's it.
3602
06:59:05,980 --> 06:59:11,102
That's the, that's the return value, you can
you can save the return value in some other
3603
06:59:11,102 --> 06:59:16,880
variable, let's see. And then later on, you
can print this see our do some stuff with
3604
06:59:16,880 --> 06:59:24,980
this. See, that's one thing. Another way of
importing the same thing is let's say you
3605
06:59:24,980 --> 06:59:30,140
don't want to use all the functions, you just
need this add all the metrics, let's say that's
3606
06:59:30,140 --> 06:59:34,640
that's the only function that you want to
use again and again. So you need not the other
3607
06:59:34,640 --> 06:59:38,310
functions, let's say for this particular file,
you do not need the other functions, then
3608
06:59:38,310 --> 06:59:49,370
what you can do is you can just say okay,
from my universal functions, import,
3609
06:59:49,370 --> 06:59:56,790
add all Numerix and you can rename it rename
this function as something and you can call
3610
06:59:56,790 --> 07:00:02,310
that function the same way. So you do that
now. You need Not to write any dot kind of
3611
07:00:02,310 --> 07:00:10,590
thing, you just call add all Numerix because
it is important now, and you say, Okay 234567
3612
07:00:10,590 --> 07:00:17,298
and you'll save that in let's a D, and then
you print the if you want, or do whatever
3613
07:00:17,298 --> 07:00:24,920
with that. That's it are you can import several
multiple functions or you can import all of
3614
07:00:24,920 --> 07:00:32,350
them. Other than modules, there are I mean,
for complex codes, I mean, this is not one
3615
07:00:32,350 --> 07:00:38,458
module that is there, I mean, there are several
modules. And the several modules may be arranged
3616
07:00:38,458 --> 07:00:43,090
in in a directory structure, where the directory
and the sub directory and the sub directory
3617
07:00:43,090 --> 07:00:48,200
and so on. So the modules that are arranged
in directory structure, although they are
3618
07:00:48,200 --> 07:00:53,810
accessed, much like the same way, that directory
structure is sometimes called package. And
3619
07:00:53,810 --> 07:00:58,940
these are basically the packages that are
that are most useful. And we will be seeing
3620
07:00:58,940 --> 07:01:06,208
some data science packages, like NumPy is
a data science package. Then, we will be seeing
3621
07:01:06,208 --> 07:01:13,160
pandas, that's a data science package, we
will be seeing matplotlib that's a data science
3622
07:01:13,160 --> 07:01:18,110
package for plotting and visualizations and
stuff. So packages, just the modules that
3623
07:01:18,110 --> 07:01:24,470
are arranged in directory structures. So now
you know what module is. And the old one,
3624
07:01:24,470 --> 07:01:30,458
Venus two, we actually missed to import the
name of have to see the name Vivi have saved
3625
07:01:30,458 --> 07:01:39,690
a name there as well. So let's go back. And
let's go back and do that and see how, how
3626
07:01:39,690 --> 07:01:46,620
many things are available. Let's go to some
other cell and empty cell. So my apps dot
3627
07:01:46,620 --> 07:01:54,360
tab completion, my name is available. Remember,
there was a variable. Yeah, that's available.
3628
07:01:54,360 --> 07:02:01,458
So the name is Python course. So this module
file does not require to only contain functions,
3629
07:02:01,458 --> 07:02:06,290
it can contain any information, any data that
you want to use in other files, other coding
3630
07:02:06,290 --> 07:02:13,010
and stuff, and so on. So, yeah, that's about
modules. In the in the next video, we will
3631
07:02:13,010 --> 07:02:19,200
practice about these functions a little bit,
we will be seeing how to call a function inside
3632
07:02:19,200 --> 07:02:23,890
another function, how to make a lot of functions
that are calling each other and so on. So
3633
07:02:23,890 --> 07:02:29,760
we will be practicing more on about these
functions, not theoretically, just in Jupyter
3634
07:02:29,760 --> 07:02:37,580
Notebook, just to get a better look and feel
of of functions more. And after that practice,
3635
07:02:37,580 --> 07:02:43,170
we will be then jumping towards data structure
starting from strings. So hope to see you
3636
07:02:43,170 --> 07:02:51,870
in the next video. Okay, before moving on,
let's just practice some, some some, I mean,
3637
07:02:51,870 --> 07:02:56,650
let's get a good grip on functions and multiple
functions and handling those. And the best
3638
07:02:56,650 --> 07:03:02,830
way to do that is to solve actually a problem.
Remember, we solved a problem when we when
3639
07:03:02,830 --> 07:03:07,540
we, when we are done when we were done with
if conditions, then we solved another problem
3640
07:03:07,540 --> 07:03:13,840
when we were done with loops just to get a
good grip on loops. Let's solve a problem.
3641
07:03:13,840 --> 07:03:21,030
Let's just solve a problem using using the
functions just to get a good idea of functions.
3642
07:03:21,030 --> 07:03:26,300
What kind of problems should be solved here?
Should we solve an older problem? Last time
3643
07:03:26,300 --> 07:03:32,400
we solve a problem using loops that are sorting
a list? What Why don't we? Why don't we solve
3644
07:03:32,400 --> 07:03:39,410
the same problem, but in a different way?
So let's go to Jupiter and see. See our file
3645
07:03:39,410 --> 07:03:47,420
Jupiter file? We have actually solved a function,
which somewhere using loops, just let me just
3646
07:03:47,420 --> 07:03:53,770
find that out. Oh yeah, they're here. So here.
So given a list of numbers, let's this make
3647
07:03:53,770 --> 07:03:58,680
another list or maybe the same list that contains
all the items in the sorted order, from minimum
3648
07:03:58,680 --> 07:04:05,400
to maximum, your result will be another list
like this. And we solve that using loops.
3649
07:04:05,400 --> 07:04:13,760
Okay, let's solve the same problem. Exactly
the same problems that solve the same problem
3650
07:04:13,760 --> 07:04:19,270
using a different way using a different user
using functions just to get a grip on functions.
3651
07:04:19,270 --> 07:04:25,840
So let's say that's our problem we want to
solve. So that's the problem again, and we
3652
07:04:25,840 --> 07:04:32,800
want to solve that. So how can we solve that?
To solve that, let's first define a function.
3653
07:04:32,800 --> 07:04:37,090
Let's just make a function.
3654
07:04:37,090 --> 07:04:46,170
Let's just make a function that let's just
make a function, let's say define, find minimum
3655
07:04:46,170 --> 07:04:52,270
and the function accepts a list. And we're
times the minimum value in the list not only
3656
07:04:52,270 --> 07:04:58,220
the minimum value of the list, but also the
position of that minimum value. So find minimum
3657
07:04:58,220 --> 07:05:04,340
as well as find out Some minimum as well as
the position of the minimum in the list. So
3658
07:05:04,340 --> 07:05:09,540
how can we how can we solve that problem?
That's that's one standalone function, no
3659
07:05:09,540 --> 07:05:15,792
matter what list you pass in, it will find
the minimum. Okay? As long as the the minimum
3660
07:05:15,792 --> 07:05:21,110
is defined for the items of the list, for
example, the list items, or let's say all
3661
07:05:21,110 --> 07:05:27,170
the metrics, okay, how can we how can we do
that? Let's see, minimum value is the list.
3662
07:05:27,170 --> 07:05:32,660
Zero, that's let's say, the minimum value.
And right now the index at the minimum value
3663
07:05:32,660 --> 07:05:40,980
is, let's say, is zero. Okay? like we did
in the loops, like is, it is kind of the same
3664
07:05:40,980 --> 07:05:48,980
goal, but let's try it a function for it.
Okay. So that's the function fine, man. So
3665
07:05:48,980 --> 07:05:54,520
how can we how can we proceed? What should
we write here? Let's see a counter. Let's
3666
07:05:54,520 --> 07:06:07,400
see. Concrete let's or it may be that city
counter right now is zero for x in L. K, if
3667
07:06:07,400 --> 07:06:16,780
x is smaller than our minimum value, if that's
true, then the minimum value indeed is x.
3668
07:06:16,780 --> 07:06:24,091
And the index where we found that is high,
okay, great. Else do nothing I mean, else
3669
07:06:24,091 --> 07:06:33,850
just go away. And I plus equals one. So move
on. So AI is just the position so AI is moving
3670
07:06:33,850 --> 07:06:39,940
on and on and on. As you follow the list,
and M contains the minimum value and Id X
3671
07:06:39,940 --> 07:06:45,298
variable contains the position of the minimum
value. So that's the function for for readability,
3672
07:06:45,298 --> 07:06:53,320
we might be adding an else clause just write
balls. And that means the if condition finishes,
3673
07:06:53,320 --> 07:06:59,200
I'm in do if this condition holds true, do
that stuff, otherwise do nothing. That's just
3674
07:06:59,200 --> 07:07:04,170
because of readability. If you want, even
if you don't write the else clause and pass
3675
07:07:04,170 --> 07:07:08,000
statement, even then everything is fine. So
let's call this function just to test whether
3676
07:07:08,000 --> 07:07:14,850
this function is working properly or not.
So let's just find, oh, we haven't returned
3677
07:07:14,850 --> 07:07:21,090
anything. We need, we need the minimum value
as well as the index. So return a minimum
3678
07:07:21,090 --> 07:07:29,070
value as well as the position so return that.
Okay. Oh, but we do view returning that inside
3679
07:07:29,070 --> 07:07:34,500
the loop that becomes in the body of the loop.
Oh, no, no, no, no, no, that's bad. Because
3680
07:07:34,500 --> 07:07:38,680
even in the first iteration, the return will
be called an even in the first iteration,
3681
07:07:38,680 --> 07:07:44,270
the function will finish indentation, remember,
indentation. Now that's better. Now this is
3682
07:07:44,270 --> 07:07:51,100
no longer inside the body of the loop. Great.
That was a bug. We fixed it, right? Okay.
3683
07:07:51,100 --> 07:07:57,690
So let's go find, let's receive a B, so a
will contain the minimum value, and we will
3684
07:07:57,690 --> 07:08:04,270
contain the index of the minimum value. So
fine men, for example. And the list let's
3685
07:08:04,270 --> 07:08:18,560
let's give it the list. 13423409. Let's say
now the minimum value is zero. And that minimum
3686
07:08:18,560 --> 07:08:25,750
value appears that 0123. That's the third
index. So b should be three a should be zero.
3687
07:08:25,750 --> 07:08:35,890
So let's see, what's the value? What's the
result? So Brent? A, B? So A is zero? Yes.
3688
07:08:35,890 --> 07:08:41,960
And the position of minimum is three, I guess
it is working fine. rate. So that's one function,
3689
07:08:41,960 --> 07:08:51,430
find a minimum? Let's find another let's write
another function. Swap. So define. define
3690
07:08:51,430 --> 07:09:02,410
another function, let's say swap values. And
what we do is it it actually accepts two indices
3691
07:09:02,410 --> 07:09:10,378
index one that actually accepts list then
two indices, index one and index two. And
3692
07:09:10,378 --> 07:09:16,860
what it does is it actually swaps the value
of index. So index, one value should go to
3693
07:09:16,860 --> 07:09:21,520
index two position and index two value should
go to index one position in the same list,
3694
07:09:21,520 --> 07:09:26,810
and then it returns the list. Okay, great.
So it would it so so that's, that's a good
3695
07:09:26,810 --> 07:09:35,020
example it would, it accepts a list type variable,
it accepts index type variable which are integers.
3696
07:09:35,020 --> 07:09:38,260
Great. So
3697
07:09:38,260 --> 07:09:46,048
let's continue with let's define a variable
temp that contains l ID x index one, just
3698
07:09:46,048 --> 07:09:54,600
store it in a temporary variable, then at
this particular index, next one, just copy
3699
07:09:54,600 --> 07:10:04,720
this value. Don't worry, we'll see lists in
detail. Later on now list. Now at index one,
3700
07:10:04,720 --> 07:10:10,540
the value of index two is copied. But it is
not overwritten, because we already have saved
3701
07:10:10,540 --> 07:10:22,430
the value somewhere before that copying appears.
So l at ID x two is simply damp. And now return
3702
07:10:22,430 --> 07:10:31,220
the list. So that's how you can swap the two
values if you want. Great. So let's just check
3703
07:10:31,220 --> 07:10:38,770
it, whether the two values are swept or not.
So let's say list is 236. And seven, that's
3704
07:10:38,770 --> 07:10:49,440
a that's list. And let's say we want alto
that is swept values. And let's say we pass
3705
07:10:49,440 --> 07:10:57,001
the list and we want the values to be swept
at position one, and position three, which
3706
07:10:57,001 --> 07:11:02,782
may add position one, the value is three,
because the position starts from zero, and
3707
07:11:02,782 --> 07:11:06,480
at the third position, the value is seven.
So we want these to swap. So the result will
3708
07:11:06,480 --> 07:11:16,350
be 276. And three, let's see what's the result?
So let's print out two. And yeah, it works
3709
07:11:16,350 --> 07:11:23,878
great. What else? What else do we need? So
we have find a minimum function, we have swept
3710
07:11:23,878 --> 07:11:31,310
values function. What else? So yeah, what
should we do? Now let's write the main function
3711
07:11:31,310 --> 07:11:37,080
sorting. Let's write that function. And we
will call we will use these kinds of functions
3712
07:11:37,080 --> 07:11:44,650
inside that function when you call these functions.
So let's define sort list. Let's say that's
3713
07:11:44,650 --> 07:11:53,208
our function, it accepts a list and it returns
a sorted list. Okay, what should we do? What
3714
07:11:53,208 --> 07:11:58,320
do you think? What should we do for the very
first time? Well, first of all, we should
3715
07:11:58,320 --> 07:12:07,208
check whether all these list it contains the
list contains all the numeric values are not
3716
07:12:07,208 --> 07:12:11,050
let's say we're just doing this for numeric
values. So, we should first check the all
3717
07:12:11,050 --> 07:12:16,770
the arguments are are of numeric type or not,
for that, we should write a function that
3718
07:12:16,770 --> 07:12:21,600
should do that oh, remember that function
is all written in in a module remember that
3719
07:12:21,600 --> 07:12:30,760
module we made that module ourselves? So,
we can import that module if we want import?
3720
07:12:30,760 --> 07:12:38,020
My remember that my universal functions and
we just need that function we just need that
3721
07:12:38,020 --> 07:12:52,860
function one just from from my universal functions
import what import check if Numerix check
3722
07:12:52,860 --> 07:13:00,240
if not numeric, as you can write that function
name something else, but justice. So you import
3723
07:13:00,240 --> 07:13:06,000
that function. Now you may be able to use
that function. So after that, you can use
3724
07:13:06,000 --> 07:13:22,810
that function. If check, if not, numeric list
or remember that function returns true if
3725
07:13:22,810 --> 07:13:28,362
all the values are numeric, otherwise, it
returns false. So if it is true, then move
3726
07:13:28,362 --> 07:13:35,708
on the if it is not true. If it is not true,
what should you do? If it is not true? If
3727
07:13:35,708 --> 07:13:51,750
it is not true, then you might be printing
an error. Error. Last does not contain numeric
3728
07:13:51,750 --> 07:14:03,400
values, maybe that and then you just return.
Return. That's it. I mean, return. Don't need
3729
07:14:03,400 --> 07:14:10,310
to write anything in return. Fine. Great.
So else we need not to write else because
3730
07:14:10,310 --> 07:14:15,990
this return will take care of that but it
is for readability. That's good, right health.
3731
07:14:15,990 --> 07:14:21,300
If all are numeric, then what should we do?
Okay, what should we do? If all are numeric,
3732
07:14:21,300 --> 07:14:31,390
what we do is we will be doing what we will
be fine minimum. We'll be finding out the
3733
07:14:31,390 --> 07:14:39,070
minimum and then we will be swapping the minimum
from
3734
07:14:39,070 --> 07:14:46,270
what should we do what we we have already
a function find a minimum that we can call
3735
07:14:46,270 --> 07:14:50,958
just right away we have a function swap values
that we can call right away. We already have
3736
07:14:50,958 --> 07:14:56,240
used this function. How can we combine all
these functions? How can we use all these
3737
07:14:56,240 --> 07:15:06,160
functions just to achieve the problem sorting,
we want disorder list. How can you do that?
3738
07:15:06,160 --> 07:15:20,550
Okay. Yeah, that's, that's, it looks like
it looks like a different thing. Maybe? Maybe.
3739
07:15:20,550 --> 07:15:31,860
So, let's just write out, let's just for x
in the list, let's start thinking here for
3740
07:15:31,860 --> 07:15:40,210
every element that is in list for x and list
what should we do? We should we should find
3741
07:15:40,210 --> 07:15:48,670
out the minimum and slap the minimum with
x r. So, we should find out the minimum as
3742
07:15:48,670 --> 07:15:54,900
well as the index of the minimum and should
slap it with with the value x and everything
3743
07:15:54,900 --> 07:16:03,680
will become great. Yeah, I guess Yes. Okay.
So, what what we are going to do is we are
3744
07:16:03,680 --> 07:16:08,480
going to maintain a counter right now, the
counter is zero, which is just the index,
3745
07:16:08,480 --> 07:16:15,500
which we are going to do is we are going to
find out the minimum minimum and index where
3746
07:16:15,500 --> 07:16:24,060
the minimum lies. So, by find minimum in the
list, so, it will return us the minimum as
3747
07:16:24,060 --> 07:16:34,300
well as the index where the minimum lies and
then what we do is, we will say, Okay, okay,
3748
07:16:34,300 --> 07:16:53,490
what we want to do is, L is actually L is
swap, swap values with index see swap values
3749
07:16:53,490 --> 07:17:04,548
and list with index c. So, index c should
be swapped with ID x and C plus equals one,
3750
07:17:04,548 --> 07:17:15,900
will that work with that work? So, after this
will the will the whole list be sorted. So,
3751
07:17:15,900 --> 07:17:22,340
let's return the list is that true, I mean,
we are finding out the minimum value one by
3752
07:17:22,340 --> 07:17:32,191
one, the only catch is the list is updated
here. And, oh, there was a problem. When we
3753
07:17:32,191 --> 07:17:36,980
are finding out, when we are finding out the
minimum, we are finding out the minimum from
3754
07:17:36,980 --> 07:17:44,120
the list. And every time the same minimum
will be returned. That's a big problem. So,
3755
07:17:44,120 --> 07:17:50,860
looks like this fine minimum function is not
doing our job, what we need to do really is
3756
07:17:50,860 --> 07:18:01,370
the, we should go to find min function and
give it that start your stock your final minimum
3757
07:18:01,370 --> 07:18:08,720
from a particular index. So, don't don't search
the whole list to find the minimum, start
3758
07:18:08,720 --> 07:18:14,570
finding out the minimum from the following
index, for example. So let's give a start
3759
07:18:14,570 --> 07:18:20,292
index and maybe an end index. But let's give
a starting next. So start searching the minimum
3760
07:18:20,292 --> 07:18:25,240
from right from there. How can we change all
the code right now? Oh, that's bad thing.
3761
07:18:25,240 --> 07:18:36,128
Let's change the code. Let's say that's the
start index. Start index. That's it. This
3762
07:18:36,128 --> 07:18:51,490
the index right now is start index and I is
also start up VB we may use a range function
3763
07:18:51,490 --> 07:18:57,220
here, that might be much more feasible to
us. So let's use a range function. Rather
3764
07:18:57,220 --> 07:19:01,570
than this let's change the coding a whole
lot. That's a bad thing we need to change
3765
07:19:01,570 --> 07:19:07,480
the code for i in range
3766
07:19:07,480 --> 07:19:17,890
starting from start index, starting starting
from start index, ending at length of the
3767
07:19:17,890 --> 07:19:31,760
list and doing a step of one Okay. Now x really
is x is really list at the index i okay if
3768
07:19:31,760 --> 07:19:38,628
x is smaller than m then this is that an index
is AI. Otherwise this we need not to do this
3769
07:19:38,628 --> 07:19:45,458
because this is this is happening automatically.
And rest of the story is same, I guess Yes.
3770
07:19:45,458 --> 07:19:51,690
That will work out. Okay, great. Oh, there
is a problem. Oh, we just missed this column
3771
07:19:51,690 --> 07:20:00,480
here. Great. We fix it. Okay. Now, so if value
is there, maybe this works. Maybe Doesn't
3772
07:20:00,480 --> 07:20:06,770
maybe there is a bug. Let's see, let's let's
just call this function. So let's call this
3773
07:20:06,770 --> 07:20:23,960
function l two is sort list. And let's pass
the list as to 153. Minus 870. Let's see.
3774
07:20:23,960 --> 07:20:31,208
That's boss this list and see what it returns.
If it returns fine, we might be happy. Otherwise,
3775
07:20:31,208 --> 07:20:37,622
we will see where is the bug? If there is
a bug, oh, this does not contain numeric values.
3776
07:20:37,622 --> 07:20:46,950
Why not? list does not contain numeric values.
Why is that happening? bliss actually contains
3777
07:20:46,950 --> 07:20:53,850
all the American values. We read the problem,
check if not numeric, let's see the let's
3778
07:20:53,850 --> 07:21:02,100
see the implementation of check if not numeric.
Let's see that. Check. If not numeric, let's
3779
07:21:02,100 --> 07:21:10,218
see the implementation. And there is the bug.
Because all these are numeric. So check if
3780
07:21:10,218 --> 07:21:19,490
not numeric x in arcs, if not is instance
then return false. So if everything is int
3781
07:21:19,490 --> 07:21:30,070
or float, so if x is int or float, then return
otherwise return true. So it returns true
3782
07:21:30,070 --> 07:21:44,220
if all our if all our numerix. So it returns
true if all our Numerix so not true means
3783
07:21:44,220 --> 07:21:52,580
false. And why why does Why does returning
for us? So that is just was let us just see
3784
07:21:52,580 --> 07:21:58,450
why it is returning false. That's that's the
bad news that something is happening wrong.
3785
07:21:58,450 --> 07:22:16,660
Let us just see how this is working. So that
is just check. Check, if not numeric. And
3786
07:22:16,660 --> 07:22:22,990
let's pass the list this list. And let's see
what is returned. Let's just print the return
3787
07:22:22,990 --> 07:22:32,910
thing. But it is either true or false. So
it returns a false why it is returning a false.
3788
07:22:32,910 --> 07:22:41,300
It is a bad thing. Why does they're turning
a false? Let's go to the File. Let's go to
3789
07:22:41,300 --> 07:22:51,040
the File. Here. Sorry. Let's go to the File.
Here in this directory. Let's open up this.
3790
07:22:51,040 --> 07:22:57,410
Maybe open this in simply an old bad. Maybe
an old bad, why not? Or maybe some other fancy
3791
07:22:57,410 --> 07:23:11,610
editor. Let's open this up and see what is
happening. ad format font, let's have a bigger
3792
07:23:11,610 --> 07:23:16,250
follow on and see what is happening.
3793
07:23:16,250 --> 07:23:30,290
Self face one of 20 bugs are bad, they're
really bad for x and ogs. Okay? If not is
3794
07:23:30,290 --> 07:23:39,680
in stance. So first of all is in stance this,
it will return true always okay. If not true,
3795
07:23:39,680 --> 07:23:44,299
which means false. Then we'll move on and
the loop will be running if anywhere you where
3796
07:23:44,299 --> 07:23:45,299
it is finding out where it is finding out
basically. So this this is working really
3797
07:23:45,299 --> 07:23:46,299
fine. Let's, let's let's write this function
somewhere inside our notebook and see what
3798
07:23:46,299 --> 07:23:47,299
is let's say rather than this. Let's say this
function like check the metric to check numeric
3799
07:23:47,299 --> 07:23:48,299
to check it not numeric to let's call that
function and see what happens check numeric
3800
07:23:48,299 --> 07:23:49,299
to it is returning false again. Why does returning
false? That's amazing. Where is the false?
3801
07:23:49,299 --> 07:23:50,299
So two is integer? Yes. One is integer. Yes.
So true. True. True. True. All these are true.
3802
07:23:50,299 --> 07:23:51,299
OH minus eight might be a problem. minus eight
might be a problem. Let's see. Maybe. I don't
3803
07:23:51,299 --> 07:23:52,299
know. Well, well, there is still false. I
mean, I'm stuck here. Guys. I'm stuck here.
3804
07:23:52,299 --> 07:23:53,299
I don't know what to do. I don't know what
to do. I have to debug this function, I have
3805
07:23:53,299 --> 07:23:54,299
to go inside that function and see what is
happening. So what we really are eggs. Oh
3806
07:23:54,299 --> 07:23:55,299
my god, the big trouble big trouble. Yeah,
I found the air. We are passing a list. And
3807
07:23:55,299 --> 07:23:56,299
that list is just one argument. That is not
a lot of arguments we have to pass all these
3808
07:23:56,299 --> 07:23:57,299
arguments in in a different way. I mean, if
you want to, you're getting you're getting
3809
07:23:57,299 --> 07:23:58,299
the bug, the bug is we're passing one variable,
not a lot of them 2153 817 these are not all
3810
07:23:58,299 --> 07:23:59,299
different variables. For example, if we just
go inside and print x, for just first x, it
3811
07:23:59,299 --> 07:24:00,299
is the all it is all the it is all the list.
It is all the list. It is not the variables
3812
07:24:00,299 --> 07:24:01,299
one by one. Let's see. Yeah, I found the bug.
Found the bug. Wait. Yeah, see, it is not?
3813
07:24:01,299 --> 07:24:02,299
It is not a lot of it is not a lot of variables.
It is not a lot of arguments. It is just one
3814
07:24:02,299 --> 07:24:03,299
argument that is in the form of placed variable.
That's incredible. What should we do? Should
3815
07:24:03,299 --> 07:24:04,299
we go inside and add another function check
if not Americ for lists, rather than variable
3816
07:24:04,299 --> 07:24:05,299
number of arguments. What should we do? Let's
write another function that check for the
3817
07:24:05,299 --> 07:24:06,299
list. Let's write here check numeric to it
contains the list for exam just accepts list
3818
07:24:06,299 --> 07:24:07,299
ello or maybe l or whatever x or art just
simply, you can call the or l list. And it
3819
07:24:07,299 --> 07:24:08,299
goes through all the list. And does does the
same job as previous. So now this will work.
3820
07:24:08,299 --> 07:24:09,299
So the function that was there in our module
is no longer working, and it will not work.
3821
07:24:09,299 --> 07:24:10,299
So we are not going to use the function that
is in the module, we are going to write another
3822
07:24:10,299 --> 07:24:11,299
function that will help us here. And we have
written that, and here we go. It just chained
3823
07:24:11,299 --> 07:24:12,299
that function to that. And we just we just
throw that out again. And let's see what happens
3824
07:24:12,299 --> 07:24:13,299
now. Oh, there was another error whichever.
Find a man missing one o v v did not find
3825
07:24:13,299 --> 07:24:14,299
this fireman is missing the starting index.
So the starting index is C rate.
3826
07:24:14,299 --> 07:24:15,299
Right? That's a problem. That's a huge problem.
Let's just sorted Oh, my god list finally
3827
07:24:15,299 --> 07:24:16,299
is sorted. Oh, huge, huge, huge. So you see,
you can call the functions inside other functions,
3828
07:24:16,299 --> 07:24:17,299
you can call the functions from modules. If
they are no longer working or no longer beneficial
3829
07:24:17,299 --> 07:24:18,299
for you, you can write new functions, you
can call them you can. Yeah, all that stuff.
3830
07:24:18,299 --> 07:24:19,299
I guess that that lengthy video taught you
a lot of lessons, how to how to code actually.
3831
07:24:19,299 --> 07:24:20,299
And this actually happens when you are doing
tasks that are really big. You have to define
3832
07:24:20,299 --> 07:24:21,299
different functions, you need to define different
functions for modular approach, and focus
3833
07:24:21,299 --> 07:24:22,299
on each function as a separate entity. And
that that makes much simplicity in managing
3834
07:24:22,299 --> 07:24:23,299
the code and bug fixing and all that stuff.
You see, I fixed the bug by just noticing
3835
07:24:23,299 --> 07:24:24,299
that just by just focusing on this function.
I have not thought anything else, just focus
3836
07:24:24,299 --> 07:24:25,299
on that function go and see the implementation
fix that everything else stays the same. Yeah,
3837
07:24:25,299 --> 07:24:26,299
so too lengthy a swap here. Okay, now you
have done a lot of practice about functions,
3838
07:24:26,299 --> 07:24:27,299
loops, and a lot of stuff. That was all the
basic programming in Python. In the in the
3839
07:24:27,299 --> 07:24:28,299
next video, from the next video, we will see
the real power, a much more real power of
3840
07:24:28,299 --> 07:24:29,299
Python where you need not write a lot of loops
and a lot of gold and still you will be able
3841
07:24:29,299 --> 07:24:30,299
to achieve a lot of stuff. And for that we
need to go through the data structures that
3842
07:24:30,299 --> 07:24:31,299
are available in Python. So from the very
next video, we will start seeing strengths
3843
07:24:31,299 --> 07:24:32,299
that study or structure we will see less in
detail we will see set in detail we will see
3844
07:24:32,299 --> 07:24:33,299
dictionary in detail we will see tuples in
detail. And after going through all these
3845
07:24:33,299 --> 07:24:34,299
data structures and getting a good grip for
the data structures. Then finally we will
3846
07:24:34,299 --> 07:24:35,299
move we will move to the packages that are
available for data science, particularly NumPy,
3847
07:24:35,299 --> 07:24:36,299
pandas matplotlib. And we will see maybe I
include maybe I include one or two videos
3848
07:24:36,299 --> 07:24:37,299
for psychic learn as well. So hope to see
you For the whole new phase in Python, the
3849
07:24:37,299 --> 07:24:38,299
data structures, so we'll hope to see in the
next video. Okay, let's dive into the long
3850
07:24:38,299 --> 07:24:39,299
awaited strings. string is basically just
a sequence of characters. And it's a data
3851
07:24:39,299 --> 07:24:40,299
type, it's kind of a data type. In Python,
it's much more powerful. The reason, the reason
3852
07:24:40,299 --> 07:24:41,299
of, I mean, making this a whole new data type
in, in almost every language is, the reason
3853
07:24:41,299 --> 07:24:42,299
is that almost all the data all the text that
appears in sequence of characters, so making
3854
07:24:42,299 --> 07:24:43,299
that sequence of corrector, the whole text
as one kind of data type, and writing special
3855
07:24:43,299 --> 07:24:44,299
kind of functions to, to deal with that text
might be necessary. And that's what the string
3856
07:24:44,299 --> 07:24:45,299
is. In Python, for example, you can declare
a string variable s, or any variable name,
3857
07:24:45,299 --> 07:24:46,299
by just double quotes, let's say ABC, are
our equal monthly by a single quotes, either
3858
07:24:46,299 --> 07:24:47,299
way is fine, d f. So either way is fine, you
can declare using double quotes, or single
3859
07:24:47,299 --> 07:24:48,299
quotes, either way is fine. One thing is,
be careful, don't mix. I mean, don't start
3860
07:24:48,299 --> 07:24:49,299
by a single quote, and think that now I will
end with double quote, and that will be fine.
3861
07:24:49,299 --> 07:24:50,299
So don't mix them together. If you're using
single quotes, use single quotes, if you're
3862
07:24:50,299 --> 07:24:51,299
using double quotes, use double quotes, don't
mix them together, that might be much more
3863
07:24:51,299 --> 07:24:52,299
confusing later on. So let's say this S is
a string, Python is the best language for
3864
07:24:52,299 --> 07:24:53,299
data science. That's a D is another string
that is defined by single quotes. In this
3865
07:24:53,299 --> 07:24:54,299
course, we are going to learn Python, then
you can print s, different in a different
3866
07:24:54,299 --> 07:24:55,299
way, let's say you will call you can call
a brand s, you can call a print to D. Or you
3867
07:24:55,299 --> 07:24:56,299
can just by the way, you can you can add two
string variables s and D. And the result is
3868
07:24:56,299 --> 07:24:57,299
a new variable. That's how the plus symbol
works in strings is plus in strings means
3869
07:24:57,299 --> 07:24:58,299
just concatenate concatenate them together.
So first, you just copy this string, the whole
3870
07:24:58,299 --> 07:24:59,299
string, and then you just concatenate the
other string with it. And the result is a
3871
07:24:59,299 --> 07:25:00,299
new string. Now that's a new variable, you
can use that variable and do a lot of stuff
3872
07:25:00,299 --> 07:25:01,299
with it. So let's go to Python and see actually,
the brains in in the strings in in the running
3873
07:25:01,299 --> 07:25:02,299
form. So let's say S is
3874
07:25:02,299 --> 07:25:03,299
string, let's say, right on is good language,
let's say. And let's have another string T,
3875
07:25:03,299 --> 07:25:04,299
that is using single quotes. It's good for
data science, sci fi. Okay, it's good for
3876
07:25:04,299 --> 07:25:05,299
data science, let's run these two, and see
the type of s was the type of s. The type
3877
07:25:05,299 --> 07:25:06,299
is str string, str, that's what the type is.
And if you just print s, that will be printed.
3878
07:25:06,299 --> 07:25:07,299
Python is a good language. Remember, so far,
we are using this sprint. And always we use
3879
07:25:07,299 --> 07:25:08,299
this kind of Hello or something like that.
That basically is a string because by the
3880
07:25:08,299 --> 07:25:09,299
way, the sprint function, actually, it takes
an arbitrary number of arguments, we can print
3881
07:25:09,299 --> 07:25:10,299
hello, then we can print anything in another
type, then we can print another Hello, let's
3882
07:25:10,299 --> 07:25:11,299
say hello to hello to that's a multi multi
variable argument function print, then we
3883
07:25:11,299 --> 07:25:12,299
can have another string maybe Who are you.
And then maybe a floating point number 5.9.
3884
07:25:12,299 --> 07:25:13,299
So we we have used these kind of, we have
used these kind of, I mean stuff a lot. We
3885
07:25:13,299 --> 07:25:14,299
have used print function. And we were using
these double quotes again and again. But but
3886
07:25:14,299 --> 07:25:15,299
these are actually strings that we will be
that we were using later there. So the spring
3887
07:25:15,299 --> 07:25:16,299
function actually accept strings and all these
kind of Normally, the whenever you use print,
3888
07:25:16,299 --> 07:25:17,299
normally you're using it normally you're going
to actually display some text, and maybe you're
3889
07:25:17,299 --> 07:25:18,299
writing that text into some file and so on.
So this string is highly, highly useful. Most
3890
07:25:18,299 --> 07:25:19,299
of the data is available in the text form
in the screen form. And we want to process
3891
07:25:19,299 --> 07:25:20,299
the data we want to find the anomalies in
data, we want to fix them again, we want to
3892
07:25:20,299 --> 07:25:21,299
stay in the text. So it is good to have a
data type that actually have a lot of functionality
3893
07:25:21,299 --> 07:25:22,299
that handles all that stuff. So Let's see,
for example, another another, let's see how
3894
07:25:22,299 --> 07:25:23,299
can we concatenate the two strings, for example,
SMT. Let's say we have B, that is s plus T,
3895
07:25:23,299 --> 07:25:24,299
that's concatenated. B. And that's francqui.
And we is going to get an ad. While bicon
3896
07:25:24,299 --> 07:25:25,299
is a good language. It's good for data science.
Well, it is concatenated. But there is no
3897
07:25:25,299 --> 07:25:26,299
space between two because wherever the first
string ends, the second string starts right
3898
07:25:26,299 --> 07:25:27,299
from there. What if we can get in a three
strings? s plus another string that just contains
3899
07:25:27,299 --> 07:25:28,299
a space corrector? Then this string? Why do
we whatever that is there in double quotes,
3900
07:25:28,299 --> 07:25:29,299
or single quotes, whatever, one corrector
to track character, all these things are called
3901
07:25:29,299 --> 07:25:30,299
strings. So now we are concatenated, three
strings together as a space, one space string
3902
07:25:30,299 --> 07:25:31,299
that contains just a space greater than T.
And let's see what happens now. So Python
3903
07:25:31,299 --> 07:25:32,299
is a good language space, it's good for data
science and so on. Well, so
3904
07:25:32,299 --> 07:25:33,299
yeah, so that's basically the introduction
of string. What if we want for example, to
3905
07:25:33,299 --> 07:25:34,299
concatenate? What if we want, we have a variable
A, which is 12. And let's say we have variable
3906
07:25:34,299 --> 07:25:35,299
b, which is the price of this book, let's
say the price of this book, and a is 12. So
3907
07:25:35,299 --> 07:25:36,299
let's say this is our price. Now price is
in integer form S is in book form, let's say
3908
07:25:36,299 --> 07:25:37,299
we want to make another string we, that contains
the following kind of thing, the price of
3909
07:25:37,299 --> 07:25:38,299
this book is and then whatever the private
price is, that should be there. So what how
3910
07:25:38,299 --> 07:25:39,299
can we do that? So let's say s, plus, maybe,
maybe another string is then maybe a space.
3911
07:25:39,299 --> 07:25:40,299
So that after that the price appears? Now,
if we right plus and right price, price is
3912
07:25:40,299 --> 07:25:41,299
no longer a string, it is an integer, and
an integer cannot be concatenated the string
3913
07:25:41,299 --> 07:25:42,299
in a straightforward way, like plus, how can
we how can we make a message like the the
3914
07:25:42,299 --> 07:25:43,299
price of this book is, whatever the value
of the price is, one way to do that is to
3915
07:25:43,299 --> 07:25:44,299
convert the variable price, the Convert the
type of the variable of price, from integer
3916
07:25:44,299 --> 07:25:45,299
to string, that means whatever the value,
in this case, 12 is written, that becomes
3917
07:25:45,299 --> 07:25:46,299
a string of characters one and two. And now
it can be concatenated with with the rest
3918
07:25:46,299 --> 07:25:47,299
of the string, and we will contain the message
that we want. For example, if we now see what
3919
07:25:47,299 --> 07:25:48,299
is free, that is, the price of this book is
this book is 12. Oh, we don't have a space
3920
07:25:48,299 --> 07:25:49,299
before. So let's let's type a space, their
space is also a corrector can be handled in
3921
07:25:49,299 --> 07:25:50,299
strength, while so that's how we can convert
different types to string. We can have a float
3922
07:25:50,299 --> 07:25:51,299
type, we can convert that to string, and so
on. Another way of doing the same or achieving
3923
07:25:51,299 --> 07:25:52,299
the same kind of stuff is to write Brent,
the price of this book is I mean, we can use
3924
07:25:52,299 --> 07:25:53,299
the power of the variable number of arguments
of then price, that's exactly the same thing.
3925
07:25:53,299 --> 07:25:54,299
The price of this book is 12, the price of
this book, however, consider one thing, the
3926
07:25:54,299 --> 07:25:55,299
print function automatically adds the space
for different kinds of arguments. You can
3927
07:25:55,299 --> 07:25:56,299
see that here, yeah, you need not to specify
a specifier space, the space is automatically
3928
07:25:56,299 --> 07:25:57,299
added if it is if it is considered to be a
different argument in the print function.
3929
07:25:57,299 --> 07:25:58,299
Okay, great. So that's the introduction of
a string. We are going to explore string much
3930
07:25:58,299 --> 07:25:59,299
in in much more detail in the upcoming video,
so stay with us, we are going to see a string
3931
07:25:59,299 --> 07:26:00,299
in much more detail. Okay, hope to see you
in the next video. A string might be very
3932
07:26:00,299 --> 07:26:01,299
lengthy, or may span I'm in very lengthy and
may span more than one lines. Or maybe the
3933
07:26:01,299 --> 07:26:02,299
formatting is in a way that you want to even
if even if it is not very lengthy, you will
3934
07:26:02,299 --> 07:26:03,299
still want the different chunks of the same
string to be appear in different lines. So
3935
07:26:03,299 --> 07:26:04,299
there is a way to declare multi line strength
again using either three single quotes or
3936
07:26:04,299 --> 07:26:05,299
three double quotes. And then three double
quotes or single quotes. Whatever convention
3937
07:26:05,299 --> 07:26:06,299
you follow Then you write all the string in,
no matter how many lines you want, and that
3938
07:26:06,299 --> 07:26:07,299
one variable actually contains a multi line
string. If you now print, for example, if
3939
07:26:07,299 --> 07:26:08,299
you call the print function on this multi
line, that that's By the way, a variable name,
3940
07:26:08,299 --> 07:26:09,299
multi line string that contains this data,
multi line, multi, multi line that now the
3941
07:26:09,299 --> 07:26:10,299
spelling our Spelling's around here, I just
created multi line anyways, if you if you
3942
07:26:10,299 --> 07:26:11,299
call that print function, this will the print
will display the string as it is like it is
3943
07:26:11,299 --> 07:26:12,299
there. So let's see the and by the way that
the same multi line string kind of fashioned
3944
07:26:12,299 --> 07:26:13,299
remember that that is used for comments as
well. If you have comments that span on multiple
3945
07:26:13,299 --> 07:26:14,299
lines, you can use this. So this multi line
string really is if it is not saved in a variable
3946
07:26:14,299 --> 07:26:15,299
and used as it is somewhere in the code, then
that acts as a multi line comment. Great.
3947
07:26:15,299 --> 07:26:16,299
So let's practice the multi line string in
in Jupyter. notebook. Let's see. So let's
3948
07:26:16,299 --> 07:26:17,299
say we have a variable A that is multi line
string. And let's say the spring is this is
3949
07:26:17,299 --> 07:26:18,299
line one.
3950
07:26:18,299 --> 07:26:19,299
Then we have this is line two, and then we
have this is last line. And this line is three.
3951
07:26:19,299 --> 07:26:20,299
That's it. Okay, great. That's a multi line
string. Let's see. How can it Brent a, what
3952
07:26:20,299 --> 07:26:21,299
happens? So this is line one, this is line
two, this is last line and this line is three?
3953
07:26:21,299 --> 07:26:22,299
Why this? The first this is shifted one corrector,
right? Oh, there is a space here. Let's remove
3954
07:26:22,299 --> 07:26:23,299
that space if not required. And run this again.
While because space is a corrector that will
3955
07:26:23,299 --> 07:26:24,299
be printed if you want. Okay, what if you
really want really want the following kind
3956
07:26:24,299 --> 07:26:25,299
of stuff, you have, let's say brand. So what
you really do is you want to bring the following
3957
07:26:25,299 --> 07:26:26,299
the following options are available. And the
options are, let's say dab, dab, dab, let's
3958
07:26:26,299 --> 07:26:27,299
see a hyphen, a. And that does play from a
that does nothing. And then we have let's
3959
07:26:27,299 --> 07:26:28,299
say hyphen B and they're also also does nothing.
Let's say you want our message to be painted
3960
07:26:28,299 --> 07:26:29,299
in in such a way, what will happen? Let's
see. Okay, the following options are available
3961
07:26:29,299 --> 07:26:30,299
hyphenate has nothing hyphen B I mean, all
this is a string multi line string, these
3962
07:26:30,299 --> 07:26:31,299
crackers that you think they are not there,
these are spaces and they are I mean the spaces
3963
07:26:31,299 --> 07:26:32,299
are painted here, the spaces are painted here,
we are saying nothing is printed, these are
3964
07:26:32,299 --> 07:26:33,299
the spaces that are printed there. So sometimes
this multi line string, it helps to format
3965
07:26:33,299 --> 07:26:34,299
our message in a way that we like. So that's
how helpful in most of the cases further if
3966
07:26:34,299 --> 07:26:35,299
you write this multi line, by the way, if
you write this multi line, comment in the
3967
07:26:35,299 --> 07:26:36,299
start and end of any good script. That means
the if you write this multi line way of defining
3968
07:26:36,299 --> 07:26:37,299
the strings at the start and end of any good
script, that code script is commented that
3969
07:26:37,299 --> 07:26:38,299
we have seen several times earlier as well.
So, for example, in problem solving, remember
3970
07:26:38,299 --> 07:26:39,299
that we define all? Oh yeah. So that's the
comment. That's a comment. Even if some code
3971
07:26:39,299 --> 07:26:40,299
is written inside that will not be executed.
Right. Okay, so that's about the multi line
3972
07:26:40,299 --> 07:26:41,299
string. In the next video we will see because
because the string really is, is basically
3973
07:26:41,299 --> 07:26:42,299
a collection of all these characters. What
if we want to access a particular character?
3974
07:26:42,299 --> 07:26:43,299
For example, this is the first graduate is
d here, the second Gregory is at the third
3975
07:26:43,299 --> 07:26:44,299
correct? Is it the fourth record is S, the
fifth Gregory space and all? What if we want
3976
07:26:44,299 --> 07:26:45,299
to access particular characters inside the
string? Because the string contains a lot
3977
07:26:45,299 --> 07:26:46,299
of directors? What if we want to play with
some of the directors inside the string? How
3978
07:26:46,299 --> 07:26:47,299
can we access different directors for example,
if we want to access seventh director of the
3979
07:26:47,299 --> 07:26:48,299
string, how can we do that? So, let's see
in the next video, how can we index different
3980
07:26:48,299 --> 07:26:49,299
characters inside a string, I hope to see
you in the next video. Okay, in this video,
3981
07:26:49,299 --> 07:26:50,299
we are going to actually access different
characters inside the string, sometimes called
3982
07:26:50,299 --> 07:26:51,299
indexing, the term slicing is basically more
relevant to arrays, lists are actually the
3983
07:26:51,299 --> 07:26:52,299
immutable structures, but we will see,
3984
07:26:52,299 --> 07:26:53,299
I'm just comparing, because you may listen
this term slicing again and again, but really
3985
07:26:53,299 --> 07:26:54,299
this indexing but we will see the indexing
or slicing sometimes is you these two terms
3986
07:26:54,299 --> 07:26:55,299
are used interchangeably, we will see the
examples of slicing in detail in lists. And,
3987
07:26:55,299 --> 07:26:56,299
and in more detail in NumPy arrays. But here,
you just think that indexing and slicing are
3988
07:26:56,299 --> 07:26:57,299
the same things. index. So for example, I
have this a let's say this is a array, and
3989
07:26:57,299 --> 07:26:58,299
I want to access its fourth element here,
the fourth corrector element is E. By the
3990
07:26:58,299 --> 07:26:59,299
way, this a is a variable, if I want to access
the very first corrector the the indexing
3991
07:26:59,299 --> 07:27:00,299
the number, the positioning starts from the
integer zero, that's the first corrector.
3992
07:27:00,299 --> 07:27:01,299
So if I want to print out of it, that will
print g if I access for example, if I write
3993
07:27:01,299 --> 07:27:02,299
the index three, what do we mean that means
the fourth element, the fourth element is
3994
07:27:02,299 --> 07:27:03,299
he what will be printed, what will be printed,
if I access the fourth element of the index
3995
07:27:03,299 --> 07:27:04,299
for a fi access this thing or space will be
printed and you will be seeing nothing because
3996
07:27:04,299 --> 07:27:05,299
when a space is printed, actually, nothing
colorful is printed there and you might be
3997
07:27:05,299 --> 07:27:06,299
thinking Oh, nothing is printed, nothing,
nothing has been accessed, actually a space
3998
07:27:06,299 --> 07:27:07,299
corrector have been accessed. So yeah, a more
we can we can we can actually access, we can
3999
07:27:07,299 --> 07:27:08,299
actually access a substring inside a string
as well. For example, we want to access for
4000
07:27:08,299 --> 07:27:09,299
example, a substring starting from index three,
and all the way up to index eight, but does
4001
07:27:09,299 --> 07:27:10,299
not include the index eight. So it will include
the corrector at index three, which is he
4002
07:27:10,299 --> 07:27:11,299
correctly at index four, which is space, let
me write space in this way. Director at index
4003
07:27:11,299 --> 07:27:12,299
five, which is Oh, correct, read index six,
next record, which is F, then a space, which
4004
07:27:12,299 --> 07:27:13,299
is seven, and then the correct read eight.
And so this is not included, to be accessed.
4005
07:27:13,299 --> 07:27:14,299
This is included, this is inside, this is
included. This is not included. So we can
4006
07:27:14,299 --> 07:27:15,299
access a substring. So starting from three
and ending at eight. Let's see, let's see
4007
07:27:15,299 --> 07:27:16,299
an example. And you'll come back to this slide
again, after after a few minutes. So let's
4008
07:27:16,299 --> 07:27:17,299
say we have a spring as let's say, how are
you? And who are you? That's it. So let's
4009
07:27:17,299 --> 07:27:18,299
do that. So spring, okay. And what do we really
want is we want to access for example, the,
4010
07:27:18,299 --> 07:27:19,299
we want to access the element to access the
elements, you have to write the square brackets.
4011
07:27:19,299 --> 07:27:20,299
That's a standard notation. In Python. Whenever
you have a collection and you want to access
4012
07:27:20,299 --> 07:27:21,299
different elements, that collection might
be a string that collection later on, we will
4013
07:27:21,299 --> 07:27:22,299
see might be a list. Maybe a tupple dictionary
may be a set. Maybe a NumPy array may be a
4014
07:27:22,299 --> 07:27:23,299
panda's structure, I mean, anything that is
a collection, normally it is accessed by It
4015
07:27:23,299 --> 07:27:24,299
has different elements, and we want to index
them. The indexing division is square brackets.
4016
07:27:24,299 --> 07:27:25,299
And indexing always starts from zero rather
than one. In Python. There are some languages
4017
07:27:25,299 --> 07:27:26,299
in which the indexing starts from one for
example, MATLAB, the indexing starts from
4018
07:27:26,299 --> 07:27:27,299
one but in Python and in several other languages.
The indexing starts from zero, which has some
4019
07:27:27,299 --> 07:27:28,299
benefits or starting with one it has some
benefits. So starting with zero is okay is
4020
07:27:28,299 --> 07:27:29,299
okay. So let's say we want to access element
at index five. The element at index five is
4021
07:27:29,299 --> 07:27:30,299
actually the sixth element in the string starting
from zero. So first, second, third, fourth,
4022
07:27:30,299 --> 07:27:31,299
fifth, sixth, so our will be printed. So let's
see. Our is printed. Let's check the let's
4023
07:27:31,299 --> 07:27:32,299
check the type of this return value. Let's
check the type of this this one element which
4024
07:27:32,299 --> 07:27:33,299
is our what is the type of it subtype of different
elements in a string different characters
4025
07:27:33,299 --> 07:27:34,299
in a string? What are the types
4026
07:27:34,299 --> 07:27:35,299
So what is the type of it. So the type is
also string. So each and every corrector is
4027
07:27:35,299 --> 07:27:36,299
also of string type. In some other languages,
the type might be a corrector. corrector is
4028
07:27:36,299 --> 07:27:37,299
another type, but in, in Python, each and
every one character is also a string. More
4029
07:27:37,299 --> 07:27:38,299
than one. correctness is also string, as long
as they are accessed from a string. Okay,
4030
07:27:38,299 --> 07:27:39,299
let's access for example, the element number
three to element number, let's say eight.
4031
07:27:39,299 --> 07:27:40,299
So the result is our so element number three,
not three, actually starting from index three,
4032
07:27:40,299 --> 07:27:41,299
which means the fourth vector, which is space,
and then e, r, e, and then space, and then
4033
07:27:41,299 --> 07:27:42,299
we finish. if you for example, move to from
three to nine, let's say, and the the rally
4034
07:27:42,299 --> 07:27:43,299
will be our why or we may move to from for
example, we may start from the very beginning.
4035
07:27:43,299 --> 07:27:44,299
So for example, index zero, we may end at
the index 10, but not including the 10. So
4036
07:27:44,299 --> 07:27:45,299
the result is, how are you and then I mean,
why Oh, and not the you included, because
4037
07:27:45,299 --> 07:27:46,299
that's index number 10. And index number 10.
The last index is not included. Great. We
4038
07:27:46,299 --> 07:27:47,299
can have negative indices in strings as well.
So a negative index is just just the indexing
4039
07:27:47,299 --> 07:27:48,299
from the right side, not from the left side,
for example, on negative index. So minus one
4040
07:27:48,299 --> 07:27:49,299
points to the last corrector. For example,
you similarly minus two points to the second
4041
07:27:49,299 --> 07:27:50,299
last corrector, and so on. So minus one, that's
a success, you. And similarly, we have minus
4042
07:27:50,299 --> 07:27:51,299
three, and that will access why, or we may
have start from let's say, minus, start from
4043
07:27:51,299 --> 07:27:52,299
let's say, minus eight, and go till minus
three, that means go back to go back to minus
4044
07:27:52,299 --> 07:27:53,299
eight index, and then move to minus three
index, okay? And minus three. In this case,
4045
07:27:53,299 --> 07:27:54,299
let's see what was the result are, what is
that? Why are? Oh, this are, I guess this
4046
07:27:54,299 --> 07:27:55,299
are? Let's check it out. So this is this,
you, this is minus one minus two minus three,
4047
07:27:55,299 --> 07:27:56,299
that's an X number three. So three is not
included. minus three is not included. So
4048
07:27:56,299 --> 07:27:57,299
it has to stop here. Okay. That's minus four
minus five minus six, minus seven and minus
4049
07:27:57,299 --> 07:27:58,299
eight. Oh, great. So that should be printed,
it has printed. So let's say we have rather
4050
07:27:58,299 --> 07:27:59,299
than minus eight, we start from minus 12,
and be raised to minus three. So we're okay.
4051
07:27:59,299 --> 07:28:00,299
Great. So we have negative indices as well.
And by the way, this kind of fetching this
4052
07:28:00,299 --> 07:28:01,299
kind of substring is sometimes called slicing,
I mean, we are just fetching the slicing,
4053
07:28:01,299 --> 07:28:02,299
although the term slicing is much more popular
in, in in mutable data structures. What What
4054
07:28:02,299 --> 07:28:03,299
is a mutable data structure? What is an immutable
data structure? Well, yeah, I should tell
4055
07:28:03,299 --> 07:28:04,299
you right now, you can change, you can not
change any corrector in the spring. That might,
4056
07:28:04,299 --> 07:28:05,299
that might look like a bad news for you. But
once the spring is created, the elements in
4057
07:28:05,299 --> 07:28:06,299
the strings are not changeable. So for example,
let's say at position number one, you want
4058
07:28:06,299 --> 07:28:07,299
to place a corrector. Let's see, that's not
possible. And the reason is, the string is
4059
07:28:07,299 --> 07:28:08,299
a data structure, the string is a variable
type a data type that is immutable, immutable,
4060
07:28:08,299 --> 07:28:09,299
are unchangeable. Once created, you cannot
change its contents, they stay fixed, you
4061
07:28:09,299 --> 07:28:10,299
cannot change them, you cannot alter them,
you you cannot delete certain contents from
4062
07:28:10,299 --> 07:28:11,299
it. I mean, once created, it stays as it is,
you can copy this into another string, you
4063
07:28:11,299 --> 07:28:12,299
can copy and paste, but you can get a substring
and copy into another variable, for example,
4064
07:28:12,299 --> 07:28:13,299
but the contents of s cannot be changed.
4065
07:28:13,299 --> 07:28:14,299
So all the kinds of data types in Python that
are unchangeable, the contents are not changeable.
4066
07:28:14,299 --> 07:28:15,299
They're called immutable. And string is immutable.
So so the the time slicing makes much more
4067
07:28:15,299 --> 07:28:16,299
I mean sense or it is more popular in the
data structures that are mutable, that are
4068
07:28:16,299 --> 07:28:17,299
mutable, although, you can use time slicing
indexing both interchangeably. But it refers
4069
07:28:17,299 --> 07:28:18,299
to roughly in reference to fetching the sub
structure or substring. In this case, in the
4070
07:28:18,299 --> 07:28:19,299
list, it will be a sub list or so on. So that's
what slicing is. Yeah. Great. Why don't we
4071
07:28:19,299 --> 07:28:20,299
do some more fun with this spring?
4072
07:28:20,299 --> 07:28:21,299
Yeah,
4073
07:28:21,299 --> 07:28:22,299
let me show you more fun with this rank, more
indexing, let's say you start at index zero,
4074
07:28:22,299 --> 07:28:23,299
you go to index 12, but not including 12.
And then you jump, you take a jump of two
4075
07:28:23,299 --> 07:28:24,299
rather than one, what we'll do is, it will
fetch all the corrector starting from index
4076
07:28:24,299 --> 07:28:25,299
zero, all the way to index 12, but not including
12. But it will take a jump of two rather
4077
07:28:25,299 --> 07:28:26,299
than taking the jump of two. So first greater
than take a jump of two, then pick a corrector,
4078
07:28:26,299 --> 07:28:27,299
then take a jump of two and then pick a corrector.
So it will actually pick every other characters
4079
07:28:27,299 --> 07:28:28,299
starting from zero. So let's see that. So
for example, if you remember the string, that's
4080
07:28:28,299 --> 07:28:29,299
the string. So it starts from h Fine, then
it skips Oh, and go to W, then it skips bass
4081
07:28:29,299 --> 07:28:30,299
and go to a then it skips R and go to E then
a skip space and go to u and then it skips
4082
07:28:30,299 --> 07:28:31,299
Oh, and go to a shoe and then the cloud achieved
and we stop there. Wow. So the general way
4083
07:28:31,299 --> 07:28:32,299
of slicing or indexing the general way is
you have a starting next start, then you have
4084
07:28:32,299 --> 07:28:33,299
an index and then you have a step size. If
you do not mention the step size. the step
4085
07:28:33,299 --> 07:28:34,299
size by default is one that we were doing
already. If you do not mention the end, the
4086
07:28:34,299 --> 07:28:35,299
default end is the building and the total
list size. If you do not mention the start
4087
07:28:35,299 --> 07:28:36,299
the default start is zero. For example, let
me make that a comment and just practice a
4088
07:28:36,299 --> 07:28:37,299
few for example. Let's start from zero we
do not mention the start let's start from
4089
07:28:37,299 --> 07:28:38,299
zero and go to 12 if you do not mention the
starting index that starts from the very beginning
4090
07:28:38,299 --> 07:28:39,299
zero go till 12 Okay great. If we do not mention
For example, we start from three and we do
4091
07:28:39,299 --> 07:28:40,299
not mention the end that means go till the
end starting from index three including the
4092
07:28:40,299 --> 07:28:41,299
last corrector Okay, if we do not mention
the step for example, if you start from one
4093
07:28:41,299 --> 07:28:42,299
go till 12 and we do not mention the step,
the default step is one okay. There is one
4094
07:28:42,299 --> 07:28:43,299
way of reversing the string, I mean very beautiful
way I mean, you do not you do not start the
4095
07:28:43,299 --> 07:28:44,299
mention and you do not mention the start,
you do not mention the end, and then just
4096
07:28:44,299 --> 07:28:45,299
take a step of minus one in this particular
way. The Start and End index they are they
4097
07:28:45,299 --> 07:28:46,299
are just swept and you get the string reversed
way. While so that's the reverse great. Isn't
4098
07:28:46,299 --> 07:28:47,299
that fancy? Yes, it is. Okay, a lot about
indexing, you can find out the length of any
4099
07:28:47,299 --> 07:28:48,299
string by using l m function, you can find
out the length of any substring if you want
4100
07:28:48,299 --> 07:28:49,299
to if you have a substring using again a lamp
function, alien, that's okay. Okay, and now
4101
07:28:49,299 --> 07:28:50,299
you've seen how to access sub strings and
how we cannot change the elements of a string
4102
07:28:50,299 --> 07:28:51,299
because it is immutable, but we can access
them, we can access them, we can just display
4103
07:28:51,299 --> 07:28:52,299
them, we can analyze them and so on. In the
next video, we will see some functions that
4104
07:28:52,299 --> 07:28:53,299
are supplied for string processing, what we
can do with strings, I mean how can we manipulate
4105
07:28:53,299 --> 07:28:54,299
those strings, although we cannot manipulate
the contents of a string, but we may copy
4106
07:28:54,299 --> 07:28:55,299
a string we may get explained, manipulate
it and save it to another variable and how
4107
07:28:55,299 --> 07:28:56,299
what kind of functions that are available
in string in string data structure string
4108
07:28:56,299 --> 07:28:57,299
data type. So let's see that in the next video.
Hope to see you in the next video. Okay, let's
4109
07:28:57,299 --> 07:28:58,299
see different functions that are available
to play with the strings. In this dense string
4110
07:28:58,299 --> 07:28:59,299
data structure, let's say you have the string
a a lot of spaces, these are a lot of spaces
4111
07:28:59,299 --> 07:29:00,299
at the beginning and these are a lot of spaces
at the end there are some spaces in the middle
4112
07:29:00,299 --> 07:29:01,299
as well. So, there is one function called
strip all the functions of the string they
4113
07:29:01,299 --> 07:29:02,299
are called by taking a dot A dot something
These are called methods you can loosely call
4114
07:29:02,299 --> 07:29:03,299
them functions, but those kind of functions
that are related to some data structure and
4115
07:29:03,299 --> 07:29:04,299
called with dot, they are sometimes called
methods. The term method is more related to
4116
07:29:04,299 --> 07:29:05,299
object oriented programming actually string
is a class. So all these are the methods But
4117
07:29:05,299 --> 07:29:06,299
even without knowing that it's perfectly okay,
you can call it method or function that's
4118
07:29:06,299 --> 07:29:07,299
perfectly okay. You can, I mean, it's okay.
It's okay without knowing what a class is
4119
07:29:07,299 --> 07:29:08,299
without knowing what an object oriented programming
is, this a dot some function that operates
4120
07:29:08,299 --> 07:29:09,299
on this a.
4121
07:29:09,299 --> 07:29:10,299
One difference with method and function is
when you call a function with a dot, and you
4122
07:29:10,299 --> 07:29:11,299
call some function that say, a dot strip.
Then inside the definition of the function,
4123
07:29:11,299 --> 07:29:12,299
this a object or the a variable is available,
like, like you have passed that variable as
4124
07:29:12,299 --> 07:29:13,299
an input argument. That's all you need to
know about the difference of matter and function,
4125
07:29:13,299 --> 07:29:14,299
the rest of the story is perfectly okay. Even
if you don't know that that's fine. Okay,
4126
07:29:14,299 --> 07:29:15,299
eight outstrip, it operates on a which means
that a is passed in this function as just
4127
07:29:15,299 --> 07:29:16,299
as input argument or it is available there
inside the function implementation. And then
4128
07:29:16,299 --> 07:29:17,299
the script function, what it does is it removes
all the spaces that are in the beginning,
4129
07:29:17,299 --> 07:29:18,299
and removes all the spaces that are at the
end, and returns another string that has that
4130
07:29:18,299 --> 07:29:19,299
has no spaces at the beginning and no spaces
at the end, and the new string is copied or
4131
07:29:19,299 --> 07:29:20,299
created in a variable b, let's say whatever
that we believe we can, we can have another
4132
07:29:20,299 --> 07:29:21,299
name of that variable. So let's see. Let's
see the running form of this script function
4133
07:29:21,299 --> 07:29:22,299
in our friend Jupyter. notebook. So let's
say a is a string variable. That's a lot of
4134
07:29:22,299 --> 07:29:23,299
spaces abcdef, a lot of spaces and hg gilwell,
whatever. And then a lot of space, and that's
4135
07:29:23,299 --> 07:29:24,299
it, this is a and then we have B, let's say
a dot strip. Okay, and that's sprint B. So
4136
07:29:24,299 --> 07:29:25,299
b is actually everything without spaces without
the starting spaces. And without ending spaces,
4137
07:29:25,299 --> 07:29:26,299
it does not hurt the spaces inside. So that's
the script function, sometimes processing
4138
07:29:26,299 --> 07:29:27,299
the data. When we when we read the data from
a file, it may have a lot of spaces at the
4139
07:29:27,299 --> 07:29:28,299
beginning at the end, maybe due to formatting
issues or something like so and it is this
4140
07:29:28,299 --> 07:29:29,299
function is available. If we want to remove
those spaces from beginning or from the end.
4141
07:29:29,299 --> 07:29:30,299
Let's see more functions. Another function
is lower, like the name suggests it actually
4142
07:29:30,299 --> 07:29:31,299
it actually converts all the string to lowercase.
For example, let's say we have a string, let's
4143
07:29:31,299 --> 07:29:32,299
say, a B, A, let's say we have a string, a
equals A, B, C, D, E, F, G, and some directors,
4144
07:29:32,299 --> 07:29:33,299
some other directors and Q f, let's say that's
a string. And now what we do is b equals a
4145
07:29:33,299 --> 07:29:34,299
dot lower. What it does is it converts all
the string to lowercase. For the characters
4146
07:29:34,299 --> 07:29:35,299
that are already in lowercase. It doesn't
hurt it. For the characters that has nothing
4147
07:29:35,299 --> 07:29:36,299
to do with lower uppercase, it doesn't hurt
that all the characters that are not in the
4148
07:29:36,299 --> 07:29:37,299
lowercase and can be converted to lowercase,
those are converted to lowercase. And this
4149
07:29:37,299 --> 07:29:38,299
is available. Yeah. Great. So similarly, we
have another function called upper for example,
4150
07:29:38,299 --> 07:29:39,299
C is equal to a dot upper that the like the
name suggests, it converts all the characters
4151
07:29:39,299 --> 07:29:40,299
to uppercase. Well, let's see more functions.
Oh, there is a function replace the Replace
4152
07:29:40,299 --> 07:29:41,299
function. What it does is it takes a substring
and replaces that substring with another substring.
4153
07:29:41,299 --> 07:29:42,299
Okay, let's see. For example, let's say we
here we want to be have the same a, let's
4154
07:29:42,299 --> 07:29:43,299
say the a is this thing. Let's say that's
a and what do we want to do is we want to
4155
07:29:43,299 --> 07:29:44,299
replace the semi colons let's say with with
with the semicolon, we want to replace the
4156
07:29:44,299 --> 07:29:45,299
semi colons with statics. So what we can do
is we can say okay, d equals a dot replace,
4157
07:29:45,299 --> 07:29:46,299
replace the semi colon with with let's say
steric. Or, yeah, so let's see what D is.
4158
07:29:46,299 --> 07:29:47,299
So each semicolon is replaced by a steric.
By the way, if you if you want to replace
4159
07:29:47,299 --> 07:29:48,299
for example, a, a dark replace, if you want
to replace one is there one semi colon One
4160
07:29:48,299 --> 07:29:49,299
semicolon with a string. For example, the
string is star star, and, and hashtag or some
4161
07:29:49,299 --> 07:29:50,299
person. That means one semicolon will be replaced
by this, seek with this string, and the other
4162
07:29:50,299 --> 07:29:51,299
semicolon will also be replaced by this screen.
And the result will be as expected, each semicolon
4163
07:29:51,299 --> 07:29:52,299
will be replaced by the screen. And that's
the result what it is further if you want,
4164
07:29:52,299 --> 07:29:53,299
for example, if you want, for example, let's
say d equals a dot replace, if you want this
4165
07:29:53,299 --> 07:29:54,299
particular substring, that contains the two
semi colons, if you want the two semi colons
4166
07:29:54,299 --> 07:29:55,299
to be replaced by another substring, let's
say two semi colons, let's say. And that is
4167
07:29:55,299 --> 07:29:56,299
also possible I mean, you, you replace one
substring with another one. Right? There is
4168
07:29:56,299 --> 07:29:57,299
one more function called split. That what
it does what what the split does is, for example,
4169
07:29:57,299 --> 07:29:58,299
you have a string, for example, let's say
a equals a string, let's say, ABC, then you
4170
07:29:58,299 --> 07:29:59,299
have this colon, then you have d f, then you
have semi colon, then you have ads g y, there's
4171
07:29:59,299 --> 07:30:00,299
Dan semi colon, then you have y y 3223. That's
it. That's your string. Let's say you read
4172
07:30:00,299 --> 07:30:01,299
that string from some CSV file and disappears.
And now what you want, you want all these
4173
07:30:01,299 --> 07:30:02,299
values to be separated out that are that that
are separated by the semicolon, maybe these
4174
07:30:02,299 --> 07:30:03,299
are different values, ABC is a different value,
then it is separated by a semicolon semicolon
4175
07:30:03,299 --> 07:30:04,299
may be an indication or token that the next
value started and so on. Let's say you want
4176
07:30:04,299 --> 07:30:05,299
to separate them, let's say you want to just
split them all of them with a particular splitter.
4177
07:30:05,299 --> 07:30:06,299
And here, let's say the splitter is semi colon.
So what you can do is you can have a list
4178
07:30:06,299 --> 07:30:07,299
and a dot split. And in the split, you can
specify the corrector that that is used for
4179
07:30:07,299 --> 07:30:08,299
splitting after and before we split that.
And remember, the split function actually
4180
07:30:08,299 --> 07:30:09,299
returns a list of strings, where this is the
first element of the list, this is the second
4181
07:30:09,299 --> 07:30:10,299
element of the list, this is the third element
of the list, this is the fourth element of
4182
07:30:10,299 --> 07:30:11,299
the list and so on. Because once you will
split, you will be having different elements
4183
07:30:11,299 --> 07:30:12,299
that are split it out. So if your brand for
example, l we will be having a list of different
4184
07:30:12,299 --> 07:30:13,299
strengths, ABC and all that, Oh, don't worry
about the single code, the single core and
4185
07:30:13,299 --> 07:30:14,299
double core is the same thing. Now we can
access for example, the third element or or
4186
07:30:14,299 --> 07:30:15,299
maybe the second element by index one. And
the second element here is D, E, F, and we
4187
07:30:15,299 --> 07:30:16,299
can work more on that. Okay. Is that it? I
mean? Are these the only functions that are
4188
07:30:16,299 --> 07:30:17,299
available? stripped function lower a birthplace
and split function? Or is that it? That's
4189
07:30:17,299 --> 07:30:18,299
all the spring is about? Maybe there are more
functions? How many functions are there in
4190
07:30:18,299 --> 07:30:19,299
string? How can we use them? What are the
what are the total number of functions? Where
4191
07:30:19,299 --> 07:30:20,299
is the list? We visit documentation? Should
should we follow some book? Should we go to
4192
07:30:20,299 --> 07:30:21,299
some tutorial and find all the string functions
and see how to use them? Well, if you want
4193
07:30:21,299 --> 07:30:22,299
to do that, you can do that. But there is
another smart way. Let's say a is a string
4194
07:30:22,299 --> 07:30:23,299
that you know, you write a dot and then a
press tab, and all the things that that are
4195
07:30:23,299 --> 07:30:24,299
there in in string, they will they will appear
in front of you on several things. You can
4196
07:30:24,299 --> 07:30:25,299
go to this, you can go to that you can go
to that and so on. So just you can check the
4197
07:30:25,299 --> 07:30:26,299
documentation of a for example, if you if
you press a and what it does, let's see. It's
4198
07:30:26,299 --> 07:30:27,299
a string object and all that stuff. Fine.
It's a string. So further what we can do.
4199
07:30:27,299 --> 07:30:28,299
So let's say a.we, press A and then we press
tab. Is there anything that starts from a
4200
07:30:28,299 --> 07:30:29,299
Nope? Is there anything that starts from B?
No. Is there anything that starts from C?
4201
07:30:29,299 --> 07:30:30,299
Yes, capitalize case fold center count. These
are the functions that are available that
4202
07:30:30,299 --> 07:30:31,299
starts from C.
4203
07:30:31,299 --> 07:30:32,299
Okay, let's focus on capitalized. Okay, what
is that thing how to use it? That's press
4204
07:30:32,299 --> 07:30:33,299
colon, question mark and see what this is
and what it does. Okay, so here is the documentation
4205
07:30:33,299 --> 07:30:34,299
here is a doc string returns capital. I used
to worry enough the string capitalized version
4206
07:30:34,299 --> 07:30:35,299
of the string. Is that the same as upper?
Maybe? So let's see. Now we know what it does.
4207
07:30:35,299 --> 07:30:36,299
Let's just check it out, print a capitalized
and see what's the result? Oh, it's got Oh
4208
07:30:36,299 --> 07:30:37,299
no, it does not get delays the whole screen,
does it? Did they the screen a was it does
4209
07:30:37,299 --> 07:30:38,299
not capitalize the whole string? What What
is a? Let's see what is a? A is the following
4210
07:30:38,299 --> 07:30:39,299
string is the following string, so it does
not capitalize the whole string. Oh, the difference
4211
07:30:39,299 --> 07:30:40,299
between the capitalized maybe? And the upper?
Is that the capitalize when it encounters
4212
07:30:40,299 --> 07:30:41,299
when it encounters? No, no, no capitalized
just capitalizes the first corrector. Let
4213
07:30:41,299 --> 07:30:42,299
me let me read the doc string, again, returns
a capitalized version of the string, more
4214
07:30:42,299 --> 07:30:43,299
specifically make the first corrector have
uppercase and the rest lowercase. Okay, that
4215
07:30:43,299 --> 07:30:44,299
means if we have a string that has a mix of
values, the capitalized will do the following.
4216
07:30:44,299 --> 07:30:45,299
It will convert the first character to uppercase
and all the rest of the characters the lowercase.
4217
07:30:45,299 --> 07:30:46,299
Wow, that's awesome function. For example,
if you have string, abs D, A, B and GG, kill
4218
07:30:46,299 --> 07:30:47,299
that say. And then we call capitalize, capitalize,
let's say. So what that does is it actually
4219
07:30:47,299 --> 07:30:48,299
capitalizes the first director and all the
rest of the directors there as it is. And
4220
07:30:48,299 --> 07:30:49,299
there are other functions as well, a dot A
dot, let's see count, what it does a dot count
4221
07:30:49,299 --> 07:30:50,299
what it does not count. What is that thing?
Let's check it out. Or maybe we can check
4222
07:30:50,299 --> 07:30:51,299
that out using help. What is zero count? So
let's see what is a load count. It's a built
4223
07:30:51,299 --> 07:30:52,299
in function called matters is an instance
of and it returns a number of non overlapping
4224
07:30:52,299 --> 07:30:53,299
occurrences of a substring. Sub in Oh my God,
if you I mean, that's what it what what is
4225
07:30:53,299 --> 07:30:54,299
written there, non overlapping apprentice
of a substring. Great Oh my god. So basically,
4226
07:30:54,299 --> 07:30:55,299
there are there are a whole lot of functions
of strings that are available, there are several
4227
07:30:55,299 --> 07:30:56,299
use of the string, there are several ways
of molding and playing with the strings, some
4228
07:30:56,299 --> 07:30:57,299
of the functions that are available, some
you can make your own, you can make your own
4229
07:30:57,299 --> 07:30:58,299
modules on top of that, to customize your
written to customize according to your requirements.
4230
07:30:58,299 --> 07:30:59,299
A lot of these are available, and you should
know how to use them. And first thing if you
4231
07:30:59,299 --> 07:31:00,299
want to do something with strings, or with
any data type in Python, first check whether
4232
07:31:00,299 --> 07:31:01,299
some method is available or not. And one way
to go that is just right away from here. And
4233
07:31:01,299 --> 07:31:02,299
other ways to go to internet and see I want
to do this in Python. with strings, whether
4234
07:31:02,299 --> 07:31:03,299
there is a function available or not the good
chances are there will be a built in function
4235
07:31:03,299 --> 07:31:04,299
that is available. And in that case, I will
encourage to use that function rather than
4236
07:31:04,299 --> 07:31:05,299
to write your own one because using the built
in function, or the method that is tied up
4237
07:31:05,299 --> 07:31:06,299
there will be much more faster probably than
the function you will be writing at your end
4238
07:31:06,299 --> 07:31:07,299
even if you're too smart in algorithms. So
yeah,
4239
07:31:07,299 --> 07:31:08,299
so that's about the spring matters, there
are so many other methods that are available.
4240
07:31:08,299 --> 07:31:09,299
In the next video, we will see some more some
more manipulation and processing and some
4241
07:31:09,299 --> 07:31:10,299
more working with strings. And then we will
move to other data structures. Okay, hope
4242
07:31:10,299 --> 07:31:11,299
to see you in the next video. In the last
video, we saw some methods of string. And
4243
07:31:11,299 --> 07:31:12,299
these are just a few of them, a lot of them
are available. We just we just discussed some
4244
07:31:12,299 --> 07:31:13,299
of them. In this video we are going to talk
more about strings in a particular way. For
4245
07:31:13,299 --> 07:31:14,299
example, what if you want to find out whether
a particular substring is there in a string
4246
07:31:14,299 --> 07:31:15,299
or not. Let's say you have a string and you
want to know whether a particular substring
4247
07:31:15,299 --> 07:31:16,299
is there inside a string or not? Well, you
can easily find out that using the end keyword.
4248
07:31:16,299 --> 07:31:17,299
And similarly not in means the reverse of
that, or the complement of that or not of
4249
07:31:17,299 --> 07:31:18,299
that. And in keyword always will return either
true or Boolean or false. If it is inside
4250
07:31:18,299 --> 07:31:19,299
the screen, it will return true if it is not
inside it will return false. So let's check
4251
07:31:19,299 --> 07:31:20,299
this the implementation of that in, in, in
Jupyter Notebook. So let's see. So let's say
4252
07:31:20,299 --> 07:31:21,299
we have a string ABC ABC. And we want to check
whether this string is there in this particular
4253
07:31:21,299 --> 07:31:22,299
string or not. So the return value is false
because ABC as a substring is no longer there.
4254
07:31:22,299 --> 07:31:23,299
A is there. For example, here, a B is here,
but ABC is no longer there. Yeah, so if we,
4255
07:31:23,299 --> 07:31:24,299
for example, have an ABC somewhere, at least
once, then the result will be true. In the
4256
07:31:24,299 --> 07:31:25,299
last, in the last video, or maybe in the very
first video for strengths, I showed you that
4257
07:31:25,299 --> 07:31:26,299
you can use plus with strings, can you compare
two strings using less than or equal to? I
4258
07:31:26,299 --> 07:31:27,299
mean, how to compare two strings, whether
they are same or not, for example, ABC, that's
4259
07:31:27,299 --> 07:31:28,299
a that's a string ABC, I want to check whether
that string is the same as ABC or not, what
4260
07:31:28,299 --> 07:31:29,299
will be the result? So so so the question
is, is this double equal to is used can be
4261
07:31:29,299 --> 07:31:30,299
used for comparing two strings? Well, the
answer is yes. Or what will be the meaning
4262
07:31:30,299 --> 07:31:31,299
of less than a string as less than the other?
Is that true? For example, ABC, is less than,
4263
07:31:31,299 --> 07:31:32,299
let's say d f. Is that true? If it is true,
for example, what does it really mean? How
4264
07:31:32,299 --> 07:31:33,299
can we define one string is I mean, this string
is less so than the other string, maybe this,
4265
07:31:33,299 --> 07:31:34,299
maybe this operator is working based on the
length of the strings. But if even if that,
4266
07:31:34,299 --> 07:31:35,299
then this length is the same as this length.
And to be more precise, we can change that
4267
07:31:35,299 --> 07:31:36,299
length, for example, by just saying, okay,
ABC, D, F, G, H, I, and I guess this string
4268
07:31:36,299 --> 07:31:37,299
will be still smaller than the right string.
So how this comparison is working? Well, I
4269
07:31:37,299 --> 07:31:38,299
guess the comparison is working based on the
based on the alphabetic order, and you know,
4270
07:31:38,299 --> 07:31:39,299
the alphabetic order, a B comes first and
B and C and all the alphabetic order that
4271
07:31:39,299 --> 07:31:40,299
is there in English dictionaries. That's how
the strings are working here. And the alphabetic
4272
07:31:40,299 --> 07:31:41,299
orders for all the special characters will
also be defined in Python, for example, that's
4273
07:31:41,299 --> 07:31:42,299
a special graduate, for example, maybe this
string is this string smaller than the following
4274
07:31:42,299 --> 07:31:43,299
string. Yeah, we've done for false, because
there is particular ordering. In, in Python
4275
07:31:43,299 --> 07:31:44,299
that is defined for these characters that
this becomes first and there's like, a becomes
4276
07:31:44,299 --> 07:31:45,299
first and B, B becomes first and C and so
on. So whatever the alphabetic order is, based
4277
07:31:45,299 --> 07:31:46,299
on that, or you can compare the two strings,
no problem. So these are also available. And
4278
07:31:46,299 --> 07:31:47,299
the third thing is in function that is also
available to check whether a particular string
4279
07:31:47,299 --> 07:31:48,299
is inside a substring is inside or not to
in another string. One more thing that I want
4280
07:31:48,299 --> 07:31:49,299
to talk about in that, for example, what if
your goal is to print the following, let's
4281
07:31:49,299 --> 07:31:50,299
say let's say you want to print the following,
we are learning. And let's say you want to
4282
07:31:50,299 --> 07:31:51,299
print the string in double quotes. We are
learning string here. Let's say you want to
4283
07:31:51,299 --> 07:31:52,299
print this, you want this string to appear
in double quote, how can you do that in Python?
4284
07:31:52,299 --> 07:31:53,299
Well, it looks like same. What's the difficulty?
Let's Let's call the print function. And then
4285
07:31:53,299 --> 07:31:54,299
just like here, we are learning. Then write
the double quote here, scraping. And here.
4286
07:31:54,299 --> 07:31:55,299
That's it. But there is a problem. The reason
is, the reason is when we call this, when
4287
07:31:55,299 --> 07:31:56,299
we write this double code, actually, the string
ends here, exactly the string ends here. And
4288
07:31:56,299 --> 07:31:57,299
when we write this single code, and this double
code, another string starts here. And this
4289
07:31:57,299 --> 07:31:58,299
is no longer a string. I mean, what it has
no data type inside. Well, how can we then
4290
07:31:58,299 --> 07:31:59,299
insert these double quotes inside? Well, there
are several ways. One way is to use escape
4291
07:31:59,299 --> 07:32:00,299
sequence and escape sequences just like it
is you use a slash and then whatever you use
4292
07:32:00,299 --> 07:32:01,299
is considered as a corrector. Inside the string
that is you're using it now if you want another
4293
07:32:01,299 --> 07:32:02,299
double quote, you use a user corrector which
is the backslash or maybe a forward slash
4294
07:32:02,299 --> 07:32:03,299
and if you use that That means that means
whatever that is coming in front of it should
4295
07:32:03,299 --> 07:32:04,299
be used as it is, rather than, rather than
considering that that's a special string defining
4296
07:32:04,299 --> 07:32:05,299
symbol. Now in this particular case, you'll
be having your double quotes available, and
4297
07:32:05,299 --> 07:32:06,299
the backslash will be just out, it's justifying
that don't touch this double code, it has
4298
07:32:06,299 --> 07:32:07,299
nothing to do with defining a string. It is
just because I want to highlight this word.
4299
07:32:07,299 --> 07:32:08,299
Another more. Another more easy way is to
use the single quotes, for example, we are
4300
07:32:08,299 --> 07:32:09,299
learning and use the double quotes as a corrector.
Inside that now the single quote, wherever
4301
07:32:09,299 --> 07:32:10,299
it starts and ends, they defined the string,
everything else is correct. We do not need
4302
07:32:10,299 --> 07:32:11,299
a escape cracker where we where we want, okay,
great. But there are a lot of escape characters,
4303
07:32:11,299 --> 07:32:12,299
for example, we have V, our backslash n, that
means go to new line, we are now on an other
4304
07:32:12,299 --> 07:32:13,299
line. So this backslash n actually puts everything
that comes after to a new line. That's an
4305
07:32:13,299 --> 07:32:14,299
escape corrector. Similarly, we have an escape
corrector, backslash D, that actually inserts
4306
07:32:14,299 --> 07:32:15,299
a tab. Whenever we want Sophie, then a tab
then now on another line, now on another tab,
4307
07:32:15,299 --> 07:32:16,299
whatever. So there are a lot of escape characters.
I'm in backslash, N, backslash t there are
4308
07:32:16,299 --> 07:32:17,299
other. So it is good to know those. One more
thing that is important. For example, let's
4309
07:32:17,299 --> 07:32:18,299
say you want to print. Let's say you want
to print some address on the right, let's
4310
07:32:18,299 --> 07:32:19,299
see, Mac's slash back slash forward slash
whatever that is called name, backslash Dr.
4311
07:32:19,299 --> 07:32:20,299
Let's say you want to do that. And your goal
was to just print that box, what will happen
4312
07:32:20,299 --> 07:32:21,299
is this backslash n will be treated as a newline
escape sequence. And backslash n will tell
4313
07:32:21,299 --> 07:32:22,299
Okay, go to the next line and create the rest
of the things. But because backslash D is
4314
07:32:22,299 --> 07:32:23,299
not any escape sequence, it is not listed
inside, it is treated as it is and that way
4315
07:32:23,299 --> 07:32:24,299
this slash is also treated as a director.
But here because if this slash followed by
4316
07:32:24,299 --> 07:32:25,299
this n, that's combination that is already
there for a new line that is treated in a
4317
07:32:25,299 --> 07:32:26,299
different way. If you want this to be used
as a deus and you don't want these, you don't
4318
07:32:26,299 --> 07:32:27,299
want this behavior, you just want that all
this should be greeted in a very literal or
4319
07:32:27,299 --> 07:32:28,299
raw sense, then you should just apply and
are there in our will tell, okay, that's,
4320
07:32:28,299 --> 07:32:29,299
that's a raw string, everything inside just
treat that as a raw string, there is no escape
4321
07:32:29,299 --> 07:32:30,299
sequence inside. Great. So and there is much
more about strings, we can talk but that that
4322
07:32:30,299 --> 07:32:31,299
was the most important that I that I told
you, at least to me, we can explore this more
4323
07:32:31,299 --> 07:32:32,299
actually, you should now explore the smaller
What are other functions of string, how can
4324
07:32:32,299 --> 07:32:33,299
we play with strings in another way and stuff
and
4325
07:32:33,299 --> 07:32:34,299
so on. If I talk about strings, I can just
I mean, I can give a whole course on strings
4326
07:32:34,299 --> 07:32:35,299
as well. But here I just give you a snapshot
of strings. If you need more about strings,
4327
07:32:35,299 --> 07:32:36,299
I mean you should be searching on internet
of seeing documentations and seeing basically
4328
07:32:36,299 --> 07:32:37,299
what you want according to your requirements,
search the functions probably they will be
4329
07:32:37,299 --> 07:32:38,299
available. Okay. In the next video, we are
going towards list topples, sets and dictionaries
4330
07:32:38,299 --> 07:32:39,299
some other data structures that we were talking
about earlier, we will be going to explore
4331
07:32:39,299 --> 07:32:40,299
them in more detail from the next video. Hope
to see you in the next video data structure
4332
07:32:40,299 --> 07:32:41,299
informally or in a very naive sense is basically
a collection of a lot of basic data types
4333
07:32:41,299 --> 07:32:42,299
that contains data one structure contain a
lot of data. And we can define sometimes several
4334
07:32:42,299 --> 07:32:43,299
methods and several specialized kind of functions
are customized and define just because of
4335
07:32:43,299 --> 07:32:44,299
that data structure to perform efficiently
different kinds of I mean for different kinds
4336
07:32:44,299 --> 07:32:45,299
of tasks, we may have to define or we may
have to choose different kinds of data structures.
4337
07:32:45,299 --> 07:32:46,299
The basic data structures that are available
in Python is a list tupple set and dictionary.
4338
07:32:46,299 --> 07:32:47,299
These are the basic data structures that are
available. We can create our own data structures
4339
07:32:47,299 --> 07:32:48,299
if we want to. But most of the problems almost
all of the problems mostly they are solved
4340
07:32:48,299 --> 07:32:49,299
by these four basic data structures. Although
a lot of these are not that efficient. There
4341
07:32:49,299 --> 07:32:50,299
are efficient ways for customized kind of
problems, we will see that efficiency when
4342
07:32:50,299 --> 07:32:51,299
we will deal with the package NumPy that is,
that is faster than all of these, but will
4343
07:32:51,299 --> 07:32:52,299
but we will see what kind of constraints are
there to make it faster. Anyways, data set
4344
07:32:52,299 --> 07:32:53,299
in a very loose term is collection, it is
a collection of a lot of values a lot of data
4345
07:32:53,299 --> 07:32:54,299
inside. And all these data structures list
tupple set and dictionary, they they are a
4346
07:32:54,299 --> 07:32:55,299
collection of data of heterogeneous types,
which means one value can be integer another
4347
07:32:55,299 --> 07:32:56,299
element let me call an element, another element
or item, another item or element can be of
4348
07:32:56,299 --> 07:32:57,299
string type, another element can be off, let's
say floating point number another element
4349
07:32:57,299 --> 07:32:58,299
is a whole list itself another element is
a topple and so on. So different elements
4350
07:32:58,299 --> 07:32:59,299
can be of different types. And that makes
this heterogeneity that makes these four data
4351
07:32:59,299 --> 07:33:00,299
structures much more applicable and much more
abstract. And they can be applied to almost
4352
07:33:00,299 --> 07:33:01,299
all the problems. So let's see one by one
and let's compare them together because the
4353
07:33:01,299 --> 07:33:02,299
best way to understand four of these is just
to compare them which can do what as compared
4354
07:33:02,299 --> 07:33:03,299
to the rest. So let's let's compare them and
learn how can we use those in detail. So list
4355
07:33:03,299 --> 07:33:04,299
first is list list is ordered ordered here
means it is indexable which means there is
4356
07:33:04,299 --> 07:33:05,299
a particular element number one is at position
one element, there is an ordering of elements
4357
07:33:05,299 --> 07:33:06,299
first element second third 25th element, there
is an ordering of element with respect to
4358
07:33:06,299 --> 07:33:07,299
their position. So that's what we mean by
ordered changeable or sometimes called more
4359
07:33:07,299 --> 07:33:08,299
more reasonable term or more usable term is
mutable. mutable means once the list is created
4360
07:33:08,299 --> 07:33:09,299
as contrast to string, once the list is created,
you can change its elements for example, you
4361
07:33:09,299 --> 07:33:10,299
can change the third element with another
element and that's perfectly fine you can
4362
07:33:10,299 --> 07:33:11,299
change it that what we mean by changeable
or more popularly called as mutable duplicates
4363
07:33:11,299 --> 07:33:12,299
means the list can contain more than one one
element more than two, I mean, at the position
4364
07:33:12,299 --> 07:33:13,299
number three, you can have the same item and
position number five you can have the same
4365
07:33:13,299 --> 07:33:14,299
item that so the duplicates are allowed tupple
however, although ordered, there there is
4366
07:33:14,299 --> 07:33:15,299
an ordering of elements there is there are
indices of different elements, this is immutable,
4367
07:33:15,299 --> 07:33:16,299
you can once topple is created like strings.
Once the template is created, you cannot change
4368
07:33:16,299 --> 07:33:17,299
different elements in the tupple you have
to create a new topple if you want to, but
4369
07:33:17,299 --> 07:33:18,299
you cannot change the items in the tupple
and the duplicates are allowed again set on
4370
07:33:18,299 --> 07:33:19,299
the other hand is unordered which means there
is no indexing there is no positioning, there
4371
07:33:19,299 --> 07:33:20,299
is no first element there is no third element,
there is no Fifth Element, there is that's
4372
07:33:20,299 --> 07:33:21,299
a collection without it without actually indexing
4373
07:33:21,299 --> 07:33:22,299
because you cannot access a particular element
with index you cannot change it, but what
4374
07:33:22,299 --> 07:33:23,299
you can do it you can insert more elements
and you can remove existing elements if you
4375
07:33:23,299 --> 07:33:24,299
want to. Again, the set like in mathematics
sets does not contain any duplicates. So one
4376
07:33:24,299 --> 07:33:25,299
item appears just once we will see the examples
Dictionary of very, very, very powerful data
4377
07:33:25,299 --> 07:33:26,299
structure. Again, it is it is dictionary is
just like a set, it's a set it is unordered.
4378
07:33:26,299 --> 07:33:27,299
Again, chancer bow, you can change them but
you can change the items you can and the dictionary
4379
07:33:27,299 --> 07:33:28,299
the pocket and it does not have duplicates,
because it's it's basically a set it is just
4380
07:33:28,299 --> 07:33:29,299
like I said, the power of dictionary is each
item consists of consists of a pair and one
4381
07:33:29,299 --> 07:33:30,299
one value in the beer is called key and another
is called the value for example, well is key
4382
07:33:30,299 --> 07:33:31,299
for 12 name is key for band and and so on.
So we have seen this dictionary before in
4383
07:33:31,299 --> 07:33:32,299
loops and stuff in just a very loose way.
But then that's really a very, very powerful
4384
07:33:32,299 --> 07:33:33,299
data structure. And later on we will see in
pandas basically all the data is basically
4385
07:33:33,299 --> 07:33:34,299
managed, just like a dictionary if you if
you have a good knowledge of dictionary, you
4386
07:33:34,299 --> 07:33:35,299
will be having a very good grip very quickly
on on a Big Data Science Library or Big Data
4387
07:33:35,299 --> 07:33:36,299
Science package which is called pandas because
each and everything in pandas is handled just
4388
07:33:36,299 --> 07:33:37,299
like you're handling a dictionary. So it's
it's a really powerful data structure to know
4389
07:33:37,299 --> 07:33:38,299
about.
4390
07:33:38,299 --> 07:33:39,299
So, so so
4391
07:33:39,299 --> 07:33:40,299
list is mutable dictionary is mutable set
is mutable, in a sense that you can insert
4392
07:33:40,299 --> 07:33:41,299
and remove elements. topple is not mutable.
And that's a comparison theoretically What
4393
07:33:41,299 --> 07:33:42,299
is there, all these types, each and every
of them is a collection of different values.
4394
07:33:42,299 --> 07:33:43,299
And the values can have different types. That's
the that's the abstract power of all these
4395
07:33:43,299 --> 07:33:44,299
data structures. So, in the next video, we
will, we will, we will actually try to get
4396
07:33:44,299 --> 07:33:45,299
a good grip on list topple set in dictionary
and we will actually define them code and
4397
07:33:45,299 --> 07:33:46,299
access different methods of those and we will
be we will be trying to become comfortable
4398
07:33:46,299 --> 07:33:47,299
with with these data structures by coding
them in Python. So hope to see you in the
4399
07:33:47,299 --> 07:33:48,299
next video. Okay, continue in previous video
we were talking about data structures in the
4400
07:33:48,299 --> 07:33:49,299
last video. So let's go to the Jupyter Notebook
and see how a list can be defined or declared
4401
07:33:49,299 --> 07:33:50,299
how a tuple can be defined or declared set
and dictionary, let's see how can we make
4402
07:33:50,299 --> 07:33:51,299
these data structures in Python? So then one
by one, we will compare how can we access
4403
07:33:51,299 --> 07:33:52,299
elements of the list? How can we insert more
elements in lists tuples are in dictionary
4404
07:33:52,299 --> 07:33:53,299
and and see the comparisons of all these one
by one operation by operation. So let's see.
4405
07:33:53,299 --> 07:33:54,299
So let's go to Jupyter Notebook, our friend
this file is getting lengthy, lengthy, let's
4406
07:33:54,299 --> 07:33:55,299
let's make multiple files. Let's say this
is part one. Just save it. And let's make
4407
07:33:55,299 --> 07:33:56,299
another let's make another file. For example,
let's just close this file, or maybe state
4408
07:33:56,299 --> 07:33:57,299
opened, let's close this file and make another
file. Python three. Yeah, so let's name that
4409
07:33:57,299 --> 07:33:58,299
file as this part two, let's start a new file
that that file was on in that was okay to
4410
07:33:58,299 --> 07:33:59,299
stay with that file as well. But just let's
make another file. Okay. So that's just have
4411
07:33:59,299 --> 07:34:00,299
a markdown cell. And let's have a heading.
data structures. Remember the markdown cells,
4412
07:34:00,299 --> 07:34:01,299
I just introduced them introduce those just
in the very beginning. And then we just forget
4413
07:34:01,299 --> 07:34:02,299
them. Because writing these description again,
and again, we'll make the video length here.
4414
07:34:02,299 --> 07:34:03,299
And the purpose is not to actually format
the notebook, the purpose is just to show
4415
07:34:03,299 --> 07:34:04,299
you the power of Python. So I just omitted
writing these descriptions more and more,
4416
07:34:04,299 --> 07:34:05,299
but just write a few descriptions in the star
and then we will forget again. Oh, that's
4417
07:34:05,299 --> 07:34:06,299
it. That's amazing. Let's see, find a list.
So list. Any variable name, that's a variable
4418
07:34:06,299 --> 07:34:07,299
in the list is, let's say this. You define
this by square brackets and different elements
4419
07:34:07,299 --> 07:34:08,299
they are separated by comma, that's a 134,
point nine. Name anything I mean, or five,
4420
07:34:08,299 --> 07:34:09,299
or maybe maybe three again. So that's the
list. Okay. ductile, on the other hand, is
4421
07:34:09,299 --> 07:34:10,299
defined using parentheses. So let's say 134.
point nine. That's the name. And that's a
4422
07:34:10,299 --> 07:34:11,299
three again, that's okay, that's a tupple.
A tupple is defined in. So when you write
4423
07:34:11,299 --> 07:34:12,299
parentheses, that means by default that topple
the variable name has I mean, if you have
4424
07:34:12,299 --> 07:34:13,299
written t that has nothing to do that it's
a tupple. That's because the Python is dynamically
4425
07:34:13,299 --> 07:34:14,299
typed. When you will write the parentheses
that means the tupple is being defined. Let's
4426
07:34:14,299 --> 07:34:15,299
define a set Let's call the variable as S,
the set is defined with with these curly brackets.
4427
07:34:15,299 --> 07:34:16,299
So let's say 134.
4428
07:34:16,299 --> 07:34:17,299
point nine, I want to tell you that all these
things they can contain each element can have
4429
07:34:17,299 --> 07:34:18,299
a different type. But then, even if we include
this three again, because the set cannot contain
4430
07:34:18,299 --> 07:34:19,299
the duplicates, later on, we will see only
one copy of three will be there in the set,
4431
07:34:19,299 --> 07:34:20,299
the other will, even if we want to include
it will not be included. Okay? Then let's
4432
07:34:20,299 --> 07:34:21,299
say a dictionary. dictionary is again defined
like a set, but but each element is a pair,
4433
07:34:21,299 --> 07:34:22,299
separated by a colon. Let's say the key value
is 23 as a key value, that's the key and the
4434
07:34:22,299 --> 07:34:23,299
value. Here is a string, let's say
4435
07:34:23,299 --> 07:34:24,299
two,
4436
07:34:24,299 --> 07:34:25,299
three, that's let's see the value. Now comma.
Now one element is there. This one element
4437
07:34:25,299 --> 07:34:26,299
that consists of key and value pair, another
element, another element may have a key with
4438
07:34:26,299 --> 07:34:27,299
string. So so the keys can be of different
types, the values can be of different types,
4439
07:34:27,299 --> 07:34:28,299
and so abstract. So the key is, let's say,
let's say B. and the value for this is, let's
4440
07:34:28,299 --> 07:34:29,299
say 43, then maybe we can have another key
value pair with key as, let's say, c. and
4441
07:34:29,299 --> 07:34:30,299
the value is, let's say, cc. CCD. That's a
charge coupled device. Okay, anyways, so.
4442
07:34:30,299 --> 07:34:31,299
So again, now you know how to define less
how to define a topper, how to define a set,
4443
07:34:31,299 --> 07:34:32,299
and how to define a dictionary. The difference
is, is the main difference here is in dictionary,
4444
07:34:32,299 --> 07:34:33,299
because one element consists of two values
rather than one. Okay, let's print that and
4445
07:34:33,299 --> 07:34:34,299
see the types let's print all the types sprint
died off. So let's paint them. That type of
4446
07:34:34,299 --> 07:34:35,299
L is. So the table L is just printed. That's
L, let's print that. Let's see the other types,
4447
07:34:35,299 --> 07:34:36,299
let's print the rest as well. So just copy
them and B is the type of list L is that the
4448
07:34:36,299 --> 07:34:37,299
type of topple is D. And that's a D, then
we have s and then we can just replace this
4449
07:34:37,299 --> 07:34:38,299
to the s. And then we have, let's say, D dictionary.
And that's, that's D. Okay, so that's been,
4450
07:34:38,299 --> 07:34:39,299
so the type of L is less the type of t is
topple the time of s is set. The dive of D
4451
07:34:39,299 --> 07:34:40,299
is dictionary. Oh, great. So that's how you
can define these lists. You can define list
4452
07:34:40,299 --> 07:34:41,299
you can find topple, you can define set, and
you can define dictionary, no problem. Next,
4453
07:34:41,299 --> 07:34:42,299
let's see how to access different elements
from from these data structures. What are
4454
07:34:42,299 --> 07:34:43,299
the way for example, to access an element
from a list, let's say the element number
4455
07:34:43,299 --> 07:34:44,299
element that indexed with one remember the
element that index with one is element number
4456
07:34:44,299 --> 07:34:45,299
two, because indexing starts from zero. So
you can access that using the square brackets.
4457
07:34:45,299 --> 07:34:46,299
If you want to access from topple again from
the square brackets exactly like the list.
4458
07:34:46,299 --> 07:34:47,299
In set, for example, you cannot index it because
the set has no ordering. First, second third
4459
07:34:47,299 --> 07:34:48,299
element is no longer there. But you can you
can, you can check whether a particular element
4460
07:34:48,299 --> 07:34:49,299
is there in the set or not using in keyword.
In dictionary, for example, if you want to
4461
07:34:49,299 --> 07:34:50,299
check whether a particular element or if you
want to access value, for a particular key,
4462
07:34:50,299 --> 07:34:51,299
you just create the dictionary variable name
and then write the key and it will return
4463
07:34:51,299 --> 07:34:52,299
the value. Okay, so let's practice this in
in Jupiter. Let's just practice this in Jupiter.
4464
07:34:52,299 --> 07:34:53,299
So let's say list value at index one. So that's
brand new, this list added next one, the value
4465
07:34:53,299 --> 07:34:54,299
should be printed as three brand topple at
index one, again, the way of accessing the
4466
07:34:54,299 --> 07:34:55,299
same Brent Brent, whether three in s or not,
the return value will be the return value
4467
07:34:55,299 --> 07:34:56,299
will be true or false. So print will be true
or false. And then print the and just access
4468
07:34:56,299 --> 07:34:57,299
the value with the key 23. So let's see what
happens. So l added index one is three tier
4469
07:34:57,299 --> 07:34:58,299
index one is three s, three years in S Yes.
4470
07:34:58,299 --> 07:34:59,299
And what is the value with the key 23? The
value is the value is two three. Let me just
4471
07:34:59,299 --> 07:35:00,299
describe more about this D. What is the value
at index B for example, now we have to give
4472
07:35:00,299 --> 07:35:01,299
the index B in the string format. That's 43.
Yeah, so that's how we can access that. Let's
4473
07:35:01,299 --> 07:35:02,299
sprint s also let's see s because when we
have defined as we have defined this duplicate
4474
07:35:02,299 --> 07:35:03,299
three But if you see the elements of s, there
are no duplicates. And it does not maintain
4475
07:35:03,299 --> 07:35:04,299
even any ordering, I mean, we have defined
s in a different way, it is maintaining everything
4476
07:35:04,299 --> 07:35:05,299
maybe in a different way, one three. Yeah,
oh, the ordering this way is the same, but
4477
07:35:05,299 --> 07:35:06,299
there is no index for the first or second
or third element and so on. Okay, so that's
4478
07:35:06,299 --> 07:35:07,299
about the defining, declaring or accessing
different elements. In the next video, we
4479
07:35:07,299 --> 07:35:08,299
will see more about about the data structures
actually, actually want to spend some time
4480
07:35:08,299 --> 07:35:09,299
on the data structures because that will be
a basic building block for for the data science
4481
07:35:09,299 --> 07:35:10,299
packages, too. If we if we know very well
about these data structures, these data structures,
4482
07:35:10,299 --> 07:35:11,299
we will be very fluent in the data science
packages and working with those. Okay, hope
4483
07:35:11,299 --> 07:35:12,299
to see you in the next video. Okay, in the
last video, we define less topple set and
4484
07:35:12,299 --> 07:35:13,299
dictionary and we actually access different
values. In this video, I'm going to actually,
4485
07:35:13,299 --> 07:35:14,299
I'm going to actually introduce more indexing,
how to access list and topple in particular,
4486
07:35:14,299 --> 07:35:15,299
because the both are very, very easily indexable
like strings. And I want to show you that
4487
07:35:15,299 --> 07:35:16,299
all kinds of indexing that you have seen in
strings, exactly works and list as well as
4488
07:35:16,299 --> 07:35:17,299
in tupple. So let's go to Jupiter, and see
what a list is, for example, a list, if you
4489
07:35:17,299 --> 07:35:18,299
print the list, that's the list, it has these
kinds of values, if you just see the list,
4490
07:35:18,299 --> 07:35:19,299
for example, starting from index one, ending
at index three, that that means the same big
4491
07:35:19,299 --> 07:35:20,299
a slice for example. So index one value is
three, index to value is 4.9. And the last
4492
07:35:20,299 --> 07:35:21,299
element is not included. So, if you get that
you get three and 4.9. So exactly the same,
4493
07:35:21,299 --> 07:35:22,299
the same kind of indexing that you have seen
in strings, exactly there is working here
4494
07:35:22,299 --> 07:35:23,299
as well. So for example, if I say list, start
from the beginning go to N but then I just
4495
07:35:23,299 --> 07:35:24,299
give minus one it will reverse the whole list,
I mean the whole list will be reversed. I'm
4496
07:35:24,299 --> 07:35:25,299
in all the same all the things that that we
saw in in string indexing stays exactly the
4497
07:35:25,299 --> 07:35:26,299
same in list as well as in topple, so topple
For example, let's access element from let's
4498
07:35:26,299 --> 07:35:27,299
say from the very beginning till the till
the third element, that's not the third element
4499
07:35:27,299 --> 07:35:28,299
till index three, which is actually the fourth
element. So topple unless they are exactly
4500
07:35:28,299 --> 07:35:29,299
they will be exactly index as as it as it
is. So all the slicing all the indexing all
4501
07:35:29,299 --> 07:35:30,299
the sub sub listings, all all the sub topples,
they can be accessed exactly the same way
4502
07:35:30,299 --> 07:35:31,299
as you as you've gone through through the
through the strings. One difference here that
4503
07:35:31,299 --> 07:35:32,299
I will explain later on, because list is mutable
it is changeable, I will discuss one thing
4504
07:35:32,299 --> 07:35:33,299
that one use when you slice it, when you get
a sub list then actually it refers to the
4505
07:35:33,299 --> 07:35:34,299
same memory and if you change the sub list
contents, the actual list chord changes. That
4506
07:35:34,299 --> 07:35:35,299
is that is true for list in slicing. And that
is true for sets and dictionaries, in the
4507
07:35:35,299 --> 07:35:36,299
copying the references and so on. So I will
discuss that later on. But rest of the things
4508
07:35:36,299 --> 07:35:37,299
are roughly the same as as they're in string
indexing. Actually, indexing is almost the
4509
07:35:37,299 --> 07:35:38,299
same everywhere in Python, it has this kind
of slicing is almost the same if you know
4510
07:35:38,299 --> 07:35:39,299
the index, how to index planes, you know how
to index lists, if you know how to index lists,
4511
07:35:39,299 --> 07:35:40,299
you know how to index couples and strings
and, and everything. And by the way, if you
4512
07:35:40,299 --> 07:35:41,299
know how to index strength lists, you will
be very fluent and NumPy. That's the very
4513
07:35:41,299 --> 07:35:42,299
powerful data structure. That's very powerful
kind of array processing package. with with
4514
07:35:42,299 --> 07:35:43,299
with some defenses that we will see but
4515
07:35:43,299 --> 07:35:44,299
even the indexing is same in pandas when you
are working with large amount of data data
4516
07:35:44,299 --> 07:35:45,299
file and stuff like so the indexing is more
or less the same that you've seen in instruments
4517
07:35:45,299 --> 07:35:46,299
we will we will cover indexing, masking and
fancy kind of indexing in much more detail
4518
07:35:46,299 --> 07:35:47,299
in NumPy. But this stays the same as, as you've
seen in in, in strengths Okay, so now can
4519
07:35:47,299 --> 07:35:48,299
we can we expand the list can we add more
elements? Can we insert more elements to the
4520
07:35:48,299 --> 07:35:49,299
list? The answer is yes. Because list is changeable.
New trouble you can insert more elements.
4521
07:35:49,299 --> 07:35:50,299
One way of inserting there is just to call
an add operator, you can just add plus and
4522
07:35:50,299 --> 07:35:51,299
you just insert in other lists like like two
strings are concatenated by plus two lists
4523
07:35:51,299 --> 07:35:52,299
can be concatenated, or combined together
again by plus, but there is a faster function
4524
07:35:52,299 --> 07:35:53,299
called append l dot append. That is sometimes
faster than using this operator we will see
4525
07:35:53,299 --> 07:35:54,299
that topple because it is immutable. You cannot
touch any content of the double you cannot
4526
07:35:54,299 --> 07:35:55,299
actually insert any element to a topple you
cannot delete any element to a tupple. There
4527
07:35:55,299 --> 07:35:56,299
are workarounds for example, convert a tupple
to a last change it then convert the list
4528
07:35:56,299 --> 07:35:57,299
to a tupple. There are ways to do that. But
tupple in its true sense, in the literal sense,
4529
07:35:57,299 --> 07:35:58,299
it is immutable. You cannot insert any elements
you cannot delete any element you cannot change
4530
07:35:58,299 --> 07:35:59,299
any element. However, you can combine two
tuples. Together, you can concatenate two
4531
07:35:59,299 --> 07:36:00,299
tuples together again by plus operator and
save the result into a new double that's possible
4532
07:36:00,299 --> 07:36:01,299
set. The you can insert elements using an
add function add function allows you to just
4533
07:36:01,299 --> 07:36:02,299
insert one element. If you want to insert
more than one elements, then you can call
4534
07:36:02,299 --> 07:36:03,299
an update function that actually accepts more
than one that accepts another set that need
4535
07:36:03,299 --> 07:36:04,299
to be inserted. That's possible dictionary,
you can insert a new key by just the new key
4536
07:36:04,299 --> 07:36:05,299
equals to that you just assign a new value
to a new key and key value pair is just inserted
4537
07:36:05,299 --> 07:36:06,299
there great, you can delete or remove any
element from the list using D l Command D
4538
07:36:06,299 --> 07:36:07,299
l l one that means the this particular element
is deleted from the list that is possible.
4539
07:36:07,299 --> 07:36:08,299
Deleting particular element from the tupple
is not possible However, you can delete the
4540
07:36:08,299 --> 07:36:09,299
whole variable whole topple that is possible,
you can remove elements from the set using
4541
07:36:09,299 --> 07:36:10,299
remove function as dot remove, and then you
just give the element that you want to remove
4542
07:36:10,299 --> 07:36:11,299
that as possible, it will be removed and you
can delete the whole delete the whole variable
4543
07:36:11,299 --> 07:36:12,299
that is always available. Similarly, you can
delete a particular item from the dictionary
4544
07:36:12,299 --> 07:36:13,299
by just deleting by just calling the D of
the value for example, whatever the key is,
4545
07:36:13,299 --> 07:36:14,299
so you call with the key and call the Delete
and it will delete everything I want to mention
4546
07:36:14,299 --> 07:36:15,299
here for to remove items from the list there
are other methods and functions that are also
4547
07:36:15,299 --> 07:36:16,299
available that I mean there is a remove function,
there is a pop function, these are available.
4548
07:36:16,299 --> 07:36:17,299
Similarly, from removing elements from the
dictionary, there are other functions that
4549
07:36:17,299 --> 07:36:18,299
are available. But just to compare them together,
I am using this de l command, although there
4550
07:36:18,299 --> 07:36:19,299
are other ways of doing the same stuff, as
well. So let's let's let's let's end this
4551
07:36:19,299 --> 07:36:20,299
video here. And in the next video, I will
show you all these operations that concatenating
4552
07:36:20,299 --> 07:36:21,299
together, inserting more elements, deleting
different elements, I will show you all these
4553
07:36:21,299 --> 07:36:22,299
things in in Python. So So hope to see you
in the next video. Okay, in the last video,
4554
07:36:22,299 --> 07:36:23,299
we saw how to insert different elements to
different data structures. And we for example,
4555
07:36:23,299 --> 07:36:24,299
in the case of tuples, it is not possible.
And we also saw how to how to actually delete
4556
07:36:24,299 --> 07:36:25,299
different elements wherever possible. So let's
go to our friend Jupyter Notebook and see
4557
07:36:25,299 --> 07:36:26,299
all these concepts in a running form. So let's
go. Okay, so let's say for example, we have
4558
07:36:26,299 --> 07:36:27,299
list, that's our list. Let's append an element
to the list or maybe more elements, that is
4559
07:36:27,299 --> 07:36:28,299
L plus. Let's say we can have another list
for example, how
4560
07:36:28,299 --> 07:36:29,299
are
4561
07:36:29,299 --> 07:36:30,299
that's six, and then you that's and these
two lists will be appended and the new list
4562
07:36:30,299 --> 07:36:31,299
will be as you can see this similarly we can
append an item using append function for example
4563
07:36:31,299 --> 07:36:32,299
6.8 that will also be appended and this will
contain these kind of values. So yeah, so
4564
07:36:32,299 --> 07:36:33,299
both arrays are fine. This plus is this plus
can be used to append to append to lists and
4565
07:36:33,299 --> 07:36:34,299
this append function can be used to simply
append a list with a with an element. Okay,
4566
07:36:34,299 --> 07:36:35,299
great topples. You cannot change the topple,
you cannot change the topple. But what you
4567
07:36:35,299 --> 07:36:36,299
can do is you can have two tuples for example,
T two is a different couple. Let's say a A
4568
07:36:36,299 --> 07:36:37,299
and B, and let's say you have four or five,
that's it that's supposed to, then you can
4569
07:36:37,299 --> 07:36:38,299
have a third double, that is just the combination
of double one and double two. And in this
4570
07:36:38,299 --> 07:36:39,299
case, you have double three, which is this.
Yeah, so double one and double two are combined
4571
07:36:39,299 --> 07:36:40,299
together, but you cannot actually insert into
the assembly, the tuple is immutable, you
4572
07:36:40,299 --> 07:36:41,299
cannot insert another element, you cannot
delete existing elements, you cannot update
4573
07:36:41,299 --> 07:36:42,299
any element and so on. Similarly, as the set,
let's see the state of the set, that's the
4574
07:36:42,299 --> 07:36:43,299
set set God add function, you can add anything,
let's if the six that is added there, and
4575
07:36:43,299 --> 07:36:44,299
the new state of assets this, or you can call
the update function. If you update method,
4576
07:36:44,299 --> 07:36:45,299
if you want to insert more elements, for example,
if you have multiple elements to be inserted
4577
07:36:45,299 --> 07:36:46,299
23. Again, and let's say you wanted to insert
an element that is already there. So for example,
4578
07:36:46,299 --> 07:36:47,299
one, then the duplicates will no longer be
there, but the new elements will be inserted.
4579
07:36:47,299 --> 07:36:48,299
Now let's see the state of D, the state of
D is this. If you want to add another key
4580
07:36:48,299 --> 07:36:49,299
value pair, you can add a key here, for example,
the key might be new key, for example, new
4581
07:36:49,299 --> 07:36:50,299
key and the value might be the value might
be, for example, a new value. Well, and now
4582
07:36:50,299 --> 07:36:51,299
if you see D, the D, the contents of the D
has changed. Well, that's simple. Yeah, great.
4583
07:36:51,299 --> 07:36:52,299
Can you concatenate two dictionaries together
using a plus operator? Is it possible? Is
4584
07:36:52,299 --> 07:36:53,299
it possible to concatenate two dictionaries
together? Let's see I have another I have
4585
07:36:53,299 --> 07:36:54,299
another dictionaries dictionary D two. That
is that say the key is why. and the value
4586
07:36:54,299 --> 07:36:55,299
is why why? And then we have another key letter
Z. and the value is. Let's sit down, can I
4587
07:36:55,299 --> 07:36:56,299
can get an A D and D two together? Can I?
Can I just update my D and add these values?
4588
07:36:56,299 --> 07:36:57,299
insert these values also there? Okay. I left
you with this question. You try to answer
4589
07:36:57,299 --> 07:36:58,299
this. And in the next video will answer this
question. But try to answer this question
4590
07:36:58,299 --> 07:36:59,299
yourself. And one way to try that is just
to go in Jupiter and just dive and check whether
4591
07:36:59,299 --> 07:37:00,299
plus is working or not. Or maybe there is
another method and stuff like so. Okay, great.
4592
07:37:00,299 --> 07:37:01,299
Hope to see you. Oh, I have not used the D
l delete and all that stuff, and so on. So
4593
07:37:01,299 --> 07:37:02,299
this question is there, let me use the removing
the elements. So let's say l is this list.
4594
07:37:02,299 --> 07:37:03,299
If I want to remove an element, let's say
element number three, if I want to remove
4595
07:37:03,299 --> 07:37:04,299
element at index three, which is this string
name, I can use simply this delete. And the
4596
07:37:04,299 --> 07:37:05,299
L is everything but without that element.
Similarly, I can remove if I want to remove
4597
07:37:05,299 --> 07:37:06,299
any element from S, I can call the function
remove. And whatever I want to remove, let's
4598
07:37:06,299 --> 07:37:07,299
say want to remove game, and the game will
no longer be there.
4599
07:37:07,299 --> 07:37:08,299
Great. If I want to remove some element from
dictionary, again, let's say that's the that's
4600
07:37:08,299 --> 07:37:09,299
the view of dictionary. I can call the Add
I can I can remove the element with key let's
4601
07:37:09,299 --> 07:37:10,299
say C, whatever the element is with key C,
delete that element, and the dictionary has
4602
07:37:10,299 --> 07:37:11,299
this particular state with this item, this
particular item is gone. Okay, great. I can
4603
07:37:11,299 --> 07:37:12,299
do that. But But d L is not the only way of
doing that. There are so many methods. I mean,
4604
07:37:12,299 --> 07:37:13,299
a lot of methods to do that. But just to just
to compare all these, I'm just giving you
4605
07:37:13,299 --> 07:37:14,299
the most similarities and differences wherever
available. Okay, great. So I have asked you
4606
07:37:14,299 --> 07:37:15,299
a question in this particular video. Can we
concatenate two dictionaries together, particularly
4607
07:37:15,299 --> 07:37:16,299
with a plus operator? If yes, then we are
done. If not, then Are there other ways and
4608
07:37:16,299 --> 07:37:17,299
stuff like so that's the question. So hope
to see you in the next video with more on
4609
07:37:17,299 --> 07:37:18,299
these data structures.
4610
07:37:18,299 --> 07:37:19,299
Okay, I asked you a question last time. Can
we concatenate this two dictionaries together
4611
07:37:19,299 --> 07:37:20,299
with a plus operator? So what's your answer?
Yes or no? The answer is Nope, yeah, so we
4612
07:37:20,299 --> 07:37:21,299
cannot concatenate them together, we cannot
insert another dictionary to this dictionary
4613
07:37:21,299 --> 07:37:22,299
using a plus operator. Because this plus operator
is not defined for dictionary, what we can
4614
07:37:22,299 --> 07:37:23,299
do is we can call an update function, because
dictionary is also a set, I mean, a set of
4615
07:37:23,299 --> 07:37:24,299
key value pairs. But at the end of the day,
it's a set with specialized function, of course,
4616
07:37:24,299 --> 07:37:25,299
but we can call update functions, and insert
the whole new dictionary inside dictionary
4617
07:37:25,299 --> 07:37:26,299
as as as follows. Yeah, so the answer is using
plus operator No, but there is a way using
4618
07:37:26,299 --> 07:37:27,299
update method. Right. So next, we focus on
the copy function, the copy function is available
4619
07:37:27,299 --> 07:37:28,299
for less the copy function is available for
set, the copy function is available for dictionary.
4620
07:37:28,299 --> 07:37:29,299
So let's see the need of this copy function
here, I want you to be very careful. Because
4621
07:37:29,299 --> 07:37:30,299
that's, that's really important. Let's say
we have a list, let's say, That's list. And
4622
07:37:30,299 --> 07:37:31,299
by the way, the same goes with set and dictionary
as well, whatever I'm going to do with list,
4623
07:37:31,299 --> 07:37:32,299
let's see a list. Now, what you do is you
copy the list or you just make another variable,
4624
07:37:32,299 --> 07:37:33,299
like you can assign the value of l to another
variable l two, what you do is that now l
4625
07:37:33,299 --> 07:37:34,299
two is also has this, now these are two different
variables, L is this variable, l two is this
4626
07:37:34,299 --> 07:37:35,299
variable. So you might be thinking l two is
separately a completely a new thing. And Alice
4627
07:37:35,299 --> 07:37:36,299
new thing, you might be thinking that both
are independent. But Python internally manages
4628
07:37:36,299 --> 07:37:37,299
the data structures, most of the data structures
in a way that because the data structure is
4629
07:37:37,299 --> 07:37:38,299
a collection of a lot of data it has it is
consuming a lot of memory, what it does is
4630
07:37:38,299 --> 07:37:39,299
when you assign a variable, or data structure
to to another variable, it does not actually
4631
07:37:39,299 --> 07:37:40,299
copy all the contents, it does not actually
make a new memory, and store the contents
4632
07:37:40,299 --> 07:37:41,299
in this. It actually this variable also actually
points to the same memory as this. and and,
4633
07:37:41,299 --> 07:37:42,299
and and the consequence of that if you change
any value, for example, in L two, let's say
4634
07:37:42,299 --> 07:37:43,299
you change the index to value from this, the
index to values 4.9. Now you're working in
4635
07:37:43,299 --> 07:37:44,299
L two, let's say you change this L to value
from 4.9. To Let's 4.9. Let's see you do that.
4636
07:37:44,299 --> 07:37:45,299
So you might be thinking that this happens
in L two, well, in L two, that has happened.
4637
07:37:45,299 --> 07:37:46,299
But what it also does is it does the same
thing in L as well. So l also changes. The
4638
07:37:46,299 --> 07:37:47,299
reason is L and L two, they both are pointing
to this structure in the memory. And whether
4639
07:37:47,299 --> 07:37:48,299
you approach that structure through L, or
you approach that structure two l two, you're
4640
07:37:48,299 --> 07:37:49,299
approaching the same memory anyway. And that
is called referencing I mean, it does not
4641
07:37:49,299 --> 07:37:50,299
create the data, it actually create a reference
in the memory to actually create a new name
4642
07:37:50,299 --> 07:37:51,299
for the same memory. And both are pointing
to or accessing to the same memory. And if
4643
07:37:51,299 --> 07:37:52,299
you really want the behavior so that l two
becomes different than L and what I what I
4644
07:37:52,299 --> 07:37:53,299
do with L two, that should not affect L, then
you should call copy function. l two is L
4645
07:37:53,299 --> 07:37:54,299
dot copy. Yeah. So that's the function, I'll
copy. Now you have l two. Now you do whatever
4646
07:37:54,299 --> 07:37:55,299
with L two, it will not affect L. So l two,
for example, index at index two, you again
4647
07:37:55,299 --> 07:37:56,299
say okay, this is 4.9. So l two changes. Now,
l two changes, but l doesn't change, l doesn't
4648
07:37:56,299 --> 07:37:57,299
change, l stays the same. Now this is different
copy, same concept, go with the set. And same
4649
07:37:57,299 --> 07:37:58,299
concept go with with the dictionary. If you
if you just make another way will s two n
4650
07:37:58,299 --> 07:37:59,299
equals two s, then if you change the contents
of s two s will change. If you don't want
4651
07:37:59,299 --> 07:38:00,299
that, then copy it similarly copy the dictionary,
because the contents of the topple they are
4652
07:38:00,299 --> 07:38:01,299
not changeable. The copy function is not available
for double. Because even if you assign this
4653
07:38:01,299 --> 07:38:02,299
T to T two, you can now not change D two because
it is immutable. So having a copy function
4654
07:38:02,299 --> 07:38:03,299
doesn't make sense in tupple. Wait.
4655
07:38:03,299 --> 07:38:04,299
One more thing regarding slicing. Let's say
you have let's say you have Dell that's available
4656
07:38:04,299 --> 07:38:05,299
to you like so that's L and let's say you
make l three another list by slicing Let's
4657
07:38:05,299 --> 07:38:06,299
say a list from let's say one to five, let's
say. So you start from index one, which is
4658
07:38:06,299 --> 07:38:07,299
three, and you go to five by not including
five, this way, the L three is automatically
4659
07:38:07,299 --> 07:38:08,299
a copy, it is not a sub list, which is referencing.
So l three. So l three is a different l two
4660
07:38:08,299 --> 07:38:09,299
is a completely new list, a new memory view,
if you change the contents in L, three, if
4661
07:38:09,299 --> 07:38:10,299
you change the contents in L three, for example,
l three, or index zero, it should go from
4662
07:38:10,299 --> 07:38:11,299
three to let's say, three, if you change the
contents in L three, these contents, these
4663
07:38:11,299 --> 07:38:12,299
change will not reflect an L. So if you do
the slicing, slicing picks a copy by default,
4664
07:38:12,299 --> 07:38:13,299
it does not pick a reference. And that's a
huge difference between this list and a NumPy
4665
07:38:13,299 --> 07:38:14,299
array, when you end it, we'll see that when
we will see a NumPy array, the slicing actually
4666
07:38:14,299 --> 07:38:15,299
also, again refers to the same memory location.
And that might be one difference in indexing,
4667
07:38:15,299 --> 07:38:16,299
indexing in the whole Python, whenever you
do slicing, you get a copy. But in NumPy,
4668
07:38:16,299 --> 07:38:17,299
when we'll see NumPy in detail, in NumPy,
when you do slicing, you get again a view
4669
07:38:17,299 --> 07:38:18,299
not a copy, and if you change in the slice
torian anything the actual the actual contents
4670
07:38:18,299 --> 07:38:19,299
also changed. And there is a reason to do
that there is a there are efficient reasons
4671
07:38:19,299 --> 07:38:20,299
to do that and stuff like so, again, the dot
copy function becomes the copy function become
4672
07:38:20,299 --> 07:38:21,299
much more applicable there as well. So, so,
so you need to know that even if you do if
4673
07:38:21,299 --> 07:38:22,299
you do slicing in general in Python in any
collection in any array, in any, if you do
4674
07:38:22,299 --> 07:38:23,299
select a collection for even for mutable objects
like list, you get a copy, but in NumPy array,
4675
07:38:23,299 --> 07:38:24,299
the things the things these things, this particular
thing with with a lot of other things this
4676
07:38:24,299 --> 07:38:25,299
but this indexing scheme actually changing,
changes with with this kind of slicing. Okay,
4677
07:38:25,299 --> 07:38:26,299
so I am this video here, I mean, you can explore
much more functions of lists tupple, seven
4678
07:38:26,299 --> 07:38:27,299
dictionary and what you can do with each of
them, and what you I mean, in which scenario,
4679
07:38:27,299 --> 07:38:28,299
what kind of thing is more suitable for the
other that completely depends upon the problem
4680
07:38:28,299 --> 07:38:29,299
at hand. But what we can do in what what we
will do what we'll be doing in the less next
4681
07:38:29,299 --> 07:38:30,299
video, we will be seeing some using some functions
of just list. And then I will be just just
4682
07:38:30,299 --> 07:38:31,299
letting you to explore the the tupple set
and dictionary and all their functions on
4683
07:38:31,299 --> 07:38:32,299
your own. And to see what function or what
method is doing what for what, which kind
4684
07:38:32,299 --> 07:38:33,299
of data structure. So in the next video, we
will be seeing some methods just for list
4685
07:38:33,299 --> 07:38:34,299
data structure. Hope to see you in the next
video. Like in screens. Let's Let's explore
4686
07:38:34,299 --> 07:38:35,299
a lot of functions in list. Although in, in
in sets and dictionaries and tuples tuples,
4687
07:38:35,299 --> 07:38:36,299
as well. But many more functions are available
in list. And by the way, let's see how many
4688
07:38:36,299 --> 07:38:37,299
things are there in this list. And let's say
l dot tab, and tab will open up a lot of things
4689
07:38:37,299 --> 07:38:38,299
with me for me abanda we know already clear
copy, copy, we know already count, we don't
4690
07:38:38,299 --> 07:38:39,299
know count, extend, index insert, pop remove
reverse some of these functions. They make
4691
07:38:39,299 --> 07:38:40,299
sense by the adjuster name. But let's see
one by one. Let's see some of those. What
4692
07:38:40,299 --> 07:38:41,299
they do. One way to do that is go to internet
and see some book or tutorial or something
4693
07:38:41,299 --> 07:38:42,299
like So another way is just write this apply.
Maybe, maybe help function maybe apply a help
4694
07:38:42,299 --> 07:38:43,299
function, it may help you how to use that.
Great this help function is great. So abandoned
4695
07:38:43,299 --> 07:38:44,299
object method of building list in stance about
an object to end of the list. Oh, it appends
4696
07:38:44,299 --> 07:38:45,299
an object to the end of the list. Which means
4697
07:38:45,299 --> 07:38:46,299
we may be able to append another list to to
a list maybe. Have you thought about that.
4698
07:38:46,299 --> 07:38:47,299
The append method just takes 111 object. Maybe
it takes a whole lot of list. But then it
4699
07:38:47,299 --> 07:38:48,299
may be possible that a list is appended inside
another list and that whole list becomes becomes
4700
07:38:48,299 --> 07:38:49,299
one element because list can contain other
lists as elements are that's a problem. Yeah.
4701
07:38:49,299 --> 07:38:50,299
So let's see more functions. Yeah, so let's
see clear what this clear What is this clear
4702
07:38:50,299 --> 07:38:51,299
what it does? Sometimes I use help, sometimes
it's used that remove all items from the list,
4703
07:38:51,299 --> 07:38:52,299
oh my god, if you call the clear that the
list is empty, okay? If you just call clear
4704
07:38:52,299 --> 07:38:53,299
function on a list will become empty. Be careful.
Okay, great. What else? So that see I have
4705
07:38:53,299 --> 07:38:54,299
this function maybe, Bob, what does Bob does
watch. So let's see. So Bob removes and returns
4706
07:38:54,299 --> 07:38:55,299
item at index defaulted the last, which means
if you also that's the default value remember
4707
07:38:55,299 --> 07:38:56,299
the default value. So, if you call a part
function without an index, it will return
4708
07:38:56,299 --> 07:38:57,299
it will remove the index it will delete the
last item and it will give you that it will
4709
07:38:57,299 --> 07:38:58,299
return that are if you give an index, it will
remove that value at that index. And it will
4710
07:38:58,299 --> 07:38:59,299
after removing it will return you that. So
you can use it wherever you want. So there
4711
07:38:59,299 --> 07:39:00,299
are many more functions for example, you can
see all of them one by one remove function,
4712
07:39:00,299 --> 07:39:01,299
for example, reverse reverse, like, like,
like the name suggests, if you call the reverse
4713
07:39:01,299 --> 07:39:02,299
function, the list will be reversed. Yeah,
and remember, we have reversed the list in
4714
07:39:02,299 --> 07:39:03,299
the following way as well, we have a way of
reversing any way, this way. So now if you
4715
07:39:03,299 --> 07:39:04,299
see the list is again reversed. So I guess
both of them are working like so same. Similarly,
4716
07:39:04,299 --> 07:39:05,299
you can explore several functions from a set,
you go and say add Clear. Clear might be working
4717
07:39:05,299 --> 07:39:06,299
as same as intersection intersection and update
is destroyed is a subset of the other. Yeah,
4718
07:39:06,299 --> 07:39:07,299
add by default or update by default, actually
take a union. So I'm not seeing update function.
4719
07:39:07,299 --> 07:39:08,299
Here it is update. Oh, union is there update
is there, which means the list you're seeing
4720
07:39:08,299 --> 07:39:09,299
is here is not a complete list you may be
writing, what are the functions that start
4721
07:39:09,299 --> 07:39:10,299
from you. So here are the and and several
others. Similarly, you can go to dictionary
4722
07:39:10,299 --> 07:39:11,299
and call for several functions clear copy
from keys get items. That item might be might
4723
07:39:11,299 --> 07:39:12,299
be interesting. What is this item? what it
does? Oh, it has an error? What? So how can
4724
07:39:12,299 --> 07:39:13,299
you use this? How can you use this function?
Let's see, oh, this is just an object, it
4725
07:39:13,299 --> 07:39:14,299
is not a function? I don't know.
4726
07:39:14,299 --> 07:39:15,299
Let's see again, are it is not listed anywhere?
Oh, it is items not item. Okay, items. That's
4727
07:39:15,299 --> 07:39:16,299
a function maybe. So these are all the items
23 with this, be with that new key with that,
4728
07:39:16,299 --> 07:39:17,299
and so on. Great. So actually, the purpose
here is not to tell you each and every function,
4729
07:39:17,299 --> 07:39:18,299
what it does, it will take a whole lot of
time. You can go and explore all these functions.
4730
07:39:18,299 --> 07:39:19,299
The purpose here is to tell you what kind
of data structure has, what kind of properties
4731
07:39:19,299 --> 07:39:20,299
and what are the similarities and differences
in between. So if you remember this one slide,
4732
07:39:20,299 --> 07:39:21,299
for list, double seven dictionary and some
text that is written out above, you'll be
4733
07:39:21,299 --> 07:39:22,299
having very good knowledge of where to pick
what kind of data structure in practice. So
4734
07:39:22,299 --> 07:39:23,299
in the next video, I'll be actually going
to Jupyter Notebook as our as our style and
4735
07:39:23,299 --> 07:39:24,299
I will be coding or solving some problem for
you that will involve list topple set or dictionary
4736
07:39:24,299 --> 07:39:25,299
are one of them or we will be choosing based
on problem what kind of data structure is
4737
07:39:25,299 --> 07:39:26,299
well and what so we'll be doing that. But
before that, I just want to I just want to
4738
07:39:26,299 --> 07:39:27,299
I just want to mention that list tupple set
or dictionary they can contain any items inside
4739
07:39:27,299 --> 07:39:28,299
any kind of type, which means a list can contain
another list. A list can contain a set a list
4740
07:39:28,299 --> 07:39:29,299
can contain a dictionary, a list of dictionary
can contain a list which itself contains a
4741
07:39:29,299 --> 07:39:30,299
dictionary, I mean, this is all abstract,
this is all abstract, one thing can contain
4742
07:39:30,299 --> 07:39:31,299
the other one thing can contain an instance
of I mean, a list can contain multiple lists.
4743
07:39:31,299 --> 07:39:32,299
And those lists can contain more or less and
so on. So before actually going to problem
4744
07:39:32,299 --> 07:39:33,299
solving, let me give you a flavor of that
how abstract these things are. Let me give
4745
07:39:33,299 --> 07:39:34,299
you a flavor of that in in just just in a
couple of examples. So in the next video I'll
4746
07:39:34,299 --> 07:39:35,299
be giving you a couple of examples based on
the abstract mess of these data structures.
4747
07:39:35,299 --> 07:39:36,299
And from the next next video, we'll be probably,
we will be doing some problem solving based
4748
07:39:36,299 --> 07:39:37,299
on that. So next two videos are completely
on Jupyter notebooks. So get ready, I hope
4749
07:39:37,299 --> 07:39:38,299
to see you in the next video. Okay, let's
see the abstractness of all these data structures.
4750
07:39:38,299 --> 07:39:39,299
Let's see just one example. Let's say we have
l as the list, we have all rich top all that
4751
07:39:39,299 --> 07:39:40,299
stuff. So let's say we have set that set,
let's say n, we have dictionary, that's a
4752
07:39:40,299 --> 07:39:41,299
dictionary. Okay? So let's say we have all
these things that say available somewhere.
4753
07:39:41,299 --> 07:39:42,299
So let's make another dictionary. For example,
let's say D, D, Ma, that's a D tool. And that
4754
07:39:42,299 --> 07:39:43,299
dictionary has key value pairs less The key
is a and the value is whole list l master
4755
07:39:43,299 --> 07:39:44,299
value is possible. Let's say the key is B.
and the value is just to topple the whole
4756
07:39:44,299 --> 07:39:45,299
topple, that's the value. Let's say the key
is C, and the value is the set. And let's
4757
07:39:45,299 --> 07:39:46,299
say the key is D, and the value is the dictionary,
the whole dictionary D it is possible. I mean,
4758
07:39:46,299 --> 07:39:47,299
you can just do that, that that is just one
example, oh, what's Oh sorry, I should have
4759
07:39:47,299 --> 07:39:48,299
I should have incorporated this way. Okay,
so this is possible. Now, for example, if
4760
07:39:48,299 --> 07:39:49,299
I access, if I access the element with, let's
say, a, I will, I will get the whole list.
4761
07:39:49,299 --> 07:39:50,299
And not only that, I can again access the
whole element. And then after that, for that
4762
07:39:50,299 --> 07:39:51,299
element, I can access for example, the third
element, the element at index three. So this
4763
07:39:51,299 --> 07:39:52,299
particular, this particular first level will
extract the list. And that will in that is
4764
07:39:52,299 --> 07:39:53,299
just the indexing or for that list. See, for
example, if
4765
07:39:53,299 --> 07:39:54,299
I access D two, and inside the tool, if I
access the dictionary that is inside, and
4766
07:39:54,299 --> 07:39:55,299
let's say I save that dictionary in k, then
it I can see the contents of K but I can just
4767
07:39:55,299 --> 07:39:56,299
for example, this or I can just access all
elements of this dictionary, or k by just
4768
07:39:56,299 --> 07:39:57,299
having 4x in gay brand, for example, x and
k of x, just do that i can i can just do that
4769
07:39:57,299 --> 07:39:58,299
we have done that in loops as well. So I want
to tell you that the these even if for example,
4770
07:39:58,299 --> 07:39:59,299
if you want to create a list l let's say l
three let's say you want to create a list
4771
07:39:59,299 --> 07:40:00,299
that can contain a whole list that can contain
what will get Oh, I mean one element is the
4772
07:40:00,299 --> 07:40:01,299
list another element is to pull another element
is the whole dictionary inside and then you
4773
07:40:01,299 --> 07:40:02,299
have some other elements let's Lee's game
and that's perfectly fine i get i mean you
4774
07:40:02,299 --> 07:40:03,299
can do that, these data structures are much
more abstract I mean now if you for example,
4775
07:40:03,299 --> 07:40:04,299
access element at index two which is dictionary,
that is completely a dictionary if you if
4776
07:40:04,299 --> 07:40:05,299
you check the type of that element that that
will be a dictionary object and you can extract
4777
07:40:05,299 --> 07:40:06,299
that element and play the way you want to
play and whatever. One more thing if you can,
4778
07:40:06,299 --> 07:40:07,299
for example lists we can let's say we want
to make a list list very quickly for example
4779
07:40:07,299 --> 07:40:08,299
list off all the squares till till starting
from zero list of all the squares till till
4780
07:40:08,299 --> 07:40:09,299
10 for example zero square one square to square
let's say we want a list of that. So one way
4781
07:40:09,299 --> 07:40:10,299
of doing that is a quick shortcut is to just
use the loops so in loops, for example, we
4782
07:40:10,299 --> 07:40:11,299
right okay, x square for x in range. Then
for example, so it will start from zero go
4783
07:40:11,299 --> 07:40:12,299
till nine, including nine and you will get
x one by one. And all this index is for making
4784
07:40:12,299 --> 07:40:13,299
a list of x squares where x starts from zero
and go to go to including nine go to nine
4785
07:40:13,299 --> 07:40:14,299
one by one and that's how you can make a list
and I'm in these kind of these are kind of
4786
07:40:14,299 --> 07:40:15,299
shortcuts. Again, you can make a sale For
example, let's say you want to make a set
4787
07:40:15,299 --> 07:40:16,299
of all the squares for x in range, let's say,
starting from starting from two, ending at
4788
07:40:16,299 --> 07:40:17,299
20. And you want to take a step of, let's
say three. So, start from index two go till
4789
07:40:17,299 --> 07:40:18,299
20 do not include 20, but take the step of
three, and you can now have a set, which is
4790
07:40:18,299 --> 07:40:19,299
which is this. I mean, there are, there are
a lot of ways of working these working with
4791
07:40:19,299 --> 07:40:20,299
these. One, one can explore more and more
about these things, but what what what the
4792
07:40:20,299 --> 07:40:21,299
basic thing about these data structures are,
they are very, very abstract, they can I mean,
4793
07:40:21,299 --> 07:40:22,299
a list can contain a dictionary, and that
dictionary can contain a topple and that will
4794
07:40:22,299 --> 07:40:23,299
have an element which is another list and
so on. It is that abstract, it allows you
4795
07:40:23,299 --> 07:40:24,299
to do each and everything in that way. Okay,
so I end this video here in the next video,
4796
07:40:24,299 --> 07:40:25,299
we will actually solve a problem using these
one of these data structures or we will try
4797
07:40:25,299 --> 07:40:26,299
to choose one of those. And that video naby
lengthy may be small, because we may have
4798
07:40:26,299 --> 07:40:27,299
bugs inside. And we will we will play around
with these data structures in the next video.
4799
07:40:27,299 --> 07:40:28,299
So do attend the next video because it's really
the practice and you will get your hands you
4800
07:40:28,299 --> 07:40:29,299
will get a very good grip on the data structures
in the solving the next problem that we are
4801
07:40:29,299 --> 07:40:30,299
that we are launching for you, okay, hope
to see you in the next video. Okay, let's
4802
07:40:30,299 --> 07:40:31,299
see a problem just to get comfortable with
these data structures. So let's let's design
4803
07:40:31,299 --> 07:40:32,299
some problem and solve that problem here using
using these data structures. So the problem
4804
07:40:32,299 --> 07:40:33,299
that I'm thinking is, let's say the following.
Let's say let's say you are you a teacher,
4805
07:40:33,299 --> 07:40:34,299
should I type all these things? Okay? Let's
say you're a teacher, you are a teacher. And
4806
07:40:34,299 --> 07:40:35,299
you have
4807
07:40:35,299 --> 07:40:36,299
different student records to learn records
containing containing ID of a student and
4808
07:40:36,299 --> 07:40:37,299
the mark marks list in each subject, where
different students have taken different number
4809
07:40:37,299 --> 07:40:38,299
of subjects. And all these records all these
records are in hardcopy. You want odd copy,
4810
07:40:38,299 --> 07:40:39,299
you want to enter all the data in computer
and want to compute the average marks of each
4811
07:40:39,299 --> 07:40:40,299
student. And display. That's the problem.
So the problem let's say is, you have for
4812
07:40:40,299 --> 07:40:41,299
example, you have a hardcopy you have you
have some papers, upon which you have different
4813
07:40:41,299 --> 07:40:42,299
students, each student have a different ID.
Some students may have taken seven subjects,
4814
07:40:42,299 --> 07:40:43,299
some student may have taken three subjects,
some student may have taken eight subjects
4815
07:40:43,299 --> 07:40:44,299
and so on different students may have taken
different subjects. Regardless there, you
4816
07:40:44,299 --> 07:40:45,299
want to first enter each for each student,
you want to first enter the records, I mean
4817
07:40:45,299 --> 07:40:46,299
all the data that is in and then you want
to compute from that data, you want to compute
4818
07:40:46,299 --> 07:40:47,299
the average marks of each student. For example,
if a student have taken five subjects, then
4819
07:40:47,299 --> 07:40:48,299
the marks for all the five subjects are available,
you just add all the marks and divide by five
4820
07:40:48,299 --> 07:40:49,299
and that's, let's say, the average marks.
So first of all, let's ride away two way to
4821
07:40:49,299 --> 07:40:50,299
compute for example, the to just collect the
data, how to collect the data. So let's write
4822
07:40:50,299 --> 07:40:51,299
a function for that. So let's say define a
function, let's say get data From user or
4823
07:40:51,299 --> 07:40:52,299
teacher, let's say, let's say that function,
and it returns data. Okay? So what I do really
4824
07:40:52,299 --> 07:40:53,299
is I say, okay, while
4825
07:40:53,299 --> 07:40:54,299
true,
4826
07:40:54,299 --> 07:40:55,299
I made a loop while true, just take the data
from the from the user, and the data is in
4827
07:40:55,299 --> 07:40:56,299
the form of you first say, okay, ID, student
ID, let's say that is inter, or actually input,
4828
07:40:56,299 --> 07:40:57,299
enter student ID. So he enters the the person
enters the student ID. Yeah. So adopt, you
4829
07:40:57,299 --> 07:40:58,299
might have define a dictionary, maybe a dictionary
D, that is empty right now. But you may, you
4830
07:40:58,299 --> 07:40:59,299
may add and remove different values. So what
you do is, you add a student ID, you get a
4831
07:40:59,299 --> 07:41:00,299
student ID, and in the string form, and then
you get the you get, for example, the input
4832
07:41:00,299 --> 07:41:01,299
as the marks list. So marks list as input.
Enter the marks,
4833
07:41:01,299 --> 07:41:02,299
by
4834
07:41:02,299 --> 07:41:03,299
comma
4835
07:41:03,299 --> 07:41:04,299
separated values. So enter the marks using
for example, if you have five subjects, just
4836
07:41:04,299 --> 07:41:05,299
write the five subject marks by separating
each with the comma, okay, then this, let's
4837
07:41:05,299 --> 07:41:06,299
see
4838
07:41:06,299 --> 07:41:07,299
more
4839
07:41:07,299 --> 07:41:08,299
students is equal to let's say input,
4840
07:41:08,299 --> 07:41:09,299
enter,
4841
07:41:09,299 --> 07:41:10,299
yes, or no.
4842
07:41:10,299 --> 07:41:11,299
for
4843
07:41:11,299 --> 07:41:12,299
adding more students, so if for example, you
have more data to insert, then press Yes,
4844
07:41:12,299 --> 07:41:13,299
otherwise personnel. So that's, for example,
our setup. So we will keep on getting more
4845
07:41:13,299 --> 07:41:14,299
and more, we will keep on getting more and
more data from the user user will keep on
4846
07:41:14,299 --> 07:41:15,299
increasing the data. But one thing that we
must know is that if for example, a student
4847
07:41:15,299 --> 07:41:16,299
ID, student ID is already in D, if that is
already in D, then we should give a message
4848
07:41:16,299 --> 07:41:17,299
brand. brand that student ID is already inserted.
So that might be a message else. ls we want
4849
07:41:17,299 --> 07:41:18,299
to do something else, what we want to do is
the following. What we want to do else is
4850
07:41:18,299 --> 07:41:19,299
we will make a dictionary, we already have
a dictionary with a student ID as our key,
4851
07:41:19,299 --> 07:41:20,299
that's our key. And at that key, what we do
is be the pick the marks list, and just split
4852
07:41:20,299 --> 07:41:21,299
it using comma because you're expecting and
all the marks they will be saved as a list.
4853
07:41:21,299 --> 07:41:22,299
So that will return a list. List of string
values. These are not indeed values, these
4854
07:41:22,299 --> 07:41:23,299
are string values. But all these lists they
are tagged by this ID. So that is a dictionary
4855
07:41:23,299 --> 07:41:24,299
that will be that we'll be getting populated
on and on and on. Further if we check F for
4856
07:41:24,299 --> 07:41:25,299
example, more students dot lower, for example,
let's call the lower function because the
4857
07:41:25,299 --> 07:41:26,299
user may interest at a lower form or if that
is equal to let's say no, that is equal to
4858
07:41:26,299 --> 07:41:27,299
No, if this is the case, or if there is no
enter for example.
4859
07:41:27,299 --> 07:41:28,299
No
4860
07:41:28,299 --> 07:41:29,299
inter no inter Know, to quit when insertion,
insertion into node with insertion. So let's
4861
07:41:29,299 --> 07:41:30,299
say that's your message. So wherever the user
inserted, if that's a no, then you return
4862
07:41:30,299 --> 07:41:31,299
the and that's it. Otherwise, you keep on
moving. So that's the whole goal. So you keep
4863
07:41:31,299 --> 07:41:32,299
on asking the, the, you keep on asking more
and more values. If whenever the teacher enters
4864
07:41:32,299 --> 07:41:33,299
a no, then you just return. Otherwise, you
keep an up, you make another equation, you
4865
07:41:33,299 --> 07:41:34,299
make another equation and keep on moving.
That's how you get the data. So the data will
4866
07:41:34,299 --> 07:41:35,299
be available to you. Once you are done with
that, then after that, we will see how to
4867
07:41:35,299 --> 07:41:36,299
once we have this data collected from the
user, then we will see how to compute marks
4868
07:41:36,299 --> 07:41:37,299
for each student individually average marks
and so on. So let's just check whether this
4869
07:41:37,299 --> 07:41:38,299
function works or not. So let's say we have
our dictionary that says student student data
4870
07:41:38,299 --> 07:41:39,299
is equal to get data from user, let's just
call that function. Let's see what happens.
4871
07:41:39,299 --> 07:41:40,299
Okay. Enter student ID, let's say ID is 12.
Okay, in remarks by comma separated values,
4872
07:41:40,299 --> 07:41:41,299
let's say, well, one, let's say
4873
07:41:41,299 --> 07:41:42,299
24,
4874
07:41:42,299 --> 07:41:43,299
comma 65, comma 87, let's say the first two
in just the first tool and just have these
4875
07:41:43,299 --> 07:41:44,299
three subjects, then internode width, so I
will enter something else. And oh, what's
4876
07:41:44,299 --> 07:41:45,299
the problem? There is a problem. If more students
taught lower is more student is not defined.
4877
07:41:45,299 --> 07:41:46,299
More student that's, I guess, more students,
more student here, oh, the spelling mistakes.
4878
07:41:46,299 --> 07:41:47,299
That's a huge mistake. So I just copy there,
these bugs are there. That's part of life.
4879
07:41:47,299 --> 07:41:48,299
Part of programming life, actually. So I guess
now it will work. So let's do the process
4880
07:41:48,299 --> 07:41:49,299
again. So 12, let's say, and the marks are
the six comma 45, comma, let's say a bad subject
4881
07:41:49,299 --> 07:41:50,299
with let's say, 13. into no to quit. No, I
will intro something else, I will keep on
4882
07:41:50,299 --> 07:41:51,299
moving. The other student is the student ID
is 45, let's say. And the marks that this
4883
07:41:51,299 --> 07:41:52,299
student has gained, actually, let's say this
student has, has registered has already registered
4884
07:41:52,299 --> 07:41:53,299
seven subject or let's say five subjects.
And the marks are, let's say 44 to five, six
4885
07:41:53,299 --> 07:41:54,299
to 677. And let's see a bad subject, let's
say four. Okay, then internodal, quit. No,
4886
07:41:54,299 --> 07:41:55,299
I want to insert one more, so do anything
else other than No. So student ID, let's say
4887
07:41:55,299 --> 07:41:56,299
now the student ID is 12. Again, let's say,
let's say want to insert another ID again.
4888
07:41:56,299 --> 07:41:57,299
And whatever the marks, let's say 45, and
45. Again, that's a now internode width, no
4889
07:41:57,299 --> 07:41:58,299
something else. But now, the message is there,
the 12 is already inserted, because the ID
4890
07:41:58,299 --> 07:41:59,299
the key value index, now you cannot repeat,
and so is the student value. So it does not
4891
07:41:59,299 --> 07:42:00,299
inserted the because this may be my mistake,
so it asks again. So now let's say I enter
4892
07:42:00,299 --> 07:42:01,299
ID, let's say 23. That's the ID or maybe a
different ID. That's the ID and the marks
4893
07:42:01,299 --> 07:42:02,299
are let's say 45, comma, 45. That's it. And
internodal grid. So let's say I enter No.
4894
07:42:02,299 --> 07:42:03,299
And that's it. So now I have received the
student data, if I show you the student data,
4895
07:42:03,299 --> 07:42:04,299
that student data is student data. That's
a dictionary, that's a dictionary with the
4896
07:42:04,299 --> 07:42:05,299
with key 12. And that's a list. But this list
contains all the values that are our string
4897
07:42:05,299 --> 07:42:06,299
type, we will see how to handle that. That's
a 45 as a key value, that's ID and that's
4898
07:42:06,299 --> 07:42:07,299
the marks list. And that's the ID in that
small list. Okay, great. Now we have student
4899
07:42:07,299 --> 07:42:08,299
data. Let's write another function that helps
us working on the student data, basically,
4900
07:42:08,299 --> 07:42:09,299
we want to find out the average marks of each
student. And then we want to print those.
4901
07:42:09,299 --> 07:42:10,299
So let's define another function and get average
marks of each student. And that function actually
4902
07:42:10,299 --> 07:42:11,299
receives this dictionary, let me call it as
D, any any variable, that's a local variable.
4903
07:42:11,299 --> 07:42:12,299
Okay, so what we want to do with that is the
following. Average marks for each student's,
4904
07:42:12,299 --> 07:42:13,299
so we will define another dictionary, let's
see everage marks dictionary, let's say that
4905
07:42:13,299 --> 07:42:14,299
is empty in the beginning, maybe, and then
what we do for x in D, let's icreate over
4906
07:42:14,299 --> 07:42:15,299
x and d, what we really do is we go to the
we find out the list of located at ELLs are
4907
07:42:15,299 --> 07:42:16,299
located at x L is basically D sub x. So that's
it, that's our list. That's our list that
4908
07:42:16,299 --> 07:42:17,299
is located there. So then what we do for i
in L. So for all i that is an L or let me
4909
07:42:17,299 --> 07:42:18,299
call it for marks, marks in L. In this particular
list, what you do is you actually have this
4910
07:42:18,299 --> 07:42:19,299
sum of sum is equal to zero right now,
4911
07:42:19,299 --> 07:42:20,299
there is no marks. So what you do is s plus
equals two marks, but convert the marks to
4912
07:42:20,299 --> 07:42:21,299
integer because they are already in string
format. We have we have saved everything instinct
4913
07:42:21,299 --> 07:42:22,299
string format, so you populate all the list.
Once you are done with this loop, the S will
4914
07:42:22,299 --> 07:42:23,299
contain the sum of all the marks, then what
you do is you compute the average and just
4915
07:42:23,299 --> 07:42:24,299
save that average in ABG. Marks decked dictionary,
let's say on average marks, just just don't
4916
07:42:24,299 --> 07:42:25,299
use the word deck, for example, you can but
let's stay gradual and add x, you just write
4917
07:42:25,299 --> 07:42:26,299
the average marks. And the average marks can
can be computed by s divided by length of
4918
07:42:26,299 --> 07:42:27,299
the list, whatever the list is. So that's
what the list is. Yeah, so that's the average
4919
07:42:27,299 --> 07:42:28,299
marks. And once you have an N one by one,
all the average marks will be populated. And
4920
07:42:28,299 --> 07:42:29,299
once we receive all these, we will then begin
then we can then just display by populating
4921
07:42:29,299 --> 07:42:30,299
the average marks. So let's see, let's call
that function. So let's call that function.
4922
07:42:30,299 --> 07:42:31,299
So ABG marks for example, equals to get a
VG marks, and let's bond these student data
4923
07:42:31,299 --> 07:42:32,299
inside. And if there is no error, then it
will return everything. Then just print the
4924
07:42:32,299 --> 07:42:33,299
average marks for each student for x in a
Vgm. brand, let's say student and Brand X
4925
07:42:33,299 --> 07:42:34,299
God average marks as then you just Brandt
okay ABG m of x, x, and that will display
4926
07:42:34,299 --> 07:42:35,299
everything Oh, if there is an error, non type
object is not equipped. I prefer nine type
4927
07:42:35,299 --> 07:42:36,299
object why non time object? We have done some
mistake. Yes. Maybe. Let's see. Let's see,
4928
07:42:36,299 --> 07:42:37,299
for example, when we run this, so let's run
this and create a cell Let's run using alt
4929
07:42:37,299 --> 07:42:38,299
Enter to create a cell everage m What is that
thing? Oh, that's nothing. Why oh, we haven't
4930
07:42:38,299 --> 07:42:39,299
returned anything. That's a bad programming.
Really bad programming. We have not returned
4931
07:42:39,299 --> 07:42:40,299
actually. The the value that we need. So the
default value is none. raid actually not so
4932
07:42:40,299 --> 07:42:41,299
great. Okay, great. You have this and now
we have something in Emirates marks. Yes,
4933
07:42:41,299 --> 07:42:42,299
this is and now we can just populate that
and we have this student 12 got average marks
4934
07:42:42,299 --> 07:42:43,299
38 student 45 core average marks 90 49.2 and
student 20 He got average marks as 45.0 Okay,
4935
07:42:43,299 --> 07:42:44,299
great. So that was just a review of split
function of string, type and marine through
4936
07:42:44,299 --> 07:42:45,299
int, and functions in general input function,
and, and dictionary and list and all that
4937
07:42:45,299 --> 07:42:46,299
stuff. So although it was a just a tiny problem,
but it gives a good flavor of the data structures
4938
07:42:46,299 --> 07:42:47,299
and strings and all that stuff. Okay, that's
about the data structures. From the next video,
4939
07:42:47,299 --> 07:42:48,299
we are actually diving into the data science
packages. And we will start from NumPy and
4940
07:42:48,299 --> 07:42:49,299
we will spend some time on NumPy and then
we will be moving towards pandas, which is
4941
07:42:49,299 --> 07:42:50,299
very, very powerful built on top of NumPy
and after that, we'll be moving towards matplotlib
4942
07:42:50,299 --> 07:42:51,299
and we will also try to give you some snapshots
of psychic learn as well. So hope to see you
4943
07:42:51,299 --> 07:42:52,299
in the next video. Okay, the next few videos
will I will discuss NumPy which is the which
4944
07:42:52,299 --> 07:42:53,299
is the very very popular package for numerical
Python. Actually NumPy is like list but it
4945
07:42:53,299 --> 07:42:54,299
is much much faster than list.
4946
07:42:54,299 --> 07:42:55,299
One one restriction if we restrict the list
of Remember, a list actually is a collection
4947
07:42:55,299 --> 07:42:56,299
of a lot of data objects. That was so abstract,
as we saw in previous videos, if for example,
4948
07:42:56,299 --> 07:42:57,299
we restrict a list that all the objects they
must have same type all elements in the list
4949
07:42:57,299 --> 07:42:58,299
for example, they have same type then that
list with all the same type, there is what
4950
07:42:58,299 --> 07:42:59,299
the NumPy looks like, but NumPy is very, very
more faster. And the reason is, even if you
4951
07:42:59,299 --> 07:43:00,299
define a list with all the elements that are
let's say of same type Yeah, but because list
4952
07:43:00,299 --> 07:43:01,299
in abstract way can handle heterogeneous kind
of objects, the functions that we will apply
4953
07:43:01,299 --> 07:43:02,299
on these items, they will no longer be faster
further to store each element we have to store
4954
07:43:02,299 --> 07:43:03,299
that information or metadata for that element
in NumPy, it is both I mean, it is efficient
4955
07:43:03,299 --> 07:43:04,299
with respect to memory, because if the type
is saying we need not to save information
4956
07:43:04,299 --> 07:43:05,299
about each element, because we need just to
save the information about the type because
4957
07:43:05,299 --> 07:43:06,299
the type is same for all elements further
when the type is same, we can write functions
4958
07:43:06,299 --> 07:43:07,299
that are much more faster than then then a
list. So NumPy is very, very popular, it has
4959
07:43:07,299 --> 07:43:08,299
very very fast universal functions available
the methods that are available in NumPy. And
4960
07:43:08,299 --> 07:43:09,299
it's a package i mean it's it's a whole directory
structure containing a lot of packages inside
4961
07:43:09,299 --> 07:43:10,299
a lot of modules and so much at the end of
the day, it's it's it's simply or in laymen
4962
07:43:10,299 --> 07:43:11,299
terms, it is like a list with all the same
type objects and it is much more useful when
4963
07:43:11,299 --> 07:43:12,299
all these objects are numeric type, although
you can have a NumPy array with with spring
4964
07:43:12,299 --> 07:43:13,299
data types, I mean all the strings are all
general objects as well, but the the most
4965
07:43:13,299 --> 07:43:14,299
the power mill the power of NumPy array will
be will become much more evident when we will
4966
07:43:14,299 --> 07:43:15,299
be working on numeric type data. So in this
particular in this particular course we will
4967
07:43:15,299 --> 07:43:16,299
focus more on numeric data then other kind
of data. So that's how you you write import
4968
07:43:16,299 --> 07:43:17,299
NumPy is installed or if you if you have installed
Python using Anaconda NumPy is already installed
4969
07:43:17,299 --> 07:43:18,299
there it is in the side packages kind of a
built in package. So import NumPy we can stay
4970
07:43:18,299 --> 07:43:19,299
as it is but we can rename this NumPy just
NP that's most popular name, we can write
4971
07:43:19,299 --> 07:43:20,299
any other name but if you see the books or
internet or somewhere this NP somehow becomes
4972
07:43:20,299 --> 07:43:21,299
much more popular. Okay. Now we can define
an array for example NP dot array that array
4973
07:43:21,299 --> 07:43:22,299
is just a method of NP kind of function. And
we can define an array using list this is
4974
07:43:22,299 --> 07:43:23,299
the list of several numbers or we can define
array as as a topple as well. So whether we
4975
07:43:23,299 --> 07:43:24,299
give a topple whether we give a list an array
is defined and then we can see the contents
4976
07:43:24,299 --> 07:43:25,299
of this array, this NP array so let let's
just go to our friend Jupyter Notebook and
4977
07:43:25,299 --> 07:43:26,299
get our hand Well dripped on, on this NumPy.
So first of all, we need to import NumPy package.
4978
07:43:26,299 --> 07:43:27,299
And we may rename as for future use as NP.
So let's say that is imported. So now let's
4979
07:43:27,299 --> 07:43:28,299
say a is an array, let's say NP dot array,
that's a function and we may have a list and
4980
07:43:28,299 --> 07:43:29,299
say, let's say 12357. Let's say that that's
right, we can also define the array using
4981
07:43:29,299 --> 07:43:30,299
a topple rather than a list, it's our choice.
Which way we define the array either way.
4982
07:43:30,299 --> 07:43:31,299
235 Let's, that's, that's another array for
example. So if we print for example, a it
4983
07:43:31,299 --> 07:43:32,299
will give us a but if we just see the type
of a it will no longer be list it will be
4984
07:43:32,299 --> 07:43:33,299
an ND array numpy.md array that n dimensional
array, okay, great. So, there are so many
4985
07:43:33,299 --> 07:43:34,299
attributes of this a and this B. Same. Similarly,
if you see the type of B although we have
4986
07:43:34,299 --> 07:43:35,299
defined this be using the tupple. But the
type is the same the it's a NumPy object rather
4987
07:43:35,299 --> 07:43:36,299
than a list or a topple.
4988
07:43:36,299 --> 07:43:37,299
So that's how you can create the the array
1111 more thing that is that is important
4989
07:43:37,299 --> 07:43:38,299
is to check the attributes of a for example,
k dot d type, that will tell us the data type
4990
07:43:38,299 --> 07:43:39,299
in a so for example, a stores all the data
that is integer 32. At defined time, for example,
4991
07:43:39,299 --> 07:43:40,299
we can we can specify the data type if we
want we can specify the type if we want. For
4992
07:43:40,299 --> 07:43:41,299
example, in teacher that means as in teacher
here, we can here we can define, for example,
4993
07:43:41,299 --> 07:43:42,299
the type as float, for example, so data type
becomes float. There are several other other
4994
07:43:42,299 --> 07:43:43,299
options that are available to define the data
type but, but even if we don't define the
4995
07:43:43,299 --> 07:43:44,299
data type can be defined automatically based
on contents. That's what the dynamic typing
4996
07:43:44,299 --> 07:43:45,299
means. So if we now define type that is, if
we, if we now check the type of a that is,
4997
07:43:45,299 --> 07:43:46,299
again in digit 32, but if you check the type
of be the type that that might be a float
4998
07:43:46,299 --> 07:43:47,299
number, yes, that's float 32. Again, there
are 64 bit support as well, I mean, we can
4999
07:43:47,299 --> 07:43:48,299
define here there are several options here
available. So that's the that's how we can
5000
07:43:48,299 --> 07:43:49,299
define the NumPy array that's just getting
started with NumPy array. In the next video,
5001
07:43:49,299 --> 07:43:50,299
we will play with these arrays a bit more.
So hope to see you in the next video. Okay,
5002
07:43:50,299 --> 07:43:51,299
in the last video, I introduced NumPy. And
we actually declared a NumPy array using a
5003
07:43:51,299 --> 07:43:52,299
list as well as a topple. In this particular
video, we will be seeing some of the properties
5004
07:43:52,299 --> 07:43:53,299
of the NumPy array variable or sometimes called
the object that variable there are several
5005
07:43:53,299 --> 07:43:54,299
properties, but I will discuss for example,
last time I discussed one property which is
5006
07:43:54,299 --> 07:43:55,299
d type a dot d type, and that store actually
the that actually stores the information of
5007
07:43:55,299 --> 07:43:56,299
the data type of the elements of the array
of NP array, remember NP array, all elements
5008
07:43:56,299 --> 07:43:57,299
of NP array they must have same data type
it cannot store heterogeneous arrays as it
5009
07:43:57,299 --> 07:43:58,299
is. Okay. Now, there is another property sometimes
called the dimensions are n them. That tells
5010
07:43:58,299 --> 07:43:59,299
actually, what are the dimensions of of the
array, I need to explain this term dimensions
5011
07:43:59,299 --> 07:44:00,299
with the following example. Let's say for
example, that's, that's that's an array just
5012
07:44:00,299 --> 07:44:01,299
consider that a list for example, 123, that's
one list. And if it is if it is an array,
5013
07:44:01,299 --> 07:44:02,299
for example, if np.if this is NP dot array.
With that list, we will say that array as
5014
07:44:02,299 --> 07:44:03,299
a one dimensional array, because we only need
one index to access that. For example, if
5015
07:44:03,299 --> 07:44:04,299
you need to access any element in this array,
you only need one index either 01 or two,
5016
07:44:04,299 --> 07:44:05,299
only one index, that's okay. So in this case,
we have just one dimensional array. On the
5017
07:44:05,299 --> 07:44:06,299
other hand, for example, if you see here,
that's one array or one list, that's another
5018
07:44:06,299 --> 07:44:07,299
array, another list. And that's another list
that contains lists inside for example. Let's
5019
07:44:07,299 --> 07:44:08,299
say that array one, and that's array two.
And that is simply an array of two different
5020
07:44:08,299 --> 07:44:09,299
arrays. That's, that's an array and that's
an array. For example, a One is this array
5021
07:44:09,299 --> 07:44:10,299
and a two is this array. Now if we need to
access any element in this particular array,
5022
07:44:10,299 --> 07:44:11,299
we need two indices. First of all, we have
to locate whether we are going to talk about
5023
07:44:11,299 --> 07:44:12,299
a one or a two, we need one index for that,
for example, if we want to locate a one, that
5024
07:44:12,299 --> 07:44:13,299
means we are going to access with elements
zero, let's say this, this whole array is
5025
07:44:13,299 --> 07:44:14,299
a So first of all, we say okay, zero means
we are going to access from from a one and
5026
07:44:14,299 --> 07:44:15,299
a to one of those. So zero means the first
one, okay, now a one. Now inside a one which
5027
07:44:15,299 --> 07:44:16,299
element, this is the zeroeth element, this
is the first element, this is a second element,
5028
07:44:16,299 --> 07:44:17,299
let's say we want to access the first element.
So that means we are going to talk about we
5029
07:44:17,299 --> 07:44:18,299
are talking about this. So very loosely speaking,
the total number of indices that are required
5030
07:44:18,299 --> 07:44:19,299
to access an element inside the array is called
dimension of the array. And m them that actually,
5031
07:44:19,299 --> 07:44:20,299
that actually defines that that actually describes
the this property, the total number of dimensions.
5032
07:44:20,299 --> 07:44:21,299
Consider, for example, this is a 2d array
or two dimensional array, let's head out to
5033
07:44:21,299 --> 07:44:22,299
two dimensional array A one, and let that's
another two dimensional array a two, that's
5034
07:44:22,299 --> 07:44:23,299
another two dimensional array, a three, for
example, and let's say this is an array of
5035
07:44:23,299 --> 07:44:24,299
two dimensional arrays, let's say NP dot array.
Now, that's that whole array, whatever that
5036
07:44:24,299 --> 07:44:25,299
array is a three dimensional array. And the
reason is to access any element, we need three
5037
07:44:25,299 --> 07:44:26,299
indices. First index will define which one
of these we are selecting, for example, let's
5038
07:44:26,299 --> 07:44:27,299
say you're selecting that. So one index is
needed that index is one for example, then
5039
07:44:27,299 --> 07:44:28,299
inside this structure like so, we need two
more indices to locate a particular particular
5040
07:44:28,299 --> 07:44:29,299
index. For example, because it is a two dimensional
array, it has two one dimensional array, so
5041
07:44:29,299 --> 07:44:30,299
which one dimensional array you are, it has
more, it has many one dimensional arrays,
5042
07:44:30,299 --> 07:44:31,299
so which one dimensional array you want to
pick, let's say the sixth one will index with
5043
07:44:31,299 --> 07:44:32,299
index five, now you have located the fifth
or sixth array. Now in that array, what element
5044
07:44:32,299 --> 07:44:33,299
let's say the eighth element. So we need three
indices to access a particular element. So
5045
07:44:33,299 --> 07:44:34,299
the dimensions of this array is three. So
let's play with that in Jupyter, notebook
5046
07:44:34,299 --> 07:44:35,299
just to get more comfortable with with the
term dimensions. So let's say for example,
5047
07:44:35,299 --> 07:44:36,299
we have an array, let's say a is NP dot array.
And let's say it contains a list, let's say
5048
07:44:36,299 --> 07:44:37,299
123. And then we have another array, one dimensional
array, let's say four, five, and six, that's
5049
07:44:37,299 --> 07:44:38,299
another array. And that is an array of these
two arrays. So that is basically a two dimensional
5050
07:44:38,299 --> 07:44:39,299
array. It is array of arrays. list of lists,
equal entries. So that's a for example, oh,
5051
07:44:39,299 --> 07:44:40,299
what's the problem? Oh, we haven't imported
NumPy, we should have. So import, import NumPy
5052
07:44:40,299 --> 07:44:41,299
as NP? Okay, we need not to import that every
time. Actually, I'm recording this video after
5053
07:44:41,299 --> 07:44:42,299
a few after a few hours. And I'm really I
have restarted all these things. So I have
5054
07:44:42,299 --> 07:44:43,299
to import now for the first time. But once
imported in the notebook, as long as a notebook
5055
07:44:43,299 --> 07:44:44,299
is running, you need not re import anything.
Okay, so a DOD for example, and then Iraq
5056
07:44:44,299 --> 07:44:45,299
and them. So that is to hear because there
are two dimensions. For example, if I want
5057
07:44:45,299 --> 07:44:46,299
to access element number three, this element,
so this element is located in the first array
5058
07:44:46,299 --> 07:44:47,299
of the two arrays, which has so the first
array, there are two arrays with index zero
5059
07:44:47,299 --> 07:44:48,299
or one. So I am going to look into the first
array, which is 123. And in that array, I'm
5060
07:44:48,299 --> 07:44:49,299
going to look for the element number two element
with index two. So that's how you can access
5061
07:44:49,299 --> 07:44:50,299
the elements of multi dimensional arrays are
arrays with more, more kind of dimensions.
5062
07:44:50,299 --> 07:44:51,299
Let's say we have another array just to just
to get more familiar with NP array, let's
5063
07:44:51,299 --> 07:44:52,299
say, and we have a list. And that list actually
contains that list actually contains three
5064
07:44:52,299 --> 07:44:53,299
one dimensional arrays. Not only that, actually
Oh, I'm confusing you a lot. Let me know Let
5065
07:44:53,299 --> 07:44:54,299
me just, let's say we have 123. Let's say
we have three one dimensional arrays. Let's
5066
07:44:54,299 --> 07:44:55,299
say we have another 2459. The the sizes of
arrays, maybe, maybe, maybe, I mean, maybe
5067
07:44:55,299 --> 07:44:56,299
different. Yeah. Is that true? maybe different?
Yes or no? Let's see, for example, the first
5068
07:44:56,299 --> 07:44:57,299
array has size three, and the second array
has total size. Does that okay? I guess, yes.
5069
07:44:57,299 --> 07:44:58,299
And now if we want to access, for example,
an element of an element with a, let's say,
5070
07:44:58,299 --> 07:44:59,299
I want to access this element five, so that
is in the secondary index with one, and then
5071
07:44:59,299 --> 07:45:00,299
in that array, it has index two. So I've accessed
this element, oh, we're not too many indices
5072
07:45:00,299 --> 07:45:01,299
for an array. Why?
5073
07:45:01,299 --> 07:45:02,299
Why is that? Why too many indices, for for
an array, B selects a B dot n dems. And then
5074
07:45:02,299 --> 07:45:03,299
that is one y one dimensional, I have to,
I have this one dimensional array. And this
5075
07:45:03,299 --> 07:45:04,299
is another one dimensional array. And I have
made a list out of it. I'm in this is 1d array
5076
07:45:04,299 --> 07:45:05,299
and another 1d array of concatenate them together,
so I shouldn't have accessed this element.
5077
07:45:05,299 --> 07:45:06,299
The problem is when you are going to define
multi dimensional arrays, the the number of
5078
07:45:06,299 --> 07:45:07,299
elements for each dimension, they should stay
consistent. For example, if the first array
5079
07:45:07,299 --> 07:45:08,299
has three elements, the second array must
have three elements, or if the secondary has
5080
07:45:08,299 --> 07:45:09,299
four elements, and the first must have four
elements. If that is not the case, the array
5081
07:45:09,299 --> 07:45:10,299
will not be defined like a multi dimensional
array. For example, if we, for example, extend
5082
07:45:10,299 --> 07:45:11,299
our first array with let's say, minus one.
Now, B will be having two dimensions, no problem.
5083
07:45:11,299 --> 07:45:12,299
And now we will be able to access for example,
this element five, like so. So we will go
5084
07:45:12,299 --> 07:45:13,299
to B again, we will see okay, select array
number two, and in that array, select index,
5085
07:45:13,299 --> 07:45:14,299
select the value indexed by two, which is
five. So accessed no problem. And that stays
5086
07:45:14,299 --> 07:45:15,299
true if you if you're going to define for
example, a three dimensional array, let me
5087
07:45:15,299 --> 07:45:16,299
just give you an example of three dimensional
array that's a C equals NP dot array. And
5088
07:45:16,299 --> 07:45:17,299
let's say we have one, two and three. And
then we have another array, for example. 456,
5089
07:45:17,299 --> 07:45:18,299
remember or so let's say that, that we can
have one more for example, we can have one
5090
07:45:18,299 --> 07:45:19,299
more list, why not? So let's say we have a
00 minus one, let's say, and that is what
5091
07:45:19,299 --> 07:45:20,299
that is. That is a two dimensional array.
That's a two dimensional array. Great. Let's
5092
07:45:20,299 --> 07:45:21,299
say we have another two dimensional array.
Let's say we have another two dimensional
5093
07:45:21,299 --> 07:45:22,299
array with same kind of consistency, the number
of elements and stuff. Let's say these elements
5094
07:45:22,299 --> 07:45:23,299
are our minus of the, the other ones, let's
say there's minus, minus, minus and this is
5095
07:45:23,299 --> 07:45:24,299
plus one. And now we have this, if you see
this thing, that's a 2d array. That's a two
5096
07:45:24,299 --> 07:45:25,299
dimensional array, that is also a two dimensional
array. An array of two dimensional arrays
5097
07:45:25,299 --> 07:45:26,299
is basically a three dimensional array. Now,
that's a three dimensional array. This one,
5098
07:45:26,299 --> 07:45:27,299
C, so if you Oh, we have some, Oh, I should
have defined this with commas. Rather than
5099
07:45:27,299 --> 07:45:28,299
rather than spaces. Actually. Yeah. The reason
I did that is MATLAB. I worked in MATLAB also.
5100
07:45:28,299 --> 07:45:29,299
So MATLAB allows this space separated list,
but I just confuse the things with with Python
5101
07:45:29,299 --> 07:45:30,299
as well. But Python requires comma, they're
okay. With MATLAB. By the way, just as a side
5102
07:45:30,299 --> 07:45:31,299
note, MATLAB allows you to have commas as
well as spaces, but this Python is just restricts
5103
07:45:31,299 --> 07:45:32,299
everything to comma. That's great. Okay, that
is C. So now, if you check c dot n them that
5104
07:45:32,299 --> 07:45:33,299
is three, if you for example, want to access
this particular element, what should you do?
5105
07:45:33,299 --> 07:45:34,299
First of all, you select the, the one of the
2d arrays, there are two 2d arrays. So this
5106
07:45:34,299 --> 07:45:35,299
is the first 2d array and that's the second
2d array. And if you For example, want to
5107
07:45:35,299 --> 07:45:36,299
access this particular element, this particular
element, which is minus three, if you want
5108
07:45:36,299 --> 07:45:37,299
to access that, you first have to access one
of the two 2d, two dimensional arrays.
5109
07:45:37,299 --> 07:45:38,299
So let's access the second one with the index
one. Now you are in this particular 2d array
5110
07:45:38,299 --> 07:45:39,299
in that array with list which 1d array you're
talking about. So I'm talking about the very
5111
07:45:39,299 --> 07:45:40,299
first 1d array, so the very first 1d array
is indexed by zero, and in that one D array,
5112
07:45:40,299 --> 07:45:41,299
which element you are talking about. So I'm
talking about this element that has index
5113
07:45:41,299 --> 07:45:42,299
two in this particular array. So now, if you
press enter, you will get minus three Wow.
5114
07:45:42,299 --> 07:45:43,299
So that is basically how and by the way, you
can make a four dimensional array, a four
5115
07:45:43,299 --> 07:45:44,299
dimensional array will be an array of three
dimensional arrays, and so on, you can make,
5116
07:45:44,299 --> 07:45:45,299
you can make, for example, n dimensional arrays,
and that's one reason why we call this as
5117
07:45:45,299 --> 07:45:46,299
nd array, n dimensional array, not the type
of C's nd array n dimensional array, you can
5118
07:45:46,299 --> 07:45:47,299
add as many dimensions as you want. Great,
we will continue exploring this NumPy more
5119
07:45:47,299 --> 07:45:48,299
and more in in the upcoming videos in particular,
I will talk about this shape property of this
5120
07:45:48,299 --> 07:45:49,299
NumPy we have already discussed D type we
have discussed and then in the next video,
5121
07:45:49,299 --> 07:45:50,299
we will talk about shape and we will discuss
more about about NumPy. So hope to see you
5122
07:45:50,299 --> 07:45:51,299
in the next video. Okay, in the last video,
we discussed this number of dimensions or
5123
07:45:51,299 --> 07:45:52,299
ending property of any any NumPy array. And
we also saw an example of defining a three
5124
07:45:52,299 --> 07:45:53,299
dimensional array in Jupyter. notebook. Let
let's discuss another property which is which
5125
07:45:53,299 --> 07:45:54,299
is the shape property. Let's see what what
this shape actually represents. So let's go
5126
07:45:54,299 --> 07:45:55,299
to Jupyter Notebook and see what actually
this shape represents. For example, you have
5127
07:45:55,299 --> 07:45:56,299
seen this C as in the last video, we define
the C as a three dimensional array that contains
5128
07:45:56,299 --> 07:45:57,299
two arrays of 2d. And each 2d array contains
three 1d arrays, and each 1d array contains
5129
07:45:57,299 --> 07:45:58,299
three elements. So what do we mean by shape?
So if we just say shape? What is that thing?
5130
07:45:58,299 --> 07:45:59,299
So shape is 233. And let me tell you what
that means. The return is tuple. So that's
5131
07:45:59,299 --> 07:46:00,299
a tuple. That is returned to three and three.
This two means how many two dimensional arrays
5132
07:46:00,299 --> 07:46:01,299
are there? Here we have two. So in each two
dimensional array, how many 1d arrays are
5133
07:46:01,299 --> 07:46:02,299
there? Well, three in each one, the array?
How many elements are there? Well, three.
5134
07:46:02,299 --> 07:46:03,299
So basically, this C dot shape, zero, tells
you the total number of two dimensional arrays,
5135
07:46:03,299 --> 07:46:04,299
that is too. And this shape. For example.
One tells you in each 2d array, how many 1d
5136
07:46:04,299 --> 07:46:05,299
arrays are there, these many? And this shape,
for example, to tells you in each one the
5137
07:46:05,299 --> 07:46:06,299
array, how many elements are there? Well,
three grade? That's awesome. Yeah. Can I tell
5138
07:46:06,299 --> 07:46:07,299
you 111 screens kind of thing? You can you
can define a NumPy array, for example, a as
5139
07:46:07,299 --> 07:46:08,299
NP dot array with just one element, let's
say two. That's an array raid. What's the
5140
07:46:08,299 --> 07:46:09,299
number of dimensions here? What do you think?
What is that? Is that a 1d array? What are
5141
07:46:09,299 --> 07:46:10,299
the number of dimensions? Strange? It's a
1d array. Yeah, it is. see another thing?
5142
07:46:10,299 --> 07:46:11,299
For example, b is equal to NP dot array. And
you define it with let's say three. And what
5143
07:46:11,299 --> 07:46:12,299
are the dimensions of B, it looks like the
same, the dimension of B should be one as
5144
07:46:12,299 --> 07:46:13,299
as their the dimension of A is one, it looks
like the dimension of B is also one. No, it's
5145
07:46:13,299 --> 07:46:14,299
zero. Because that's an array. If you pass
it as as a list. It's an array of one D if
5146
07:46:14,299 --> 07:46:15,299
you just define just one number that can be
defined as an array NumPy allows you that
5147
07:46:15,299 --> 07:46:16,299
but that one number is just as a yo D array.
Now if you can get in it, a lot of zero days,
5148
07:46:16,299 --> 07:46:17,299
you get one day if you concatenate the last
one days, you get a duty. If you're getting
5149
07:46:17,299 --> 07:46:18,299
a lot of duties, you get a 3d and so on. Get
a look and feel Yeah. So that's what it is.
5150
07:46:18,299 --> 07:46:19,299
So yes, In this video, I discuss the shape
there is another There is there are so many
5151
07:46:19,299 --> 07:46:20,299
properties, let me let me discuss some properties,
let's size that actually tells the total number
5152
07:46:20,299 --> 07:46:21,299
of elements complete total number of elements
in the array. So, how many elements are there
5153
07:46:21,299 --> 07:46:22,299
that is size. There is also I guess m bikes
property, that tells the how many total number
5154
07:46:22,299 --> 07:46:23,299
of bytes that the destructor is taking inside
the memory. And there are several other I
5155
07:46:23,299 --> 07:46:24,299
mean properties, if you just apply a tab and
get certain things, you will see a lot of
5156
07:46:24,299 --> 07:46:25,299
functions. And you can you can check a lot
of properties that some of these functions
5157
07:46:25,299 --> 07:46:26,299
we will explore later on. Sometimes they are
called the universal functions, we will see
5158
07:46:26,299 --> 07:46:27,299
them because they are very, very fast. And
these functions the vectorized implementation
5159
07:46:27,299 --> 07:46:28,299
of these functions. That is the reason why
NumPy is so so fast, and why it is so popular.
5160
07:46:28,299 --> 07:46:29,299
Anyways, so in the next video, we will go
to explore the NumPy a bit more. And we'll
5161
07:46:29,299 --> 07:46:30,299
show you more fun stuff with the NumPy. So
hope to see you in the next video. NumPy actually
5162
07:46:30,299 --> 07:46:31,299
provides a lot of functions to create arrays,
special kinds of arrays just for testing.
5163
07:46:31,299 --> 07:46:32,299
And sometimes just for. I mean, there are
a lot of ways to create arrays from scratch,
5164
07:46:32,299 --> 07:46:33,299
for example, what if you want to create an
array containing all zeros, so there is a
5165
07:46:33,299 --> 07:46:34,299
function in NumPy NP dot zeros that tells
you how to do that. Similarly, if you want
5166
07:46:34,299 --> 07:46:35,299
to generate a lot of generate an array containing
a lot of ones or all ones, there is a function
5167
07:46:35,299 --> 07:46:36,299
to do that and stuff like so, there are some
functions that are actually used a lot and
5168
07:46:36,299 --> 07:46:37,299
I want to discuss those. One function is NP
dot arrange, actually, this is a single R,
5169
07:46:37,299 --> 07:46:38,299
this is not a two Rs, this is single r NP
dot arrangement, one R and NP dot arranged
5170
07:46:38,299 --> 07:46:39,299
function, what it does is it creates an array
for example, if you say NP dot arrange, it
5171
07:46:39,299 --> 07:46:40,299
creates an array for example, if you say okay,
100. So it creates an array that it creates
5172
07:46:40,299 --> 07:46:41,299
a 1d array that starts from the the values
in that array starts from 012, all up to 99.
5173
07:46:41,299 --> 07:46:42,299
So that's an array. That's a quick way to
create an array with all the numbers till
5174
07:46:42,299 --> 07:46:43,299
100. Yeah, so let's see, let's see running
example of this NP arrange method in Jupyter
5175
07:46:43,299 --> 07:46:44,299
Notebook just to get a better look and feel
of how it works. So let's see. So let's say
5176
07:46:44,299 --> 07:46:45,299
we have a equals NP dot arrange. And let's
see 100. So that's it. If you want to see
5177
07:46:45,299 --> 07:46:46,299
what is inside a, you can see this is an array
with all the values starting from zero up
5178
07:46:46,299 --> 07:46:47,299
to 99. Maybe you want to create an array that
starts from a particular number ends at a
5179
07:46:47,299 --> 07:46:48,299
particular number. Maybe those two numbers
are different. And maybe this arrange function
5180
07:46:48,299 --> 07:46:49,299
actually allows that. Let's say I want to
start with 20. And I want to end at 100. And
5181
07:46:49,299 --> 07:46:50,299
I want to create all the array that does that.
So let's say this. So that's okay, start from
5182
07:46:50,299 --> 07:46:51,299
20 and 100. But the last element last index
is not included. That's possible. Last but
5183
07:46:51,299 --> 07:46:52,299
not the least, if you want for example, to
start from 20 and add 100. And let's say you
5184
07:46:52,299 --> 07:46:53,299
want to take a jump of three. That's possible.
Remember, does this does this resemble with
5185
07:46:53,299 --> 07:46:54,299
something that you know already? Remember
that? Yeah, let me pause for a minute, but
5186
07:46:54,299 --> 07:46:55,299
not for a minute, just for some seconds. Let
me pause. Do you remember this arrange NP
5187
07:46:55,299 --> 07:46:56,299
dot brains function? It looks like something
like what? Remember that for i in range? Yes.
5188
07:46:56,299 --> 07:46:57,299
for i in range, for example, start from 20.
Go 200. Take example three. Remember that?
5189
07:46:57,299 --> 07:46:58,299
So it has some resemblance with range function?
Yeah. Although range is an arbitrator.
5190
07:46:58,299 --> 07:46:59,299
What's an arbitrator? why I'm telling you
that? Okay, let me tell you an arbitrator
5191
07:46:59,299 --> 07:47:00,299
as well here, just just just just spend a
few seconds on on this range function. You,
5192
07:47:00,299 --> 07:47:01,299
you might be thinking when we call this range,
let's say starting from, let's say range them,
5193
07:47:01,299 --> 07:47:02,299
you might be thinking that it returns a list
of numbers, starting from zero to nine, but
5194
07:47:02,299 --> 07:47:03,299
that doesn't happen. It returns nothing. Actually,
when you actually call it when you actually
5195
07:47:03,299 --> 07:47:04,299
call it it returns just an object. When you
call it in a for loop or somewhere. It progressively
5196
07:47:04,299 --> 07:47:05,299
do. rounds one by one element one by one.
So it returns an element, then it hydrates
5197
07:47:05,299 --> 07:47:06,299
and return another element that it never creates
a list of elements, it now creates a list
5198
07:47:06,299 --> 07:47:07,299
for you. That's awesome. Actually, it generates
numbers, it generates the next number and
5199
07:47:07,299 --> 07:47:08,299
the next number as you move on. So it saves
a lot of memory and these kind of objects,
5200
07:47:08,299 --> 07:47:09,299
they are called I craters that I played, they
they never played. But if you want, for example,
5201
07:47:09,299 --> 07:47:10,299
to get a list, if you really want to get a
list, then what you can do is you can call
5202
07:47:10,299 --> 07:47:11,299
the range, let's say in the same way, and
you can just write a list. So provide me a
5203
07:47:11,299 --> 07:47:12,299
list don't just provide me an ID. And that
will give you a list. How cool is that? Right?
5204
07:47:12,299 --> 07:47:13,299
Anyways, that was just a side note. It has
nothing to do with this arrange function anyways.
5205
07:47:13,299 --> 07:47:14,299
So NP dot arrange, it actually returns an
array does not it is not like an iterator,
5206
07:47:14,299 --> 07:47:15,299
it returns an array, complete array the way
you want. So that's what this arrange is it
5207
07:47:15,299 --> 07:47:16,299
has resemblance with this built in range function
that mostly used in in for loops. Okay. Next,
5208
07:47:16,299 --> 07:47:17,299
let's discuss this NP dot random dot permutation
NP dot random is a package. And P is a package,
5209
07:47:17,299 --> 07:47:18,299
it has a lot of sub packages inside random
as a package. Random has a lot of modules
5210
07:47:18,299 --> 07:47:19,299
one module is permutation. There are a lot
of other modules. So let's see this random.
5211
07:47:19,299 --> 07:47:20,299
Let's see what it does. So for example, let's
say a equals NP dot random dot, permutation,
5212
07:47:20,299 --> 07:47:21,299
let's say permutation. And what I do is I
say okay, np dot arrange, let's see 10 what
5213
07:47:21,299 --> 07:47:22,299
it does is, this NP dot arrange will return
an array containing all the values zero to
5214
07:47:22,299 --> 07:47:23,299
nine, these are 10 values, and then this permutation
function that resides in the package and P
5215
07:47:23,299 --> 07:47:24,299
dot random that is in the random packet of
MP, it actually shuffles all the values and
5216
07:47:24,299 --> 07:47:25,299
rearrange all the values in random fashion.
And he will now be an array containing the
5217
07:47:25,299 --> 07:47:26,299
same elements, but in a different order in
a different random order. So let me know print
5218
07:47:26,299 --> 07:47:27,299
this a, it will be having all the elements
from zero to nine bought in a really shuffled
5219
07:47:27,299 --> 07:47:28,299
away. And that shuffling is completely random.
Yeah, you see that? Sometimes you may you
5220
07:47:28,299 --> 07:47:29,299
may call some function, you may want to write
some function on arrays. And you may want
5221
07:47:29,299 --> 07:47:30,299
arrays that are that that do not have a particular
ordering, there are just random arrays, just
5222
07:47:30,299 --> 07:47:31,299
to test your code just to test how it works
on any kind of array. In that case, one way
5223
07:47:31,299 --> 07:47:32,299
of getting shuffled kind of array. One quick
way is to just use NP dot random dot permutation
5224
07:47:32,299 --> 07:47:33,299
function. The NP dot random package does not
only have this permutation, there are a lot
5225
07:47:33,299 --> 07:47:34,299
of other functions and be random, for example,
np dot random random dot Rand int, for example,
5226
07:47:34,299 --> 07:47:35,299
Rand int, that creates a random integer. That's,
for example, if I that's that, let me call
5227
07:47:35,299 --> 07:47:36,299
this and we have, how can it be used? Okay,
you can give a low value from the very start,
5228
07:47:36,299 --> 07:47:37,299
we can give a high value, I mean, and it creates
actually, random integers starting from low
5229
07:47:37,299 --> 07:47:38,299
ending at high. So that's how it can be used.
For example, let me call it as NP dot random
5230
07:47:38,299 --> 07:47:39,299
dot Rand int, create a random number between
20 and 30, create some random integer, and
5231
07:47:39,299 --> 07:47:40,299
it will return some random integer between
20 and 30. If we call it again, it may return
5232
07:47:40,299 --> 07:47:41,299
some other is it is returning 30 again, 29.
Again, and again. Now two turns 2932. Maybe
5233
07:47:41,299 --> 07:47:42,299
we want to maybe want to generate random integer
between 20 and 30. So it creates a random
5234
07:47:42,299 --> 07:47:43,299
integer. One thing that you might be noticing
what is the what is the return value? the
5235
07:47:43,299 --> 07:47:44,299
return value? Is we for example, what should
be the type of E or do you think? Is this
5236
07:47:44,299 --> 07:47:45,299
V is an array? No, it is a number. It's an
integer, the type of VA should be an integer
5237
07:47:45,299 --> 07:47:46,299
because it is returning a random integer it
is returning an integer but it is selecting
5238
07:47:46,299 --> 07:47:47,299
that integer randomly from 20 to 300. So it
should be integer and it is Yes. Wow.
5239
07:47:47,299 --> 07:47:48,299
Yeah,
5240
07:47:48,299 --> 07:47:49,299
so we will be exploring some more functions
in the random package of NP and then we will
5241
07:47:49,299 --> 07:47:50,299
be moving towards this fascinating function
score function called V shape. So there is
5242
07:47:50,299 --> 07:47:51,299
more to come for NumPy so hope to see you
in the next video. Okay in the last video
5243
07:47:51,299 --> 07:47:52,299
we saw a range function that's a very useful
function to just create a test testing array
5244
07:47:52,299 --> 07:47:53,299
and just see see the output of a particular
operation or algorithm, just on different
5245
07:47:53,299 --> 07:47:54,299
kinds of arrays. Further we saw permutation
functions permutation function in NP dot random
5246
07:47:54,299 --> 07:47:55,299
package. And we saw that this this permutation
function, actually, it reshuffles, it shuffles
5247
07:47:55,299 --> 07:47:56,299
different kinds of odd if if array is applied
to this permutation function, it actually
5248
07:47:56,299 --> 07:47:57,299
shuffles all the, all the elements of that
array in a random way in a completely random
5249
07:47:57,299 --> 07:47:58,299
way. Today, we will explore this random package
a bit more, and then we will see a reshape
5250
07:47:58,299 --> 07:47:59,299
function, but that reshape does basically
this reshape, for example, if you have an
5251
07:47:59,299 --> 07:48:00,299
array, let's say, array, is let's say we have
an array with, let's say, 10 elements, and
5252
07:48:00,299 --> 07:48:01,299
if we call a dot reshape, and we give, let's
say, two by five, so it will make a two dimensional
5253
07:48:01,299 --> 07:48:02,299
array out of a, which is B, and that will
be a two by five matrix R, that will be an
5254
07:48:02,299 --> 07:48:03,299
array, or a matrix with two rows and five
columns. And now we can, we can just work
5255
07:48:03,299 --> 07:48:04,299
with this B, just like it's a two dimensional
array, and we can just, we can just treat
5256
07:48:04,299 --> 07:48:05,299
this B as a two dimensional array and work
with that. It is it becomes handy sometimes
5257
07:48:05,299 --> 07:48:06,299
if for example, we want to, we want to test
certain operations on on matrices. A quick
5258
07:48:06,299 --> 07:48:07,299
way to make a matrix is just to call arrange
function, and then whatever the result is
5259
07:48:07,299 --> 07:48:08,299
just reshape it into the desired order matrix
and test the algorithm. So let's go to the
5260
07:48:08,299 --> 07:48:09,299
let's go to Jupyter Notebook and check this
random package a bit more and then see the
5261
07:48:09,299 --> 07:48:10,299
reshape function. So let's go to Jupyter.
notebook. Yes, so there are a lot of ways
5262
07:48:10,299 --> 07:48:11,299
to generate these random numbers. One for
example, we already have seen Rand int. And
5263
07:48:11,299 --> 07:48:12,299
other way for example, array, an array can
be generated, like MP dot random dot RAND
5264
07:48:12,299 --> 07:48:13,299
function. So now, if we create this, if we
create, let's if we pass let's say 1000, random
5265
07:48:13,299 --> 07:48:14,299
value array will be generated in a and a each
value of a will be a random number between
5266
07:48:14,299 --> 07:48:15,299
between zero and one. So all these numbers
are just random between zero and one each
5267
07:48:15,299 --> 07:48:16,299
number is zero and one random number. And,
and this distribution basically is the distribution
5268
07:48:16,299 --> 07:48:17,299
of this random number is all the distribution
is uniform. If for example, you want to plot
5269
07:48:17,299 --> 07:48:18,299
the histogram, the histogram or the distribution
of a it will look like uniform. Let me just
5270
07:48:18,299 --> 07:48:19,299
give you give you one or two plots, using
matplotlib package, although we will see matplotlib
5271
07:48:19,299 --> 07:48:20,299
package later on. But let's assume that this
is just a plotting package. This is just a
5272
07:48:20,299 --> 07:48:21,299
package that helps us plotting just import
that import mat plot lib.pi plot as PLT import
5273
07:48:21,299 --> 07:48:22,299
that. And after importing that, you just plot
a histogram PLT dot hist, for example, and
5274
07:48:22,299 --> 07:48:23,299
pass a and you can see the histogram is roughly
uniform. I mean, everything is equally likely
5275
07:48:23,299 --> 07:48:24,299
we can make more bands, for example, we can
have bands, equals let's say 100. And we can
5276
07:48:24,299 --> 07:48:25,299
see almost all events they are I mean just
look like uniform. If we make more and more
5277
07:48:25,299 --> 07:48:26,299
data set, then they will all look uniform.
One more thing we can we can have, for example
5278
07:48:26,299 --> 07:48:27,299
this. And let's say B equals NP dot random
dot Rand n, and that generates normal random
5279
07:48:27,299 --> 07:48:28,299
numbers, or Gaussian random numbers, let's
say which which the distribution of the numbers
5280
07:48:28,299 --> 07:48:29,299
are is the bell shaped curve, for example,
so let's just PLT dot haste B. And then let's
5281
07:48:29,299 --> 07:48:30,299
say equal to 200. And we can see a bell shaped
curve because the distribution of this data
5282
07:48:30,299 --> 07:48:31,299
is is Gaussian distribution looks like so.
So this this random packages, this NP dot
5283
07:48:31,299 --> 07:48:32,299
random is really important package. It has
different, it can create different kinds of
5284
07:48:32,299 --> 07:48:33,299
random numbers from following from different
distributions and doing in machine learning
5285
07:48:33,299 --> 07:48:34,299
or in statistics, sometimes we need to generate
these kinds of random numbers for sometimes
5286
07:48:34,299 --> 07:48:35,299
for testing purposes, sometimes for adding
noise of a particular type to test our model
5287
07:48:35,299 --> 07:48:36,299
and stuff like so. So it's good to have a
good grip on NP dot random package. Okay.
5288
07:48:36,299 --> 07:48:37,299
Next we see reshape function. One more thing.
For example, if you want to create, for example,
5289
07:48:37,299 --> 07:48:38,299
a two dimensional array of just random numbers,
let's say you can call NP NP dot random dot
5290
07:48:38,299 --> 07:48:39,299
Rand. And you can just call a, you can just
pass two arguments, for example, two by three,
5291
07:48:39,299 --> 07:48:40,299
and the C will be a two by three matrix. If
you see the C, it will be a two by three matrix
5292
07:48:40,299 --> 07:48:41,299
of four random values. If you see c dot, and
then it will be having the dimensions are
5293
07:48:41,299 --> 07:48:42,299
two. And it's a two dimensional array. Further,
we can create, for example, a four dimensional
5294
07:48:42,299 --> 07:48:43,299
array c equals NP dot random dot Rand, maybe
two by three by four by two. And that's a
5295
07:48:43,299 --> 07:48:44,299
four dimensional array with this particular
order. So if you see this C dot m, then that
5296
07:48:44,299 --> 07:48:45,299
will be level b, this. Yeah, so let me let
me just give you an interpretation of what
5297
07:48:45,299 --> 07:48:46,299
that thing is. There are two arrays that are
three dimensional. And there are two of those.
5298
07:48:46,299 --> 07:48:47,299
Okay? Now, each three dimensional array has
three two dimensional arrays. Wow.
5299
07:48:47,299 --> 07:48:48,299
So each
5300
07:48:48,299 --> 07:48:49,299
two dimensional array has four one dimensional
arrays, and each one dimensional array has
5301
07:48:49,299 --> 07:48:50,299
two elements in it. So that's what the structure
is. Yeah, get a good look and feel. So let's
5302
07:48:50,299 --> 07:48:51,299
see the reshape function. For example, let's
say we have d equals NP dot range. Let's say
5303
07:48:51,299 --> 07:48:52,299
we have 100 values. And then we say reshape
these 100 values to let's say, let's say four
5304
07:48:52,299 --> 07:48:53,299
by 25. So this D will be a four by 25 matrix.
So if we just get the shape of D, so that
5305
07:48:53,299 --> 07:48:54,299
will be a four by 25 matrix or a two dimensional
array with four rows and 25 columns. Yeah,
5306
07:48:54,299 --> 07:48:55,299
so sometimes we want to work on matrices,
and we just, we can just plug in these arrays
5307
07:48:55,299 --> 07:48:56,299
function to generate a bunch of numbers. And
then we can reshape those and build a matrix
5308
07:48:56,299 --> 07:48:57,299
quickly, and then just test the performance
of our algorithm or stuff like so. So, not
5309
07:48:57,299 --> 07:48:58,299
only the reship not only returns the, the
I mean, you can you can reshape a matrix,
5310
07:48:58,299 --> 07:48:59,299
and you can reshape an array into more than
two dimensional array if you want to, for
5311
07:48:59,299 --> 07:49:00,299
example, arrange 100, let's say dot reshape,
maybe or as four by five by five, it's a three
5312
07:49:00,299 --> 07:49:01,299
dimensional array. Now, this D will be a three
dimensional array containing different values.
5313
07:49:01,299 --> 07:49:02,299
Yeah, so now you can access it and do whatever
you want to do. So not only the reshape, arrange
5314
07:49:02,299 --> 07:49:03,299
and permit random, there are other functions
as well NP dot zeros. For example, if you
5315
07:49:03,299 --> 07:49:04,299
press z, and you just see the zeros, and then
you just press the question mark, you will
5316
07:49:04,299 --> 07:49:05,299
know what that function is how can we use
it and so on. Similarly, you can have several
5317
07:49:05,299 --> 07:49:06,299
other function there is an important function
once for example, you can call that function,
5318
07:49:06,299 --> 07:49:07,299
and that will generate an array of all ones,
you can see how to call that function here.
5319
07:49:07,299 --> 07:49:08,299
There is NP dot empty, there is NP dot empty,
like there are so many functions just to create
5320
07:49:08,299 --> 07:49:09,299
some matrices very quickly. And you want to
test your core algorithms based on those.
5321
07:49:09,299 --> 07:49:10,299
So yeah, so there are a lot of functions that
we want to that we can work on. So next, so
5322
07:49:10,299 --> 07:49:11,299
there are a lot of functions that can quickly
create a NP array and an n dimensional array.
5323
07:49:11,299 --> 07:49:12,299
That we can quickly create an array test or
algorithm or use the array wherever we want
5324
07:49:12,299 --> 07:49:13,299
to like we're everyone to use. And we can
move on just a few functions like arranged
5325
07:49:13,299 --> 07:49:14,299
ones zeros, they are there are random dot
Rand random dot Rand n, and other functions
5326
07:49:14,299 --> 07:49:15,299
they are available. For In the next video
we will be seeing we will be seeing the indexing
5327
07:49:15,299 --> 07:49:16,299
or slicing inside NumPy array and we will
also be seeing the difference of that indexing
5328
07:49:16,299 --> 07:49:17,299
with or slicing from the array In the list
or or are the ordinary data structures? What
5329
07:49:17,299 --> 07:49:18,299
is the difference in? What is the difference
of slicing in NumPy? with for example, with
5330
07:49:18,299 --> 07:49:19,299
the list, we will see that in the in the next
video, hope to see you in the next video.
5331
07:49:19,299 --> 07:49:20,299
Okay?
5332
07:49:20,299 --> 07:49:21,299
Here is my favorite topic in NumPy slicing.
Actually, indexing or slicing in NumPy is
5333
07:49:21,299 --> 07:49:22,299
the way you access sub arrays is just the
same as the way you access sub strings or
5334
07:49:22,299 --> 07:49:23,299
sub lists. And you already have seen, how
can we how can we use the slicing or indexing
5335
07:49:23,299 --> 07:49:24,299
in lists and in strings, the difference here
in NumPy is in list for example, if you slice
5336
07:49:24,299 --> 07:49:25,299
you get, for example, let's say B equals a
one colon five, if you slice that thing, from
5337
07:49:25,299 --> 07:49:26,299
NumPy, then B is not a copy, it is actually
accessing the same memory view as an A. Now,
5338
07:49:26,299 --> 07:49:27,299
if you change any element in B, the corresponding
element in a will change as long as as a NumPy
5339
07:49:27,299 --> 07:49:28,299
array. However, if A is a list or any other
data structure, ordinary data structure, then
5340
07:49:28,299 --> 07:49:29,299
the slicing this, this kind of slice gives
a copy rather than a view. So that's an important
5341
07:49:29,299 --> 07:49:30,299
difference, we need to know that rest of the
indexing technique is almost the same. You
5342
07:49:30,299 --> 07:49:31,299
do this kind of indexing that is how you can
reverse this a start and step all all the
5343
07:49:31,299 --> 07:49:32,299
things are same, except How can play How can
we play with the two dimensional arrays. Let's
5344
07:49:32,299 --> 07:49:33,299
let let's see that. Let's see some examples
of indexing one by one in in Jupyter Notebook
5345
07:49:33,299 --> 07:49:34,299
and see how the slicing actually creates a
view rather than a copy. So let's go to our
5346
07:49:34,299 --> 07:49:35,299
Jupyter Notebook and see how can we play with
different indices, let's say a is NP dot arrange,
5347
07:49:35,299 --> 07:49:36,299
and B dot arranged, let's say 100. And let's
shuffle them. Let's say as it is, let's say
5348
07:49:36,299 --> 07:49:37,299
that's a now a, let's say, let's bring some
certain things. Let's A B equals a big all
5349
07:49:37,299 --> 07:49:38,299
the elements starting from index three, ending
at index nine, Sudan is not included. That's
5350
07:49:38,299 --> 07:49:39,299
B, that's blank v. Let's see what's B. So
b is this array. Okay? Now what I'm going
5351
07:49:39,299 --> 07:49:40,299
to do is I'm just changing the contents of
b, this NumPy array is mutable, you can change
5352
07:49:40,299 --> 07:49:41,299
the elements inside, no problem. So I'm going
to change the elements, let's say one element
5353
07:49:41,299 --> 07:49:42,299
in B, let's say, I'm going to change element
numbers zero, and B, which is three, and I'm
5354
07:49:42,299 --> 07:49:43,299
just placing that element as minus 100 minus
1200. That's it. That's the case. Okay, now
5355
07:49:43,299 --> 07:49:44,299
the contents of B has been changed. We are
but now let's see the contents of a the contents
5356
07:49:44,299 --> 07:49:45,299
of a also has changed. That's a big difference
between slicing an ordinary Lester adini data
5357
07:49:45,299 --> 07:49:46,299
structure or slicing a list, when you slice
a list, you get us you get another label,
5358
07:49:46,299 --> 07:49:47,299
but that label or that variable is accessing
the same memory, the memory actually is not
5359
07:49:47,299 --> 07:49:48,299
copied. There is one memory view. And these
two different names, whether you access those
5360
07:49:48,299 --> 07:49:49,299
elements using B, or you access those elements
using a the same memory is being accessed
5361
07:49:49,299 --> 07:49:50,299
if you change the memory using B or A you
will see the effect in both of the variables.
5362
07:49:50,299 --> 07:49:51,299
So that's one difference. Now, after having
knowledge of this difference, if we really
5363
07:49:51,299 --> 07:49:52,299
want this behavior to not happen, one thing
that we can call is we can say okay, a, for
5364
07:49:52,299 --> 07:49:53,299
example, a, let's say three to 10. And then
we can call our famous function, remember
5365
07:49:53,299 --> 07:49:54,299
that copy, you can copy that and now B is
completely a different array. It's it's a
5366
07:49:54,299 --> 07:49:55,299
different memory view, if you change B now,
the effect will not be seen in a so copy function
5367
07:49:55,299 --> 07:49:56,299
is there whenever you need copy. One thing
if you are not going to change elements the
5368
07:49:56,299 --> 07:49:57,299
number is applies you very fast implementation
of slicing by not changing the memory view
5369
07:49:57,299 --> 07:49:58,299
if if you are aware, your algorithm is not
going to change the elements slicing will
5370
07:49:58,299 --> 07:49:59,299
give you much much efficient access to the
elements or the or the sub blocks or sub arrays
5371
07:49:59,299 --> 07:50:00,299
without actually making the copies inside
the memory which can take time and space both.
5372
07:50:00,299 --> 07:50:01,299
So this is one plus of NumPy Over the over
the other data structure that we have seen
5373
07:50:01,299 --> 07:50:02,299
so far in Python, okay, let's play with indices,
5374
07:50:02,299 --> 07:50:03,299
let's say what do you think? What is that
thing? colon, colon to what? Or colon colon,
5375
07:50:03,299 --> 07:50:04,299
let's say five, what it will do, it will start
from the very first index, which is zero,
5376
07:50:04,299 --> 07:50:05,299
it will go to the last index, but it will
pick every fifth element. So let's see. So,
5377
07:50:05,299 --> 07:50:06,299
it picks zero then five then 10, then 15,
because the jump is five break, what do you
5378
07:50:06,299 --> 07:50:07,299
think what this will do? Let me just let me
just teach you by example, what this will
5379
07:50:07,299 --> 07:50:08,299
do. Yeah, what it will do remember, if you
apply a minus here, the end and the start
5380
07:50:08,299 --> 07:50:09,299
and end they just get swept, and this becomes
a step from from the end. So, what will happen
5381
07:50:09,299 --> 07:50:10,299
is the same kind of impact, you start from
the very end, then you take the step of minus
5382
07:50:10,299 --> 07:50:11,299
one from the end, and you just based every
element, so this is kind reversing the array
5383
07:50:11,299 --> 07:50:12,299
with with kind of step starting at the end
rate. So, another way of reversing the array
5384
07:50:12,299 --> 07:50:13,299
is if you want to reverse the array as a whole
display minus one, which means start from
5385
07:50:13,299 --> 07:50:14,299
the end and pick every element from the end
till the beginning and the end, and the array
5386
07:50:14,299 --> 07:50:15,299
will be reversed. This element is there, remember
that this is there, let's chain that element.
5387
07:50:15,299 --> 07:50:16,299
Let's chain that element. So, so a adds position.
So, I want to find out the index, where this
5388
07:50:16,299 --> 07:50:17,299
minus 1200 is located. So Id x is equal to
a dot index I guess there is a function index
5389
07:50:17,299 --> 07:50:18,299
Yes, he has a no index Oh, there is no index
there. Is there an MP dot index and P dot
5390
07:50:18,299 --> 07:50:19,299
index? I want to find out the index where
so in DAX there is no index function indices
5391
07:50:19,299 --> 07:50:20,299
or something, I want an index function is
there any index function I want to find out
5392
07:50:20,299 --> 07:50:21,299
the index? Where minus 200 is located? There
are several ways but I want to find one. So
5393
07:50:21,299 --> 07:50:22,299
for example, for example, let me see whether
there is an index function and not available
5394
07:50:22,299 --> 07:50:23,299
in NumPy or not. No, it is no longer there.
But there is in the CS function, I guess.
5395
07:50:23,299 --> 07:50:24,299
So in the CS, what that does, I guess that
does the same job. Let me see MPR indices
5396
07:50:24,299 --> 07:50:25,299
returns an array representing the indices
of a grid, okay. So I have to give a grid
5397
07:50:25,299 --> 07:50:26,299
and then it returns for example, the indices
of all that grid, how can I use that? Well,
5398
07:50:26,299 --> 07:50:27,299
it becomes it becomes difficult, there may
be a find function, or how can you locate
5399
07:50:27,299 --> 07:50:28,299
the index where the minus 200? Is, is located?
How can I How can I do that?
5400
07:50:28,299 --> 07:50:29,299
Huh?
5401
07:50:29,299 --> 07:50:30,299
Yeah, very difficult. Seems like very difficult.
Oh, why don't I rather than finding out a
5402
07:50:30,299 --> 07:50:31,299
function? Why don't I just play with play
with the NumPy? Why not? So let's say a equal
5403
07:50:31,299 --> 07:50:32,299
equals minus 1200. That gives me a Boolean
array comparing each and every element with
5404
07:50:32,299 --> 07:50:33,299
minus 1200. So, the array the returning array,
let me call the index array or the Boolean
5405
07:50:33,299 --> 07:50:34,299
array, let's be that array is true or false
array or zero or one array, wherever there
5406
07:50:34,299 --> 07:50:35,299
is minus 1200, that index is one that value
is one otherwise it is zero, completely zero.
5407
07:50:35,299 --> 07:50:36,299
And then what I do is, I just multiply that
with with NP dot arrange NP dot arrange with
5408
07:50:36,299 --> 07:50:37,299
with saying that a dot A dot A dot size, so
whatever the size of A is, so because these
5409
07:50:37,299 --> 07:50:38,299
are the indices Okay, then what that's point
wise multiplication grade. So, when I will
5410
07:50:38,299 --> 07:50:39,299
multiply them together, what I will get is
is what I will get from multiplication, I
5411
07:50:39,299 --> 07:50:40,299
will get, how can I How can I find out actually,
a train lost here literally, how can I find
5412
07:50:40,299 --> 07:50:41,299
out how can I find out the index where Where
am I? So that will give me what? Let's see,
5413
07:50:41,299 --> 07:50:42,299
what is B. Now, the B is B is just an array.
B is just an array, and there is this three.
5414
07:50:42,299 --> 07:50:43,299
That is looking at it. So how can I find out?
Where is this three? How can I, again, the
5415
07:50:43,299 --> 07:50:44,299
problem is finding out the index. Okay, that's,
that's really a bad thing. Can I call this
5416
07:50:44,299 --> 07:50:45,299
aid dot indices? And just give a minus 1200.
And everything just worked out? No, there
5417
07:50:45,299 --> 07:50:46,299
is an error, there is an error. Oh, I'm lost
here. Literally, I'm lost here, I need to
5418
07:50:46,299 --> 07:50:47,299
know how to find out the index where this
particular element minus 1200 lies. So
5419
07:50:47,299 --> 07:50:48,299
that's a
5420
07:50:48,299 --> 07:50:49,299
question for you as well. I'm also lost. So
let's see you in the next video. And we first
5421
07:50:49,299 --> 07:50:50,299
will solve this problem to finding out the
index of a particular element, or maybe a
5422
07:50:50,299 --> 07:50:51,299
lot of elements. And then we will continue
from there onwards to see more indexing. Okay,
5423
07:50:51,299 --> 07:50:52,299
great. So hope to see you in the next video
by first solving the problem, how to find
5424
07:50:52,299 --> 07:50:53,299
out the index of a particular element in a
NumPy array, or maybe more than one elements
5425
07:50:53,299 --> 07:50:54,299
in a NumPy array. And then we will be practicing
more about these slicing examples. Okay, hope
5426
07:50:54,299 --> 07:50:55,299
to see you in the next video. Okay, let's
say this element is there. And let's say we
5427
07:50:55,299 --> 07:50:56,299
want to, we want to locate that element in
the array, we want to just know where this
5428
07:50:56,299 --> 07:50:57,299
element is in the array. So array has this
element. Let's let me paint array as it is,
5429
07:50:57,299 --> 07:50:58,299
this array has this particular element, and
we want to know where what is the index of
5430
07:50:58,299 --> 07:50:59,299
this element inside the array, there are several
ways of doing this. One way is to find out
5431
07:50:59,299 --> 07:51:00,299
their index is simply you call the function
arc where arc where for example, org, where
5432
07:51:00,299 --> 07:51:01,299
A is equal to minus 1200. And that will return
a 2d array. And if you just want any one index,
5433
07:51:01,299 --> 07:51:02,299
then you return that kind of thing. So if
you write this thing, you will get the index
5434
07:51:02,299 --> 07:51:03,299
exactly of the element that is there. So the
index is three, if you want to change that
5435
07:51:03,299 --> 07:51:04,299
value, for example, the value should be three
here, if you want to change that value, what
5436
07:51:04,299 --> 07:51:05,299
you can do is you can right, okay, ie x is
equal to three, and is reverse to its position
5437
07:51:05,299 --> 07:51:06,299
wherever it was created, okay, great. Now,
let's play with the two dimensional indices.
5438
07:51:06,299 --> 07:51:07,299
Let's do dimensional arrays, let's say we
have a equals NP dot random dot, Rand, let's
5439
07:51:07,299 --> 07:51:08,299
say, let's say we have a five by four matrix,
let's say a two dimensional array, let's round
5440
07:51:08,299 --> 07:51:09,299
all the values by multiplying them to 10.
What it does is because all the values this
5441
07:51:09,299 --> 07:51:10,299
RAND function, all the values it generates
are the values between zero and one, what
5442
07:51:10,299 --> 07:51:11,299
this multiplied by 10, what it does is, it
actually scales up all the values to 10. And
5443
07:51:11,299 --> 07:51:12,299
then round function, actually, round downs
are actually rounds the values to the integers.
5444
07:51:12,299 --> 07:51:13,299
Now a will be worse the problem round that
third round method is no longer there. Okay,
5445
07:51:13,299 --> 07:51:14,299
maybe there is NP naught round, maybe that
NP dot round, maybe NP dot round is their
5446
07:51:14,299 --> 07:51:15,299
Yes, and B dot round. So round function of
NP. So this a is a is this array, for example,
5447
07:51:15,299 --> 07:51:16,299
that's five by four, a four, five rows and
four columns. So let's say I want to access
5448
07:51:16,299 --> 07:51:17,299
the second row. First of all, let's say I
want to access this particular entry. This
5449
07:51:17,299 --> 07:51:18,299
particular entry is second row and third column,
which means the index is one comma two, because
5450
07:51:18,299 --> 07:51:19,299
second row means the row row first has index
zero. row two has index one. Similarly, column
5451
07:51:19,299 --> 07:51:20,299
one has index zero, column two has index two,
a one and column three has index two. So that
5452
07:51:20,299 --> 07:51:21,299
is what this particular entry is. What if
we want to access the whole second row, for
5453
07:51:21,299 --> 07:51:22,299
example, we want the second row. So that's
how you call that's how you slice. A normal
5454
07:51:22,299 --> 07:51:23,299
meaning of this is you the role should be
one and the columns, all the columns, so That's
5455
07:51:23,299 --> 07:51:24,299
how you access the whole second row. If you
want to, for example, access the whole third
5456
07:51:24,299 --> 07:51:25,299
row, for example, or a whole second column,
let's say that means you say this, okay, the
5457
07:51:25,299 --> 07:51:26,299
column number second, and all the rows, which
means the whole second column that is accessed.
5458
07:51:26,299 --> 07:51:27,299
That if you see, that's the whole second column
six, four to 10. And one, that's what the
5459
07:51:27,299 --> 07:51:28,299
second column is. Further, once you have a,
you can, you can, for example, access a sub
5460
07:51:28,299 --> 07:51:29,299
matrix, let's say you want, you want row number
one to rule number three, not including three.
5461
07:51:29,299 --> 07:51:30,299
And then of these rows, you want column number
two to column number
5462
07:51:30,299 --> 07:51:31,299
four, let's say. And if you do that, you access
the whole sub matrix. First, it actually picks
5463
07:51:31,299 --> 07:51:32,299
row number two and row number three, because
row number two starts from one. And then of
5464
07:51:32,299 --> 07:51:33,299
those rows, it picks these columns, and you
can just pick the pick the sub matrix inside
5465
07:51:33,299 --> 07:51:34,299
more, you can, you can do a lot of processing
on these matrices. For example, this is matrix
5466
07:51:34,299 --> 07:51:35,299
A, if you just type a dot transpose, that
these four transpose, the matrix just is taken
5467
07:51:35,299 --> 07:51:36,299
transpose of it. Further, there is a complete
library, linear algebra library in NumPy.
5468
07:51:36,299 --> 07:51:37,299
For example, if you just import NumPy NumPy
dot linear algebra, as a for example, then
5469
07:51:37,299 --> 07:51:38,299
this linear algebra library in NumPy, has
a lot of functions, Eigen values, chelski
5470
07:51:38,299 --> 07:51:39,299
decomposition, computing determinant of a
matrix, finding out inverse of a matrix and
5471
07:51:39,299 --> 07:51:40,299
what not. For example, let's say we have la
dot inverse, and here is NP dot random dot
5472
07:51:40,299 --> 07:51:41,299
Rand, let's say, some three by three matrix.
So what it returns is, it returns the inverse
5473
07:51:41,299 --> 07:51:42,299
of this matrix, and this linear algebra library,
and there are other libraries as well. But
5474
07:51:42,299 --> 07:51:43,299
this is one scientific library, that may be
most of data science experts who actually
5475
07:51:43,299 --> 07:51:44,299
want to do research, they might be thinking,
this linear algebra library, that that specifies
5476
07:51:44,299 --> 07:51:45,299
a lot of functions related to related to these
matrices or two dimensional arrays. So that
5477
07:51:45,299 --> 07:51:46,299
is there. Okay, so that's about indexing.
We can play with these indices a lot if we
5478
07:51:46,299 --> 07:51:47,299
want. One more thing, just just one. One last
thing, let's say this is our a. And what we
5479
07:51:47,299 --> 07:51:48,299
want to do is let's say we want to sort this
A with respect to the columns, we want each
5480
07:51:48,299 --> 07:51:49,299
column to be sorted individually, what we
can do is we can call sort function, and we
5481
07:51:49,299 --> 07:51:50,299
can pause X's equals zero, access equals zero,
that means sort all the columns individually
5482
07:51:50,299 --> 07:51:51,299
and the result will be if you see the result,
the result will be every column is sorted
5483
07:51:51,299 --> 07:51:52,299
individually. If we want to sort for example,
every row individually, we will say okay,
5484
07:51:52,299 --> 07:51:53,299
sort x is equals one, and every row will be
sorted individually. And if this is a multi
5485
07:51:53,299 --> 07:51:54,299
dimensional array more than three more than
two dimensions, then x is can be two x's can
5486
07:51:54,299 --> 07:51:55,299
be free. So which with respect to whatever
axes you want, your sorting can happen. It
5487
07:51:55,299 --> 07:51:56,299
can do that, if A is one dimensionally, then
dot sort function without an access, just
5488
07:51:56,299 --> 07:51:57,299
sorts just sorts the one dimensional array
from beginning to the end. And if you want
5489
07:51:57,299 --> 07:51:58,299
to descending order a sword just sought them
sorted first and then reverse it using indexing.
5490
07:51:58,299 --> 07:51:59,299
Great, I mean, there is a lot to discuss,
there is a lot to discuss, I'm ending this
5491
07:51:59,299 --> 07:52:00,299
slicing here. In the next video, I'm going
to show you kind of masking or sometimes called
5492
07:52:00,299 --> 07:52:01,299
the fancy indexing that is much more powerful
and useful in a lot of different contexts.
5493
07:52:01,299 --> 07:52:02,299
So hope to see you in the next video with
more NumPy indexing. Okay, there is another
5494
07:52:02,299 --> 07:52:03,299
way of indexing a NumPy array. In the last
video we saw we can, we can do slicing notation,
5495
07:52:03,299 --> 07:52:04,299
for example, start from here and here and
stuff like so. There is another way of accessing
5496
07:52:04,299 --> 07:52:05,299
a NumPy array as we have an array and we can
just give the give an index array inside for
5497
07:52:05,299 --> 07:52:06,299
example. Let's say a is one dimensional array
and then we just give 146 that means big element
5498
07:52:06,299 --> 07:52:07,299
at index one, pick the element at index four,
pick the element at index six. So this kind
5499
07:52:07,299 --> 07:52:08,299
of array inside can be a list or an array.
That is called an index array. And you can
5500
07:52:08,299 --> 07:52:09,299
just pick the elements that you want to pick,
for example, you want to pick all all elements,
5501
07:52:09,299 --> 07:52:10,299
you want to pick first element, fifth element
and 17th element, you can just create an index
5502
07:52:10,299 --> 07:52:11,299
array and pass it. And in an index your and
access your elements using that index array
5503
07:52:11,299 --> 07:52:12,299
that's possible in NumPy array. Further, you
can access different elements using a Boolean
5504
07:52:12,299 --> 07:52:13,299
mask as well. So Boolean array, for example,
true, true, false false, wherever there is
5505
07:52:13,299 --> 07:52:14,299
a true pick that element wherever there is
a false, don't pick that element and return
5506
07:52:14,299 --> 07:52:15,299
the elements that are picked. For example,
assuming here that you have an array, which
5507
07:52:15,299 --> 07:52:16,299
is one dimensional array, let's say, assume
that has eight elements, 12345678 elements.
5508
07:52:16,299 --> 07:52:17,299
Now you pass a Boolean mask inside, where
with with obviously, eight elements, a true
5509
07:52:17,299 --> 07:52:18,299
or false values, wherever there is true. So
pick the very first value, pick the second
5510
07:52:18,299 --> 07:52:19,299
value, pick the don't pick the third value,
don't pick the fourth value, pick the fifth
5511
07:52:19,299 --> 07:52:20,299
value, pick the sixth value, pick the seventh
value, and don't pick the last value. So that
5512
07:52:20,299 --> 07:52:21,299
is also possible in in NumPy. One thing that
is important is if you do this kind of indexing,
5513
07:52:21,299 --> 07:52:22,299
which is sometimes called masking, if you
do that, if you do if you supply an array
5514
07:52:22,299 --> 07:52:23,299
index, or index in a Boolean form, you by
default get a copy as as as compared to slicing
5515
07:52:23,299 --> 07:52:24,299
in slicing, you get a view that's a separate
copy, you need not to call a dot copy function,
5516
07:52:24,299 --> 07:52:25,299
it is by default, a different copy. And this
is a difference between the ordinary slicing
5517
07:52:25,299 --> 07:52:26,299
that you do, for example, start from one go
till 50, take a jump of let's say two, if
5518
07:52:26,299 --> 07:52:27,299
that is your indexing style, that is called
a slicing, the return value is a different
5519
07:52:27,299 --> 07:52:28,299
view having the same memory. However, if you
do the, if you use the array index, or the
5520
07:52:28,299 --> 07:52:29,299
Boolean array called masks, then you get a
copy of rather than also so which means if
5521
07:52:29,299 --> 07:52:30,299
you if you get a new array, you change the
elements in the new array using the array
5522
07:52:30,299 --> 07:52:31,299
indices. You're not getting that change happen
to the original array. So that's the difference
5523
07:52:31,299 --> 07:52:32,299
between slicing and masking. Okay, this kind
of Boolean indexing becomes really handy.
5524
07:52:32,299 --> 07:52:33,299
For example, what if you want to exit? What
if you want to get all elements that are smaller
5525
07:52:33,299 --> 07:52:34,299
than eight, one way to do that is just write
a and then apply a condition is less than
5526
07:52:34,299 --> 07:52:35,299
eight, well, a is less than eight, we'll create
a Boolean array. And everywhere where the
5527
07:52:35,299 --> 07:52:36,299
element is smaller than eight, there will
be a true otherwise it will be false. Now,
5528
07:52:36,299 --> 07:52:37,299
the inside array is a Boolean array, and you
access all the elements with respect to that
5529
07:52:37,299 --> 07:52:38,299
condition. So it will return all elements
that are smaller than eight. How how fancy
5530
07:52:38,299 --> 07:52:39,299
is that? Further, you can you can have these
conditions in a combined way. There is one
5531
07:52:39,299 --> 07:52:40,299
difference there is an AND operator A and
D and, and there isn't an operating in a different
5532
07:52:40,299 --> 07:52:41,299
way. So I'm going to discuss the difference
of this and this and as well in this in this
5533
07:52:41,299 --> 07:52:42,299
whole in this video. So let's go to Jupyter
Notebook our fan and see how can we play with
5534
07:52:42,299 --> 07:52:43,299
this masks.
5535
07:52:43,299 --> 07:52:44,299
So let's say a is again and B dot arrange,
arrange, let's say 100. That's it. That's
5536
07:52:44,299 --> 07:52:45,299
our a. And what we now do is we access the
elements of A, B access, for example, the
5537
07:52:45,299 --> 07:52:46,299
third element and the fifth element and the
sixth element. Let's say we want to do that.
5538
07:52:46,299 --> 07:52:47,299
And that's our B. So that happens, let's say,
so what B is B is this, something that you
5539
07:52:47,299 --> 07:52:48,299
need to know is if you change the elements
of B now, because that's a copy, let's say
5540
07:52:48,299 --> 07:52:49,299
minus four, that change does not happen in
eight that happens in B for sure. But that
5541
07:52:49,299 --> 07:52:50,299
doesn't happen in a, a does not contain any
value that is minus four. Because using these
5542
07:52:50,299 --> 07:52:51,299
kinds of indices, the array index By default,
the result is a copy rather than a view. Further,
5543
07:52:51,299 --> 07:52:52,299
let's say you have this a and you want to
access all the elements that are smaller than
5544
07:52:52,299 --> 07:52:53,299
let's say that are smaller than let's say
40, access all elements that are smaller than
5545
07:52:53,299 --> 07:52:54,299
40. So that is possible now even contain only
the elements that are smaller than 40. All
5546
07:52:54,299 --> 07:52:55,299
the elements while further if you want to
access all elements that are that are smaller
5547
07:52:55,299 --> 07:52:56,299
than 40 that are smaller than 40. And they
are bigger than they are smaller than 40.
5548
07:52:56,299 --> 07:52:57,299
And they are bigger than 30. Let's say you
want to access all the elements that are between
5549
07:52:57,299 --> 07:52:58,299
30 and 40. You can just access those elements
like so there is a problem. A dot any a dot
5550
07:52:58,299 --> 07:52:59,299
all what's the problem here? The truth value
of an array with more than one element is
5551
07:52:59,299 --> 07:53:00,299
ambiguous use a.ne or a dot all. Okay, this
a is less than 40 is a Boolean array is greater
5552
07:53:00,299 --> 07:53:01,299
than 40. That's a Boolean array. So what's
the problem? What, why can't we not use this?
5553
07:53:01,299 --> 07:53:02,299
What's the problem? We should have used that.
So use and, and, yeah, I guess we were missing
5554
07:53:02,299 --> 07:53:03,299
these, we were missing these brackets because
it might be confusing this 40 with this a
5555
07:53:03,299 --> 07:53:04,299
and stuff like so. So use parenthesis rate.
Now, B contains only the elements that are
5556
07:53:04,299 --> 07:53:05,299
between 30 and 40. Now, one thing, what's
the difference between this particular and
5557
07:53:05,299 --> 07:53:06,299
and this symbol and the difference is this
and AMD an operator It is used when both of
5558
07:53:06,299 --> 07:53:07,299
the sides of this end has what is one object
and it has one true value either true or false.
5559
07:53:07,299 --> 07:53:08,299
And this particular symbol is used when the
left side and the right side can be arrays,
5560
07:53:08,299 --> 07:53:09,299
and each element of that array can be true
or false. And so, so, you can think of this
5561
07:53:09,299 --> 07:53:10,299
and is using arrays, however, this is used
when both the sides are single objects. So
5562
07:53:10,299 --> 07:53:11,299
that's the difference. Other variants of and
I mean, the end is like this, that these are
5563
07:53:11,299 --> 07:53:12,299
these are the same things, but remember the
use this is used for arrays, this is used
5564
07:53:12,299 --> 07:53:13,299
for single objects. Similarly, there are other
symbols like
5565
07:53:13,299 --> 07:53:14,299
or
5566
07:53:14,299 --> 07:53:15,299
that is used this way or or that is used that
way. Similarly, there is a not not for arrays
5567
07:53:15,299 --> 07:53:16,299
is used like this way and not for otherwise,
is used like that way. So remember these the
5568
07:53:16,299 --> 07:53:17,299
left side, I have symbols, they are used for
arrays, the right kind of symbols, they are
5569
07:53:17,299 --> 07:53:18,299
used for single objects that has true or false
values. So these, this kind of masking is
5570
07:53:18,299 --> 07:53:19,299
really, really powerful. Later, we will see
in pandas accessing different kinds of data
5571
07:53:19,299 --> 07:53:20,299
with particular kind of conditioning, that
becomes really handy if we if we are comfortable
5572
07:53:20,299 --> 07:53:21,299
with these kinds of indexing. And that's really
powerful indexing. Okay. So, I've told you
5573
07:53:21,299 --> 07:53:22,299
the difference here between Aaron and I've
told you that this is copy rather than a view.
5574
07:53:22,299 --> 07:53:23,299
So just bear with me some more time on NumPy.
And I will tell you some more truths about
5575
07:53:23,299 --> 07:53:24,299
NumPy. And then we will move towards another
package called pandas. So before pandas more
5576
07:53:24,299 --> 07:53:25,299
NumPy is coming, I hope to see you in the
next video. Okay, in the last video, we saw
5577
07:53:25,299 --> 07:53:26,299
masking, which is sometimes called the fancy
indexing as well. And here we are going to
5578
07:53:26,299 --> 07:53:27,299
discuss one more feature of NumPy, which is
very powerful feature called broadcasting.
5579
07:53:27,299 --> 07:53:28,299
I think, for example, you have an array, let's
say two, three, a matrix, that's a two dimensional
5580
07:53:28,299 --> 07:53:29,299
array 235 and nine, and you want to add, in
every element, you want to add a number, let's
5581
07:53:29,299 --> 07:53:30,299
say five. So one way to do that is create
another array with 5555. And just apply this
5582
07:53:30,299 --> 07:53:31,299
add operator and you are done. Great. But
this NumPy allows you to just write let's
5583
07:53:31,299 --> 07:53:32,299
say this is array, a NumPy allows you to just
do this particular thing. And this five is
5584
07:53:32,299 --> 07:53:33,299
automatically broadcasted to match with the
dimensions of its other operand. And addition
5585
07:53:33,299 --> 07:53:34,299
happens you need not to do this explicitly.
And this broadcasting is not just one scalar
5586
07:53:34,299 --> 07:53:35,299
value. For example, if you have one variable,
let's say a is this and you want to add, for
5587
07:53:35,299 --> 07:53:36,299
example, this particular column, let's say
one three, you want to add this particular
5588
07:53:36,299 --> 07:53:37,299
column in the first column as well as in the
second column, but then you need this one
5589
07:53:37,299 --> 07:53:38,299
three to be copied again and make a bigger
array and then you do that well, broadcasting
5590
07:53:38,299 --> 07:53:39,299
allows you if you just write this as a plus
one three, it will be automatically broadcasted
5591
07:53:39,299 --> 07:53:40,299
to match the size of the other operand, wherever
the book broadcasting is possible, there are
5592
07:53:40,299 --> 07:53:41,299
certain rules to to know when broadcasting
is possible it is not possible each and every
5593
07:53:41,299 --> 07:53:42,299
time. For example, if you have this matrix
239 and Jeff 421 Let's at this matrix and
5594
07:53:42,299 --> 07:53:43,299
you want for example, two one and six two,
for example, if you want to do that, the broadcasting
5595
07:53:43,299 --> 07:53:44,299
may not happen because in this way, if I want
to broadcast this structure, the structures
5596
07:53:44,299 --> 07:53:45,299
should be if if the structure is broadcasted
to in horizontal way, the the two columns
5597
07:53:45,299 --> 07:53:46,299
will be arrayed and the addition cannot happen.
If it expands to a vertical way still the
5598
07:53:46,299 --> 07:53:47,299
addition cannot happen. So, this here you
will get an error because broadcasting is
5599
07:53:47,299 --> 07:53:48,299
cannot happen, but in several cases when you
want to add for example, a scalar multiply
5600
07:53:48,299 --> 07:53:49,299
with a particular thing wherever possible
this broadcasting is possible and broadcasting
5601
07:53:49,299 --> 07:53:50,299
is just a I mean it just a feature of NumPy
that allows you to not repeat to match the
5602
07:53:50,299 --> 07:53:51,299
dimension of the other operand to apply a
particular operator it does it by itself great.
5603
07:53:51,299 --> 07:53:52,299
Next, we see some more important functions
to no one is horizontal stack. That means,
5604
07:53:52,299 --> 07:53:53,299
if you want to concatenate two different array
two arrays that are that can be concatenated
5605
07:53:53,299 --> 07:53:54,299
together horizontally, you can get out you
can call at stack function and that will concatenate
5606
07:53:54,299 --> 07:53:55,299
the two arrays together and returns another
array. Similarly, V stack is if you want to
5607
07:53:55,299 --> 07:53:56,299
concatenate two arrays vertically, if they
can be concatenated vertically, vertically,
5608
07:53:56,299 --> 07:53:57,299
similarly, there, there is another powerful
function sort, and there are a lot of other
5609
07:53:57,299 --> 07:53:58,299
functions, these kinds of functions, they
are called Universal functions. And they are
5610
07:53:58,299 --> 07:53:59,299
very, very, very powerful, very, very fast
their implementation is vectorized, where
5611
07:53:59,299 --> 07:54:00,299
Christ mean the implementation the all loop
kind of layer is deferred to at the compile
5612
07:54:00,299 --> 07:54:01,299
time and the things are really faster when
you do a vectorized code. So, having said
5613
07:54:01,299 --> 07:54:02,299
that, it is always recommended to not use
explicitly for loops to achieve these kind
5614
07:54:02,299 --> 07:54:03,299
of,
5615
07:54:03,299 --> 07:54:04,299
to achieve these kind of results, whenever
a universal function is available, use that
5616
07:54:04,299 --> 07:54:05,299
because the efficiency of that universal function
will be way, way way more than then whatever
5617
07:54:05,299 --> 07:54:06,299
loop loop or whatever function you will be
writing other than the universal function.
5618
07:54:06,299 --> 07:54:07,299
So, and by the way, there is another function
concatenate as well, in which you can specify
5619
07:54:07,299 --> 07:54:08,299
axes. And it will either act as horizontal
stack or either act as vertical stack, depending
5620
07:54:08,299 --> 07:54:09,299
upon whether the x value is zero or one, whatever.
So, let's just get comfortable with these,
5621
07:54:09,299 --> 07:54:10,299
these three functions, just quickly neural
Jupyter Notebook and see an example of, let's
5622
07:54:10,299 --> 07:54:11,299
say, broadcasting as well. So let's say we
have a function, and let's say you have an
5623
07:54:11,299 --> 07:54:12,299
array is let's say, np dot random dot Rand,
let's say that is two by three. And then I
5624
07:54:12,299 --> 07:54:13,299
just multiply this with them. Remember the
last thing and then we just NP dot around,
5625
07:54:13,299 --> 07:54:14,299
we just round everything. So that it becomes
it becomes whole, in this particular way.
5626
07:54:14,299 --> 07:54:15,299
Okay, that's a, let's say, so that's our a,
that's the now if we say a plus three, three
5627
07:54:15,299 --> 07:54:16,299
will be added everywhere in a, and that happens
through broadcasting. Well, if we if we do,
5628
07:54:16,299 --> 07:54:17,299
for example, a plus, for example, np dot range,
let's say just do values, and then we just
5629
07:54:17,299 --> 07:54:18,299
reshape it, reshape it, to reshape it to let's
say, a two by one matrix. If you do that,
5630
07:54:18,299 --> 07:54:19,299
then still, what what will happen is just
apply the parenthesis just to show that this
5631
07:54:19,299 --> 07:54:20,299
should happen. First, what what will happen
is there will, there will be a column that
5632
07:54:20,299 --> 07:54:21,299
will be added to every column A, and that
again, will be happened through through the
5633
07:54:21,299 --> 07:54:22,299
broadcasting. So broadcasting is that powerful.
Next, let's see the stats. So that's it, this
5634
07:54:22,299 --> 07:54:23,299
is a, let's say we have the that's another
way, let's say NP dot random dot Rand. Let's
5635
07:54:23,299 --> 07:54:24,299
say that new array is two by two. And again,
let's say it is multiplied by Dan and NP doc
5636
07:54:24,299 --> 07:54:25,299
round just to avoid the decimal points. That's
it, this is B. Now a is two by three array
5637
07:54:25,299 --> 07:54:26,299
D is a two by two array, if I just concatenate
them horizontally, I will get another array
5638
07:54:26,299 --> 07:54:27,299
which will be two by five. So C equals np.at
stack horizontal stack, at stack, and I will
5639
07:54:27,299 --> 07:54:28,299
call these A and B. One thing that you need
to know is if you if you want to call this
5640
07:54:28,299 --> 07:54:29,299
x stack, horizontal stack or vertical stack,
these arguments in B that you want to concatenate
5641
07:54:29,299 --> 07:54:30,299
you have to give them in a topple or you may
you may want to give several values to concatenate
5642
07:54:30,299 --> 07:54:31,299
together maybe you have maybe you have 10
matrices to concatenate together horizontally.
5643
07:54:31,299 --> 07:54:32,299
You have to give all these as a tuple inside
a All right. Now similarly, we can do a vertical
5644
07:54:32,299 --> 07:54:33,299
stack if we want. I mean, one on top of the
other. And we can call it and getting it function
5645
07:54:33,299 --> 07:54:34,299
as well, if you want. Third is sort function.
For example, if we want. If you want to use
5646
07:54:34,299 --> 07:54:35,299
NP dot, let's say a is NP dot random dot permutation,
let's say NP dot range, let's say the 10 values.
5647
07:54:35,299 --> 07:54:36,299
Let's say that our a, let's say, this is a,
and we want to sort this array. Oh, this is
5648
07:54:36,299 --> 07:54:37,299
already sorted. Why is it sorted? No, it is
not sorted 1/4. It is not sorted? Yeah. Let's
5649
07:54:37,299 --> 07:54:38,299
say we want to sort it a dot sort. One way
of doing that is just call a dot sort, and
5650
07:54:38,299 --> 07:54:39,299
you're done. That's the value of a another
way, which is sometimes more readable, although
5651
07:54:39,299 --> 07:54:40,299
exactly the same is to use a universal function,
using NP dot that thing that also is the same
5652
07:54:40,299 --> 07:54:41,299
thing. Now sort by default sorts in ascending
order. If you want to sort in descending order,
5653
07:54:41,299 --> 07:54:42,299
then what you can do is you can sort aid or
sought, for example, do that in ascending
5654
07:54:42,299 --> 07:54:43,299
order, then what you do is you just reverse
it, minus one, and just copy that in a again,
5655
07:54:43,299 --> 07:54:44,299
now he will be sorted. While sorted in descending
order. Yeah, great. Um, one more just just
5656
07:54:44,299 --> 07:54:45,299
just just to give you one more flavor, if
you create an array, for example, np dot array
5657
07:54:45,299 --> 07:54:46,299
of strings, for example, ABC, and another
string is, how are you and vai maybe we have
5658
07:54:46,299 --> 07:54:47,299
another string? Whew, 785. And maybe we have
another string, one, three e r, that's it.
5659
07:54:47,299 --> 07:54:48,299
That's a string. That is possible. As long
as all the objects have same type, you can
5660
07:54:48,299 --> 07:54:49,299
create an empty array. Now, you might be wondering,
what we'll do this sort function on a because
5661
07:54:49,299 --> 07:54:50,299
these are all strings? Well, the answer is
it will sort the strings according to the
5662
07:54:50,299 --> 07:54:51,299
alphabetic order, whatever the alphabetic
order is, whatever string according to the
5663
07:54:51,299 --> 07:54:52,299
alphabetic order should become first that
will become first and the other strings, they
5664
07:54:52,299 --> 07:54:53,299
will they will just join. Yeah. So yeah, so
that's about something that is not that is
5665
07:54:53,299 --> 07:54:54,299
not the numeric value. Okay, great. There
is a few more things to come about NumPy array,
5666
07:54:54,299 --> 07:54:55,299
and then we will be moving towards panda's
library that is built on top of NumPy array
5667
07:54:55,299 --> 07:54:56,299
for better processing of data, I hope to see
you in the next video. Okay, in last video,
5668
07:54:56,299 --> 07:54:57,299
we saw horizontal concatenation, vertical
concatenation sort function, we also saw some
5669
07:54:57,299 --> 07:54:58,299
broadcasting and stuff like so. Universal
functions, it should be speed here, sorry,
5670
07:54:58,299 --> 07:54:59,299
it should be speed, speed. Universal functions
are really, really speedy, I always am talking
5671
07:54:59,299 --> 07:55:00,299
about NumPy. Whenever I start NumPy, I said,
it is fast, it is fast as fast, I never show
5672
07:55:00,299 --> 07:55:01,299
you how fast that is. So let me give you an
example. Let me let me just create an A NumPy
5673
07:55:01,299 --> 07:55:02,299
array with a lot of numbers, and then just
apply an ordinary function, let's say want
5674
07:55:02,299 --> 07:55:03,299
to add all the numbers in this array B, let's
apply an ordinary function that is not in
5675
07:55:03,299 --> 07:55:04,299
NumPy. And then let's use universal function
dot sum, and see how speed differences there.
5676
07:55:04,299 --> 07:55:05,299
If for example, we apply apply a universal
function to achieve a particular task how
5677
07:55:05,299 --> 07:55:06,299
speedy that universal function is, because
a vectorized implementation, as I told you
5678
07:55:06,299 --> 07:55:07,299
is much faster, how faster let's check that
out in new Jupyter Notebook. That's a magic
5679
07:55:07,299 --> 07:55:08,299
command time ID that will tell us how much
time this particular task has, has taken.
5680
07:55:08,299 --> 07:55:09,299
And if you run this command, it will it will
call this function again and again several
5681
07:55:09,299 --> 07:55:10,299
times. And then we'll report an average value
that will be much more stable than just calling
5682
07:55:10,299 --> 07:55:11,299
once. After that, we will also we will also
write our own sum function using loop. And
5683
07:55:11,299 --> 07:55:12,299
we will see whether that is even closer to
a universal function speed or not. Let us
5684
07:55:12,299 --> 07:55:13,299
just check the speed of universal functions
that will give you a look and feel of how
5685
07:55:13,299 --> 07:55:14,299
much NumPy implementation is faster. So let's
say we have an array, let's say B and B dot
5686
07:55:14,299 --> 07:55:15,299
random dot Rand. And let's say that array
is huge, really huge. Let's say that's the
5687
07:55:15,299 --> 07:55:16,299
case. Now what we do is we let's say we we
call a function sum. So let's say we call
5688
07:55:16,299 --> 07:55:17,299
a function sum. That's a built in function.
In Mumbai, that's a built in function that's
5689
07:55:17,299 --> 07:55:18,299
a built in function in Python, not a NumPy
function. And then let's say we do the same
5690
07:55:18,299 --> 07:55:19,299
task using NumPy universal function and P
dot sum, that's the same as NP dot sum is
5691
07:55:19,299 --> 07:55:20,299
the same as if we if we write, for example,
b dot sum.
5692
07:55:20,299 --> 07:55:21,299
So whether you write b dot sum, or you use
NP dot sum and be passed and passed, as an
5693
07:55:21,299 --> 07:55:22,299
argument, both these things are roughly the
same. So let's run it, it will take a while
5694
07:55:22,299 --> 07:55:23,299
It will take a time because, okay, the sum
function takes 307 milliseconds, that is not
5695
07:55:23,299 --> 07:55:24,299
a universal function in NumPy. That's a Python
function. That is not written in NumPy. That
5696
07:55:24,299 --> 07:55:25,299
is not a vectorized code, nothing. It takes
307 milliseconds to perform to take the sum
5697
07:55:25,299 --> 07:55:26,299
of the elements of this array. And it does
that by applying seven rounds in in Santa
5698
07:55:26,299 --> 07:55:27,299
loops. However, the universal function takes
just around three milliseconds, I'm assuming
5699
07:55:27,299 --> 07:55:28,299
2.7 milliseconds, how will how are you going
to compare this 307? With three? How much
5700
07:55:28,299 --> 07:55:29,299
faster you are around? Around 100? times your
faster? I mean, yeah, I mean, this NumPy is
5701
07:55:29,299 --> 07:55:30,299
literally faster NumPy, the universal function
will faster, maybe you attempt to know that,
5702
07:55:30,299 --> 07:55:31,299
okay, the sum function might be too slow.
Let me write my own function. To do that,
5703
07:55:31,299 --> 07:55:32,299
let me define my son, and my son just take
an argument, let's say something, let's say
5704
07:55:32,299 --> 07:55:33,299
G. And what it does is for, let's say s equals
zero, what it does is for x in g, s plus equals
5705
07:55:33,299 --> 07:55:34,299
2x X plus equals to x and then just return
as nothing. That's your function. Let's say
5706
07:55:34,299 --> 07:55:35,299
you think that this is really a great function.
Let's do that. Okay, let's compute the time
5707
07:55:35,299 --> 07:55:36,299
for this time it my son. And let's pause the
rabee and see how faster this is. This is
5708
07:55:36,299 --> 07:55:37,299
roughly the same as your calling the sum function,
but this NP dot sum or the universal function
5709
07:55:37,299 --> 07:55:38,299
is very faster, fairly faster. So, use universal
functions, avoid for loops, avoid your own
5710
07:55:38,299 --> 07:55:39,299
functions, if the same task has been a can
be achieved through universal functions, whenever
5711
07:55:39,299 --> 07:55:40,299
possible, avoid loops when you are working
with NumPy. That serious suggestion, follow
5712
07:55:40,299 --> 07:55:41,299
that, because the universal function written
in NumPy, they follow the vectorized code,
5713
07:55:41,299 --> 07:55:42,299
all the interpreted slowness that is deferred
to the compilation layer. And the NumPy becomes
5714
07:55:42,299 --> 07:55:43,299
really really faster and shows its power when
you are working on large arrays using the
5715
07:55:43,299 --> 07:55:44,299
universal functions. So I can speak more about
NumPy. But I have told you some basics of
5716
07:55:44,299 --> 07:55:45,299
NumPy. And we end the NumPy here and from
the next video, we will be moving towards
5717
07:55:45,299 --> 07:55:46,299
a very, very fancy and beautiful kind of package
called pandas to handle data. And by the way,
5718
07:55:46,299 --> 07:55:47,299
the pandas library the pandas package completely
is built on top of NumPy. Everything that
5719
07:55:47,299 --> 07:55:48,299
is there in pandas is built inside is built
on top of NumPy as all the indexing and all
5720
07:55:48,299 --> 07:55:49,299
kinds of stuff, slicing and speed. All is
there in pandas that is due to the NumPy.
5721
07:55:49,299 --> 07:55:50,299
So we will see one more package after pandas
which is matplotlib for for plotting afterwards.
5722
07:55:50,299 --> 07:55:51,299
And we'll do a project at the end using scikit
learn as well, just to wrap up all these things
5723
07:55:51,299 --> 07:55:52,299
together. But for now I'm ending NumPy here
and in the next video, we will start pandas
5724
07:55:52,299 --> 07:55:53,299
hope to see you in the next video. Okay, welcome
to pandas data science package that is very,
5725
07:55:53,299 --> 07:55:54,299
very powerful of handling data, manipulating
data and used a lot in data munging and data
5726
07:55:54,299 --> 07:55:55,299
cleaning and data pre processing and whatnot.
This pandas basically is built on top of NumPy.
5727
07:55:55,299 --> 07:55:56,299
So most of the features of NumPy is also available
in pandas.
5728
07:55:56,299 --> 07:55:57,299
Let's let's dive in. I mean, this pandas is
a very, very fancy library, very, very fancy
5729
07:55:57,299 --> 07:55:58,299
package, that you can handle very large amounts
of data in CSV files or an Excel files. Wherever
5730
07:55:58,299 --> 07:55:59,299
the data is located. The missing entries are
there. You can handle all the data you can
5731
07:55:59,299 --> 07:56:00,299
manipulate all the data you can prepare all
the data in just a few lines of Using this
5732
07:56:00,299 --> 07:56:01,299
pandas package, so let's just start pandas
package. There are two most important objects
5733
07:56:01,299 --> 07:56:02,299
of pandas. One is series and other is data
frame that we will see later on, there is
5734
07:56:02,299 --> 07:56:03,299
one more index. But the most important one
is, or the useful one is the series and data
5735
07:56:03,299 --> 07:56:04,299
frames. So let's just define, first of all,
you need to import pandas package import pandas.
5736
07:56:04,299 --> 07:56:05,299
And you can rename this as PD, that's a, that's
the most popular renaming, although you can
5737
07:56:05,299 --> 07:56:06,299
rename it any. And then you just say okay,
PD dot series, and then just like a NumPy
5738
07:56:06,299 --> 07:56:07,299
array, you pass the data that you want. And
you can create your own indices, for example,
5739
07:56:07,299 --> 07:56:08,299
like, just like dictionary, this a is a key
value. This is a key or index for this point,
5740
07:56:08,299 --> 07:56:09,299
two, five, this B is index 4.5, C is index
4.75. And these index four one, so you can
5741
07:56:09,299 --> 07:56:10,299
you can, you can supply your explicit indices
as well. If you do not supply the indices,
5742
07:56:10,299 --> 07:56:11,299
the default indices are 012, and three, but
you can define your own his own indices in
5743
07:56:11,299 --> 07:56:12,299
the way you want. Now, once this data object
is created, you can call the data values and
5744
07:56:12,299 --> 07:56:13,299
you will find out the values you can call
the dollar index and you will find out the
5745
07:56:13,299 --> 07:56:14,299
indices let's see in the Jupyter Notebook
just to get comfortable with pandas. First
5746
07:56:14,299 --> 07:56:15,299
of all, import pandas as PD, maybe or something
else. So okay, let's import it, maybe we can
5747
07:56:15,299 --> 07:56:16,299
check what we're going to reveal working in
PD dot worryin. The version of pandas we are
5748
07:56:16,299 --> 07:56:17,299
working in right now is 0.2 4.25. Read. So
let's create data or whatever variable let's
5749
07:56:17,299 --> 07:56:18,299
say a as PD dot series buzy dot series and
there we just give a list of some values 2345
5750
07:56:18,299 --> 07:56:19,299
let's say these are the values. And then we
can give index as another list. Let's say
5751
07:56:19,299 --> 07:56:20,299
the indices are a maybe the indices need not
to be strings, anymore, anything AB, C, and
5752
07:56:20,299 --> 07:56:21,299
let's say the index of fighters. Let's see.
So now the series object or the pandas object
5753
07:56:21,299 --> 07:56:22,299
series is created. Series basically handles
one dimensional arrays, later on, we will
5754
07:56:22,299 --> 07:56:23,299
see DataFrame handles multi dimensional arrays,
I mean more than one dimensions. Normally
5755
07:56:23,299 --> 07:56:24,299
typically two dimensional arrays, but okay,
a dot values. So let's call the values, values,
5756
07:56:24,299 --> 07:56:25,299
and you will get all the values inside the
series. And by the way, this values array
5757
07:56:25,299 --> 07:56:26,299
that you get, let's check what's the type
of that array was type of battery? A dot values?
5758
07:56:26,299 --> 07:56:27,299
What is that thing? That's a NumPy array.
Wow. And what's the type of a itself that
5759
07:56:27,299 --> 07:56:28,299
will be a pandas object. Great. So everything
inside pandas, the NumPy is playing all the
5760
07:56:28,299 --> 07:56:29,299
role inside pandas. Great. So now, let's check
the index a dot index. That's also a NumPy.
5761
07:56:29,299 --> 07:56:30,299
That's also an array of index type, that's
a different actually index is also an object
5762
07:56:30,299 --> 07:56:31,299
in pandas. That's an index type object with
these kind of indices, we can access for example,
5763
07:56:31,299 --> 07:56:32,299
this a, just like we are working with dictionary
for example, a dat returns a value, we can
5764
07:56:32,299 --> 07:56:33,299
change the values, we can add different, we
can add more key value pairs. So just think
5765
07:56:33,299 --> 07:56:34,299
like these.
5766
07:56:34,299 --> 07:56:35,299
Just think this data I'll just like the dictionary
object that we saw this, these are the keys
5767
07:56:35,299 --> 07:56:36,299
and these are the values. And this is one
one very good way of remembering what the
5768
07:56:36,299 --> 07:56:37,299
series does, and manipulating series The way
we want. Okay, one, we can access a z like
5769
07:56:37,299 --> 07:56:38,299
this, we also can do slicing. Let's say we
want to access from A to let's say C let's
5770
07:56:38,299 --> 07:56:39,299
say we want to access all these one difference
is when you access like this, in the normal
5771
07:56:39,299 --> 07:56:40,299
slicing using implicit indices, for example
123 or zero, the final index is not included,
5772
07:56:40,299 --> 07:56:41,299
but if you access like so, using explicit
indices that are there, the final index is
5773
07:56:41,299 --> 07:56:42,299
also included. So that is one more fancy way
of indexing using in this pandas. Okay. Great,
5774
07:56:42,299 --> 07:56:43,299
that's a serious object by the way, we can
create a serious object by first creating
5775
07:56:43,299 --> 07:56:44,299
a dictionary for example. Let's let's go back
to our slides and see this example, let's
5776
07:56:44,299 --> 07:56:45,299
create a dictionary. For example, of plates,
let's have a lot of students with Grade A
5777
07:56:45,299 --> 07:56:46,299
grade A minus Grade B, red b minus, and let's
create that dictionary, then we can just create
5778
07:56:46,299 --> 07:56:47,299
a series object or panda's object, by just
passing this dictionary inside, we can make
5779
07:56:47,299 --> 07:56:48,299
another dictionary for example, and we can
make another series object. So a one way of
5780
07:56:48,299 --> 07:56:49,299
defining the series object is just to is just
to pass the data as well as index in other
5781
07:56:49,299 --> 07:56:50,299
ways to just first create the dictionary and
just pass the dictionary variable inside,
5782
07:56:50,299 --> 07:56:51,299
and the series object will be created. Okay,
that was just an introduction to series, we
5783
07:56:51,299 --> 07:56:52,299
will move on and see more features of pandas,
as we as we explore it more and more in the
5784
07:56:52,299 --> 07:56:53,299
upcoming videos. Hope to see you in the next
video. Okay, let's say we have two different
5785
07:56:53,299 --> 07:56:54,299
dictionaries, let's say we have a lot of students
and the a grade is defined to be four and
5786
07:56:54,299 --> 07:56:55,299
a minus grades defined to be 3.5. The b grade
A has a number three, the B minus grade has
5787
07:56:55,299 --> 07:56:56,299
a number of a numeric value that is 2.5. And
similarly b grade has an American value let's
5788
07:56:56,299 --> 07:56:57,299
do and then we create just a series object
using this dictionary, let's say rather than
5789
07:56:57,299 --> 07:56:58,299
just the numeric values as GPS or something
like so let's say a grade also is defined
5790
07:56:58,299 --> 07:56:59,299
at 85 marks in total, a minus graders defined
at 80 marks in total, and similarly these
5791
07:56:59,299 --> 07:57:00,299
and then we create another series object,
let's say named with Mark marks using these
5792
07:57:00,299 --> 07:57:01,299
PD dot series. So let's go to Jupyter Notebook
and just play a little with these dictionaries.
5793
07:57:01,299 --> 07:57:02,299
And build the series object, let's say marks,
or let's say grades. dictionary equals, let's
5794
07:57:02,299 --> 07:57:03,299
say, a grade, is has has an eighth grade has
number value for RGB value for let's say,
5795
07:57:03,299 --> 07:57:04,299
let's say we have a b grade with GPA value,
let's say B is let's say it's 3.5. Let's say
5796
07:57:04,299 --> 07:57:05,299
we have C grade with GPA value, let's say
three. And let's say Finally, we have d grade
5797
07:57:05,299 --> 07:57:06,299
with GPA value, let's say 2.5. Let's say that's
a dictionary. Okay? What we do now is we create
5798
07:57:06,299 --> 07:57:07,299
a grades series object, let's say using PD
dot series, and just pass this grades underscore
5799
07:57:07,299 --> 07:57:08,299
teched. Now this capital a capital B, capital
C and capital D, they will act as indices
5800
07:57:08,299 --> 07:57:09,299
and this for 3.53. In 2.5, they will act like
values. So for example, if we call her and
5801
07:57:09,299 --> 07:57:10,299
just now called grades dot v dot values, so
we will get, for example, what is that? That
5802
07:57:10,299 --> 07:57:11,299
just values, let's say, beget this grade stock
values, and we get all the values that are
5803
07:57:11,299 --> 07:57:12,299
available. Similarly, if we find grades or
index, we will find out A, B, C and D. Let's
5804
07:57:12,299 --> 07:57:13,299
define another dictionary, for example, marks
dictionary dict. And there is let's say again,
5805
07:57:13,299 --> 07:57:14,299
a while the total marks are 85. For the a
grade, let's say, for b grade, the total marks
5806
07:57:14,299 --> 07:57:15,299
are let's say, 75. Let's say for C grade,
the total marks are
5807
07:57:15,299 --> 07:57:16,299
let's say 65. And for D grade, let's say the
total marks are 55, let's say. So let's say
5808
07:57:16,299 --> 07:57:17,299
that's another dictionary. Now, let's create
a series of objects, a series object PD dot
5809
07:57:17,299 --> 07:57:18,299
series, series, let's say marks dictionary.
So now again, we have if you just write this
5810
07:57:18,299 --> 07:57:19,299
marks, just like so, you will see the marks
is 85, b 75, c 65, D is 55. And all the values
5811
07:57:19,299 --> 07:57:20,299
they are integer 64. Ghana values, now we
can access. Now we can play with this marks,
5812
07:57:20,299 --> 07:57:21,299
for example, if we just want to access for
example, what are the marks? What are the
5813
07:57:21,299 --> 07:57:22,299
marks between, let's say, for example, what
are the marks given a at a we can access that
5814
07:57:22,299 --> 07:57:23,299
we can change that we can just play like a
dictionary. What if we rather than using the
5815
07:57:23,299 --> 07:57:24,299
index In a, we use for example, slicing, we
want to start from the very beginning. And
5816
07:57:24,299 --> 07:57:25,299
let's say we want to go to two what will happen?
Let's see. Yeah, so, the slicing is there
5817
07:57:25,299 --> 07:57:26,299
for example, if you want these are explicit
indices A B, C, D, these are explicit indices
5818
07:57:26,299 --> 07:57:27,299
and they are there. For example, if you can
slice the you can slice the data using explicit
5819
07:57:27,299 --> 07:57:28,299
indices that you are given that you are given
or implicit indices that are the default indices,
5820
07:57:28,299 --> 07:57:29,299
the first value index at zero, the second
value is index two one and so on. So, you
5821
07:57:29,299 --> 07:57:30,299
can do that as well, one catch here for example,
that we will see later on, there may be a
5822
07:57:30,299 --> 07:57:31,299
problem that your explicit indices they are
also numeric, and then you do the slicing
5823
07:57:31,299 --> 07:57:32,299
like so, then the series object may be confused
whether I have to use the explicit indices
5824
07:57:32,299 --> 07:57:33,299
or implicit indices inside we will see how
to resolve that issue, but by this pandas
5825
07:57:33,299 --> 07:57:34,299
allowed to use explicit indices as well as
the implicit indices. Okay, we were here.
5826
07:57:34,299 --> 07:57:35,299
So, he just so, yeah, so, we were here. So,
we have created these grades a series object
5827
07:57:35,299 --> 07:57:36,299
This marks as a series object, these the series
object is good for one dimensional arrays
5828
07:57:36,299 --> 07:57:37,299
or data with just one dimensional list or
dictionary, kind of with just one dimensions,
5829
07:57:37,299 --> 07:57:38,299
later, we will see data frame that actually
is is actually the extension of curl can be
5830
07:57:38,299 --> 07:57:39,299
looks like it can be looked like as an extension
of series towards more than one dimension,
5831
07:57:39,299 --> 07:57:40,299
we may have, for example, two dimensional
arrays or two dimensional data structures,
5832
07:57:40,299 --> 07:57:41,299
something like so. And we will be seeing this
data frame which is much more powerful, particularly
5833
07:57:41,299 --> 07:57:42,299
for reading data from files and manipulating
it and stuff like so. We will see that in
5834
07:57:42,299 --> 07:57:43,299
the next video data frame that running form
of data frame in the next video, hope to see
5835
07:57:43,299 --> 07:57:44,299
you in the next video. Okay, in the last video,
we were discussing series, and I told you
5836
07:57:44,299 --> 07:57:45,299
that data frame is basically if if the data
has if the data in the form of different columns,
5837
07:57:45,299 --> 07:57:46,299
for example, a record as an array, then you
have another record, then you have another
5838
07:57:46,299 --> 07:57:47,299
record. And each element in that record is
a different attribute. So this particular
5839
07:57:47,299 --> 07:57:48,299
way of two dimensional data is very well handled
using data frame inside pandas rather than
5840
07:57:48,299 --> 07:57:49,299
series. So but you can make these data frame
objects using different series objects. For
5841
07:57:49,299 --> 07:57:50,299
example, you have a great object that grades
object that we created last time, you know,
5842
07:57:50,299 --> 07:57:51,299
marks object that we created last time, let's
build a data frame using these two and see
5843
07:57:51,299 --> 07:57:52,299
what it looks like in in Jupyter. notebook.
Let's see that. So remember, we have a marks
5844
07:57:52,299 --> 07:57:53,299
series object, and we have a grades series
object. Let's now make grades. Maybe, maybe
5845
07:57:53,299 --> 07:57:54,299
the name is rates, okay? The name is like
grades. Okay, so grades object, this one,
5846
07:57:54,299 --> 07:57:55,299
let's make a data frame.
5847
07:57:55,299 --> 07:57:56,299
Let's say D, or maybe whatever name you want
to do data frame with, again, that data frame
5848
07:57:56,299 --> 07:57:57,299
can also be defined using a dictionary. Again,
now we have let's say, marks is the key for
5849
07:57:57,299 --> 07:57:58,299
data marks. And grades is the key for data
grades. Let's say let's say we define a data
5850
07:57:58,299 --> 07:57:59,299
frame like so. And now if you see if you just
display this D, we get a very beautiful look
5851
07:57:59,299 --> 07:58:00,299
and feel of I mean this as the index is the
explicit index at index a, the marks, the
5852
07:58:00,299 --> 07:58:01,299
marks is 85. The grades are for at index B,
the marks are 75, the grades are 33.5. And
5853
07:58:01,299 --> 07:58:02,299
so on that that looks like so not only that,
you can just transpose it like you have transpose
5854
07:58:02,299 --> 07:58:03,299
to a NumPy array, and you will get the flipped
version or the transpose variant if you want.
5855
07:58:03,299 --> 07:58:04,299
Great. So that's how and you can have for
example, more dictionaries to concatenate
5856
07:58:04,299 --> 07:58:05,299
together and more columns will be added here.
And that's what the real data looks like.
5857
07:58:05,299 --> 07:58:06,299
I mean, it has a lot of columns, which normally
are attributes. And each row is basically
5858
07:58:06,299 --> 07:58:07,299
one record or one sample of the data that
you want to work on. So this data frame is
5859
07:58:07,299 --> 07:58:08,299
really, really ideal data structure for working
with files, having a lot of records and you
5860
07:58:08,299 --> 07:58:09,299
want to manipulate the data and stuff like
so. So yeah, so one more thing, let's let's
5861
07:58:09,299 --> 07:58:10,299
access the D, for example, that's brand D,
that's the, that's the D, let's access the
5862
07:58:10,299 --> 07:58:11,299
values inside D, other than No, so what are
the values, so, the values inside D is completely
5863
07:58:11,299 --> 07:58:12,299
again, a two dimensional array that is completely
like so. So for example, if we want to access
5864
07:58:12,299 --> 07:58:13,299
this particular element 65, that is row number
three, and column number one, excluding the
5865
07:58:13,299 --> 07:58:14,299
indices at row number three and column number
one. So we can access that particular value
5866
07:58:14,299 --> 07:58:15,299
T dot values, just assuming that dimensional
NumPy array, row number three is to index
5867
07:58:15,299 --> 07:58:16,299
with do and column number one is index with
that, and we will be able to access 65. Wow,
5868
07:58:16,299 --> 07:58:17,299
great. So that is there. There are more things
that are available d dot for example, columns,
5869
07:58:17,299 --> 07:58:18,299
d dot columns, columns, it will give us what
are the columns, the columns are marks and
5870
07:58:18,299 --> 07:58:19,299
grades. There and there are other properties.
And there are other several properties that
5871
07:58:19,299 --> 07:58:20,299
we need to know Rs, for example, this there,
we define this as di d dot index and stuff
5872
07:58:20,299 --> 07:58:21,299
like so. Okay. One more thing that you need
to know is we can repeat right now we have
5873
07:58:21,299 --> 07:58:22,299
that sub D, that is this one. That's the D.
Let's say we want to add another column here,
5874
07:58:22,299 --> 07:58:23,299
just we want to add another column here. And
that is the name of that column is scaled
5875
07:58:23,299 --> 07:58:24,299
marks. And the scale marks are what if we
have computed marks, rather than from 100?
5876
07:58:24,299 --> 07:58:25,299
What if we have computed marks out of 90?
What are the scaled marks up 90? So one way
5877
07:58:25,299 --> 07:58:26,299
to do that, and very quick way to do that
is just like a dictionary, again, like a dictionary,
5878
07:58:26,299 --> 07:58:27,299
you just add a new key, let's say, scaled
marks, that's a new key. and the value is
5879
07:58:27,299 --> 07:58:28,299
simply all the marks column divided by 90.
So is that true? No? divided by 90, if we
5880
07:58:28,299 --> 07:58:29,299
have just completed all the marks by 90, and
then how can we? How can we compute the marks
5881
07:58:29,299 --> 07:58:30,299
from 90? It is rather than 100. It is from
90, I guess? How can we compute the marks
5882
07:58:30,299 --> 07:58:31,299
from 90? If you want to compute the marks
from 90, I guess they will look like and divided
5883
07:58:31,299 --> 07:58:32,299
by 90. And maybe 100 is multiplied here. I
guess maybe the formula. I guess that that
5884
07:58:32,299 --> 07:58:33,299
that's what it is, I guess let's see. So now
if you see D, there will be another column
5885
07:58:33,299 --> 07:58:34,299
that is there. And oh, it does something else.
Anyways, it does something that Yeah, so something
5886
07:58:34,299 --> 07:58:35,299
anyways, so we see we have just, I mean, we've
just computed this, we just
5887
07:58:35,299 --> 07:58:36,299
we just found that we just inserted that column
inside that I'm in, there is a process for
5888
07:58:36,299 --> 07:58:37,299
each of these kinds of values. Maybe we have
added this column in a very wrong way. And
5889
07:58:37,299 --> 07:58:38,299
later on, we suggest that okay, we should
delete that column. Well, that's very simple.
5890
07:58:38,299 --> 07:58:39,299
Again, using the concepts again, just like
the dictionaries, delete this, and this column
5891
07:58:39,299 --> 07:58:40,299
is deleted from data. And you're again with
the data that you had. So you can add columns,
5892
07:58:40,299 --> 07:58:41,299
you can delete columns, and indexing is really
fine. I mean, indexing like like masking,
5893
07:58:41,299 --> 07:58:42,299
let's say, you want to bake for example, or
you want to bake the DataFrame such that you
5894
07:58:42,299 --> 07:58:43,299
want to pick all the records such that the
marks are the marks are. The marks are greater
5895
07:58:43,299 --> 07:58:44,299
than let's say, greater than, let's say 70.
You want to pick all the records where the
5896
07:58:44,299 --> 07:58:45,299
bulk of the marks are greater than 70. This
is that simple. All the data will be will
5897
07:58:45,299 --> 07:58:46,299
be copied into g with this condition. And
this condition can be arbitrarily complex
5898
07:58:46,299 --> 07:58:47,299
using ands and ORS and combinations and all
that stuff. And you have seen this kind of
5899
07:58:47,299 --> 07:58:48,299
stuff in NumPy as well. I mean, this is called
Okay, great. So that's available in pandas
5900
07:58:48,299 --> 07:58:49,299
as well. Okay, so that's how you can index
in the next. In the next video, I'm going
5901
07:58:49,299 --> 07:58:50,299
to basically show you one type of problem
that normally happens in real data that is
5902
07:58:50,299 --> 07:58:51,299
the missing value problem. Sometimes you read
a data and some of the attributes or some
5903
07:58:51,299 --> 07:58:52,299
of the row column p values they are just missing.
I mean, they are not available due to certain
5904
07:58:52,299 --> 07:58:53,299
reasons. How can you How can you handle those
values? And how actually pandas suggest you
5905
07:58:53,299 --> 07:58:54,299
to handle those kinds of missing values, which
are sometimes called Nan values or non type
5906
07:58:54,299 --> 07:58:55,299
values. Also, they they mostly used interchangeably
in pandas. So in the next video, we are going
5907
07:58:55,299 --> 07:58:56,299
to handle or see how to handle missing data
in pandas hope to see you in the next video.
5908
07:58:56,299 --> 07:58:57,299
Okay, in the last video, we saw data frame
object. And we saw actually how to add and
5909
07:58:57,299 --> 07:58:58,299
remove columns how to process data, how to
index how to actually mask or how to apply
5910
07:58:58,299 --> 07:58:59,299
conditions and selections in in bond as we
saw that very briefly, but in this particular
5911
07:58:59,299 --> 07:59:00,299
video, we are going to see one kind of missing
value, sometimes called name or not a number,
5912
07:59:00,299 --> 07:59:01,299
or maybe not anything or sometimes this nun
type none, which is the default return type
5913
07:59:01,299 --> 07:59:02,299
of any function. In Python. This non type
is also sometimes in pandas is treated as
5914
07:59:02,299 --> 07:59:03,299
Nan or Nan is treated as none or interchangeably.
Any anything. Let me give you what do we mean
5915
07:59:03,299 --> 07:59:04,299
by that, let's say we have two dictionaries,
let's say one dictionary is a with key value
5916
07:59:04,299 --> 07:59:05,299
a and value is one, then B and the value is
two. Okay? The other dictionary is B and C.
5917
07:59:05,299 --> 07:59:06,299
So for example, that is one record with columns
A and B. So a and b are the columns. On the
5918
07:59:06,299 --> 07:59:07,299
first record, the value of a is one, and the
value of b is two. Now let's say we want to
5919
07:59:07,299 --> 07:59:08,299
insert another record in the same data frame.
Now the value of b is available in the second
5920
07:59:08,299 --> 07:59:09,299
time, well, if b is available, which is three,
and the value of c is available, which means
5921
07:59:09,299 --> 07:59:10,299
a C column is added now. But for the value
c the first row value is not available. So
5922
07:59:10,299 --> 07:59:11,299
we will say this value is missing here. But
in the second row, we have four similarly,
5923
07:59:11,299 --> 07:59:12,299
the value of a is missing for for the second
row, and that is a missing value, which is
5924
07:59:12,299 --> 07:59:13,299
sometimes called Nam. So these are missing
values. And they are typical. When you are
5925
07:59:13,299 --> 07:59:14,299
working with data. And you're reading data
on you're getting data from, from out from
5926
07:59:14,299 --> 07:59:15,299
somewhere or large files and stuff like so.
So pandas give some methods to handle these
5927
07:59:15,299 --> 07:59:16,299
kind of
5928
07:59:16,299 --> 07:59:17,299
these kind of I mean, this kind of situation,
let's say let's say a equals PD dot data frame,
5929
07:59:17,299 --> 07:59:18,299
data frame, again, a dictionary, let's say
we have a,
5930
07:59:18,299 --> 07:59:19,299
one and B, let's say four, that's the first
row or record. The second record, let's say
5931
07:59:19,299 --> 07:59:20,299
is another dictionary, let's say B is minus
three, and C is let's say, nine. That's it.
5932
07:59:20,299 --> 07:59:21,299
That's it. That's our data frame a. So now
if you bring this a if you see the data inside
5933
07:59:21,299 --> 07:59:22,299
a, you will see Oh, what's the problem? Is
this and be heavy? Have you played something
5934
07:59:22,299 --> 07:59:23,299
in a wrong way? Let's see. Oh, we have to
create a list. That's okay, we have to create
5935
07:59:23,299 --> 07:59:24,299
a list of it, you have to create list of dictionaries,
that's the proper way of calling it. So we
5936
07:59:24,299 --> 07:59:25,299
missed just this index list of that. Okay,
right. So now we have this A, B, just call
5937
07:59:25,299 --> 07:59:26,299
that a and this value is missing and that
value is missing. And in large data files,
5938
07:59:26,299 --> 07:59:27,299
this is typical, I mean, there are a lot of
values that can be missing. One way that pandas
5939
07:59:27,299 --> 07:59:28,299
supplies to hell these missing values is to
just fill these missing values with some some
5940
07:59:28,299 --> 07:59:29,299
fixed number for example, there is a fill
na function, fill any function and let's say
5941
07:59:29,299 --> 07:59:30,299
you supply as zero that means wherever there
is a not available or not a number value,
5942
07:59:30,299 --> 07:59:31,299
fill that with zero, or maybe any any value
you want to fill that with. So that is One
5943
07:59:31,299 --> 07:59:32,299
way to do that, and now if you see the value
of a is all the non values are filled with
5944
07:59:32,299 --> 07:59:33,299
that, another kind of function that is available
in pandas that is sometimes used a that is
5945
07:59:33,299 --> 07:59:34,299
drop na that that function drop na, what that
does is it drops all the records that contain
5946
07:59:34,299 --> 07:59:35,299
a missing value. Sometimes if that is visible,
I mean dropping all the records that contain
5947
07:59:35,299 --> 07:59:36,299
missing values, if that is visible, then go
for that. But if if the if the missing values
5948
07:59:36,299 --> 07:59:37,299
are a lot and they are spread over a lot of
rows, then dropping all those kinds of records,
5949
07:59:37,299 --> 07:59:38,299
they will create a lot of I mean data loss
and and then it becomes really, really important
5950
07:59:38,299 --> 07:59:39,299
how to how to handle these missing values.
However, you can fix you can fill the missing
5951
07:59:39,299 --> 07:59:40,299
values using fixed value or you can drop them
and later on we will see in scikit learn that
5952
07:59:40,299 --> 07:59:41,299
there are other ways of handling the missing
values as well, you can fill the each column
5953
07:59:41,299 --> 07:59:42,299
missing values in each column using an average
or using for example, a regression there are
5954
07:59:42,299 --> 07:59:43,299
ways to to handle these missing values. But
in pandas, these two functions are right away
5955
07:59:43,299 --> 07:59:44,299
they are you can fill all them with a fixed
value for example or you can drop them and
5956
07:59:44,299 --> 07:59:45,299
you are ready to go. Okay great. Next, we
are going to see oh as as I mentioned earlier,
5957
07:59:45,299 --> 07:59:46,299
what is the what is the confusion between
what if there is a confusion between implicit
5958
07:59:46,299 --> 07:59:47,299
and explicit indices. And that I will discuss
in the next video basically, just to give
5959
07:59:47,299 --> 07:59:48,299
you a look and feel what if the explicit indices
you supply they are one three and five. And
5960
07:59:48,299 --> 07:59:49,299
what if you call this this particular command
one colon three, will it call the implicit
5961
07:59:49,299 --> 07:59:50,299
index or the explicit index, that's a problem.
So we will see because 1.1 colon three, one
5962
07:59:50,299 --> 07:59:51,299
and three they are also explicit indices.
And whether this one colon three is referring
5963
07:59:51,299 --> 07:59:52,299
to the implicit indices that are default indices,
or they're referring to these indices. So
5964
07:59:52,299 --> 07:59:53,299
this confusion is there and we will see how
to handle that confusion. Using this lock,
5965
07:59:53,299 --> 07:59:54,299
LLC function and index lock ilsc function,
we will see that in the next video, hope to
5966
07:59:54,299 --> 07:59:55,299
see you in the next
5967
07:59:55,299 --> 07:59:56,299
video. Okay, in the previous video, I mentioned
a confusion that can be there, if you have
5968
07:59:56,299 --> 07:59:57,299
supplied the explicit indices that can conflict
with implicit indices. In particular, for
5969
07:59:57,299 --> 07:59:58,299
example, if this is the series object, or
maybe a data frame object if you want to if
5970
07:59:58,299 --> 07:59:59,299
for indices, let's just think about the series
object, it has these values ABC with index
5971
07:59:59,299 --> 08:00:00,299
one three and five, if you for example, access
a particular element let's say data with index
5972
08:00:00,299 --> 08:00:01,299
one that means the explicit index for sure,
but if for example, we slice the values for
5973
08:00:01,299 --> 08:00:02,299
example, one colon three, the default behavior
of slicing if you give an American disease,
5974
08:00:02,299 --> 08:00:03,299
that is to use implicit indices, and by implicit
indices, we mean by we mean that what is at
5975
08:00:03,299 --> 08:00:04,299
index one at index one this is b, so B will
be printed for example, or B will be fetched,
5976
08:00:04,299 --> 08:00:05,299
and then you move to do which is C then C
will be fetched, and these are the values
5977
08:00:05,299 --> 08:00:06,299
that will be printed, but the behavior might
be different, you might be expecting to use
5978
08:00:06,299 --> 08:00:07,299
explicit indices, which means access one colon
three, and when the explicit indices are used,
5979
08:00:07,299 --> 08:00:08,299
the last index is also included. And in that
case, you might be expecting the index one
5980
08:00:08,299 --> 08:00:09,299
is of a so as should be printed, and index
three is of B and B should be printed. And
5981
08:00:09,299 --> 08:00:10,299
this configure might be there if if this is
there. So to handle that there is there are
5982
08:00:10,299 --> 08:00:11,299
two functions one is called l OC. And another
method is called i l OC, whenever you call
5983
08:00:11,299 --> 08:00:12,299
LLC, that means you are using explicit indices.
I mean, you're forcing to use explicit index.
5984
08:00:12,299 --> 08:00:13,299
And whenever you call, I LSE that means you're
accessing elements using the implicit index
5985
08:00:13,299 --> 08:00:14,299
what whatsoever. So let's, let's practice
this and see the confusion. See the detail
5986
08:00:14,299 --> 08:00:15,299
of this kind of confusions in in here Jupyter
Notebook. So let's say we have a series object,
5987
08:00:15,299 --> 08:00:16,299
let's say a equals PD dot series. And let's
say it has values as a, b, and c, NASA value.
5988
08:00:16,299 --> 08:00:17,299
These are the values and index as let's say
One, three and five let's add these are the
5989
08:00:17,299 --> 08:00:18,299
indices let's say this is eight Okay, let's
say we access a using one that means that
5990
08:00:18,299 --> 08:00:19,299
means the explicit index and that is this
let's say B access and using the slicing operator.
5991
08:00:19,299 --> 08:00:20,299
Now, this will use implicit indices and it
will access I mean it will access these B
5992
08:00:20,299 --> 08:00:21,299
and C because one colon three using indices
implicit indices results that and we might
5993
08:00:21,299 --> 08:00:22,299
be might be expecting that use this kind of
stuff. So, if we are really interested in
5994
08:00:22,299 --> 08:00:23,299
using explicit indices, what should we do
is we should call the lat function a lock
5995
08:00:23,299 --> 08:00:24,299
and then one colon three that means, use explicit
indices there is to remove the confusions
5996
08:00:24,299 --> 08:00:25,299
now, it will use the explicit index one and
three and if for example, we are interested
5997
08:00:25,299 --> 08:00:26,299
in using implicit indices, then it is good
to use ilok function Yeah, now, one one column
5998
08:00:26,299 --> 08:00:27,299
three is to use implicit indices and the implicit
indices are like these. So, and like in series
5999
08:00:27,299 --> 08:00:28,299
objects you can you can you can do the same
in data frame objects. Once you are using
6000
08:00:28,299 --> 08:00:29,299
lock and ilok then the further indexing inside
these square brackets is exactly the same
6001
08:00:29,299 --> 08:00:30,299
like NumPy. So, whether you use log or ILOG,
the indexing mechanism is exactly that the
6002
08:00:30,299 --> 08:00:31,299
slicing mechanism is exactly the same like,
like you you you have used in in NumPy. I
6003
08:00:31,299 --> 08:00:32,299
mean all indexing that stays the same log
means you're using explicit index ILOG means
6004
08:00:32,299 --> 08:00:33,299
you are using explicit implicit index. Let's
say for example, we have our data frame, I
6005
08:00:33,299 --> 08:00:34,299
guess D, that's our data frame available to
us. Let's say I want to access d dot ilok.
6006
08:00:34,299 --> 08:00:35,299
Let's say I want to access the second row
completely the second record, oh, the record
6007
08:00:35,299 --> 08:00:36,299
that is indexed at look at an index at two,
which is a third row completely, let's say
6008
08:00:36,299 --> 08:00:37,299
I want to
6009
08:00:37,299 --> 08:00:38,299
access that. Now this two is acting as this
two is acting as, for example, if you see
6010
08:00:38,299 --> 08:00:39,299
the the second row or the or the row at the
second index, which is a third row that is
6011
08:00:39,299 --> 08:00:40,299
completely this edit returns that once you
have used a lock, for example, and mostly
6012
08:00:40,299 --> 08:00:41,299
people use ilok. Sometimes lock is also required.
But I log is just to explicitly mentioning
6013
08:00:41,299 --> 08:00:42,299
that I'm using I'm going to use the implicit
indexing scheme. Again, you can consider hold
6014
08:00:42,299 --> 08:00:43,299
that thing as a matrix. And once you have
applied this eye lock, then you're free to
6015
08:00:43,299 --> 08:00:44,299
play with the indices, like you play with
two dimensional arrays, for example. I want
6016
08:00:44,299 --> 08:00:45,299
to for example, I want to reverse, for example,
all the rows and I want to reverse all the
6017
08:00:45,299 --> 08:00:46,299
all the all the structure, for example, let's
say I want to do that. And you can see everything
6018
08:00:46,299 --> 08:00:47,299
is reversed. I mean all the indexing like
like nine by all indexing is there in, in
6019
08:00:47,299 --> 08:00:48,299
pandas. I mean, once you have used ilok inside
is just just remember the NumPy indexing and
6020
08:00:48,299 --> 08:00:49,299
everything like so. Okay, so that's the log
and I log function. In the next video, we
6021
08:00:49,299 --> 08:00:50,299
are actually going to going to just practice
the pandas to actually to actually work on
6022
08:00:50,299 --> 08:00:51,299
our data file that is saved as a CSV file.
So we will, we will show you how to how to
6023
08:00:51,299 --> 08:00:52,299
actually add how to actually manipulate read
and write the data and play with the data,
6024
08:00:52,299 --> 08:00:53,299
the data, the real data that is there in in
some CSV file, and how pandas will help you
6025
08:00:53,299 --> 08:00:54,299
to to manipulate the data very efficiently
and very quickly. So hope to see you in the
6026
08:00:54,299 --> 08:00:55,299
next video. Okay, in this particular video,
I will be talking about real data set. The
6027
08:00:55,299 --> 08:00:56,299
data set I have chosen just to show you some
some functions that are available in pandas
6028
08:00:56,299 --> 08:00:57,299
to work on real data set the data set I've
chosen as COVID-19 data set that was available
6029
08:00:57,299 --> 08:00:58,299
on kaggle. And it's surreal data set that
contains information of victims recovered
6030
08:00:58,299 --> 08:00:59,299
the total number of recovered people in per
country per province, the total number of
6031
08:00:59,299 --> 08:01:00,299
died people and the total number of number
of reported people per date available that
6032
08:01:00,299 --> 08:01:01,299
that data is available. Let's see the look
and feel of that data in a file. Just to just
6033
08:01:01,299 --> 08:01:02,299
to see what kind of data we are talking about.
Let's say this is our data. This is the serial
6034
08:01:02,299 --> 08:01:03,299
number column that contains just the record
number. That's, that's a column called observation
6035
08:01:03,299 --> 08:01:04,299
date. That's a date, that's a province or
state. That's country or region that's last
6036
08:01:04,299 --> 08:01:05,299
updated when the record is updated was the
time and how many confirmed cases were there
6037
08:01:05,299 --> 08:01:06,299
at that date, and how many deaths at that
date and how many recovered at that date,
6038
08:01:06,299 --> 08:01:07,299
as the date is moving on and on, you will
be seeing that the number of confirmed cases
6039
08:01:07,299 --> 08:01:08,299
and the number of recovered cases they will
be increasing, maybe the number of deaths
6040
08:01:08,299 --> 08:01:09,299
they also increase. So let's see this data.
Let's read that data using pandas and do some
6041
08:01:09,299 --> 08:01:10,299
manipulation of this data and see the look
and feel of that data. In Jupyter, notebook.
6042
08:01:10,299 --> 08:01:11,299
Let's go to Jupyter Notebook and see. So first
of all, I need this pandas library and pour
6043
08:01:11,299 --> 08:01:12,299
it that maybe somewhere I need this NumPy
library as well. I'm also learning a psychic
6044
08:01:12,299 --> 08:01:13,299
learn SK learn library because I want to,
I want to use impute function, just to handle
6045
08:01:13,299 --> 08:01:14,299
the missing values, it is just more powerful
to use the I'm in the SK learn library there
6046
08:01:14,299 --> 08:01:15,299
is also a Data Science Library package that
is particularly a machine learning library,
6047
08:01:15,299 --> 08:01:16,299
or our package that actually gives a better
support or a larger support of handling missing
6048
08:01:16,299 --> 08:01:17,299
data. Although here I have used this SK learn
function just for an example. And but but
6049
08:01:17,299 --> 08:01:18,299
I could have used this data frame fill any
function or something like so but I'm just
6050
08:01:18,299 --> 08:01:19,299
using that one. Okay, after importing all
these, what I did is I just call PD dot read
6051
08:01:19,299 --> 08:01:20,299
CSV function, and I load that data and then
I did this stuff one by one. Let's, let's
6052
08:01:20,299 --> 08:01:21,299
let's spend some time on all these commands
one by one. And let's see in Jupyter Notebook,
6053
08:01:21,299 --> 08:01:22,299
what is happening, let's go to Jupyter Notebook
and actually read that file and do whatever
6054
08:01:22,299 --> 08:01:23,299
we are doing here. So first of all, import
NumPy that is already imported. Import.
6055
08:01:23,299 --> 08:01:24,299
For example, pandas that is also already imported,
then from SK learn dot impute import simple
6056
08:01:24,299 --> 08:01:25,299
impurity. So let's let's use that or let's
Okay, let's do that. From SK learn dot impute
6057
08:01:25,299 --> 08:01:26,299
SK learn dot impute import simple in pewter,
okay, import that because that's a new thing,
6058
08:01:26,299 --> 08:01:27,299
we need to import that now read the data,
for example, data frame in df. So df equals
6059
08:01:27,299 --> 08:01:28,299
PD dot read CSV. There is a CSV file read
CSV. And it contains the path of the file.
6060
08:01:28,299 --> 08:01:29,299
The path is located in my directory, it is
located at this particular location COVID.
6061
08:01:29,299 --> 08:01:30,299
And the name of that is COVID, underscore
19 ESCO data. So COVID underscore 19 underscore
6062
08:01:30,299 --> 08:01:31,299
data dot c s v. So let's read that file, the
file will be read, if you just see that some
6063
08:01:31,299 --> 08:01:32,299
of there is a function, let's say head that
gives the top records or the records that
6064
08:01:32,299 --> 08:01:33,299
appear just the very top that's that's what
the data file that I was showing you in Excel,
6065
08:01:33,299 --> 08:01:34,299
it is showing just the first five records,
I can show the first 10 Records, for example,
6066
08:01:34,299 --> 08:01:35,299
just by calling the head function in this
particular way. Okay, great. Let's say I just
6067
08:01:35,299 --> 08:01:36,299
want to remove this real number because I
think that is not required. And let's say
6068
08:01:36,299 --> 08:01:37,299
I want to remove this particular column. Because
that is also not required. There are multiple
6069
08:01:37,299 --> 08:01:38,299
ways of doing that. I can call an t l function
on this. And I can call the L function on
6070
08:01:38,299 --> 08:01:39,299
that. But there is another way of doing that
by df dot drop df dot drop and in that you
6071
08:01:39,299 --> 08:01:40,299
just give the columns that you want to drop
one column is serial number, I guess, what's
6072
08:01:40,299 --> 08:01:41,299
the column name? That's s and No. So you want
to you want to drop that column and then you
6073
08:01:41,299 --> 08:01:42,299
want to drop this particular column with herring
last update. So that is last update. So that
6074
08:01:42,299 --> 08:01:43,299
is I guess what is there
6075
08:01:43,299 --> 08:01:44,299
Xs one in place Drew. So Xs one is justments.
Mentioning, do do that stuff with columns
6076
08:01:44,299 --> 08:01:45,299
in place, equals true. That actually is, is
telling that whatever this operation you are
6077
08:01:45,299 --> 08:01:46,299
going to do reflect the changes in this df
frame. If we do not write in place to it,
6078
08:01:46,299 --> 08:01:47,299
we'll do everything and return onto a temporary
variable or underscore variable or whatever
6079
08:01:47,299 --> 08:01:48,299
we are saying, but the DF the data frame will
stay unchanged. So in place true means do
6080
08:01:48,299 --> 08:01:49,299
that changing in df variable itself. So now
if we see df dot had flat say, it will no
6081
08:01:49,299 --> 08:01:50,299
longer be showing us the serial number column
and the last updated column. What next we
6082
08:01:50,299 --> 08:01:51,299
can do we may we may want to rename this,
this name to just date. For example, this
6083
08:01:51,299 --> 08:01:52,299
to maybe another, let's rename all these columns,
using using the Rename function, df dot rename
6084
08:01:52,299 --> 08:01:53,299
columns equals two and then we have that dictionary
again in place equals two. So let's use let's
6085
08:01:53,299 --> 08:01:54,299
use this read in function, TF dot rename.
Let's do that. And here we have columns, columns,
6086
08:01:54,299 --> 08:01:55,299
if I spell right columns, and then that is
dictionary what columns you want to change,
6087
08:01:55,299 --> 08:01:56,299
I want to change observation date, I want
to change that to simply date, let's say and
6088
08:01:56,299 --> 08:01:57,299
I also want to change province slash state
to simply simply state, our province province
6089
08:01:57,299 --> 08:01:58,299
that say simply that and I also want to change
this country slash region to simply country.
6090
08:01:58,299 --> 08:01:59,299
So, maybe I want to change this country slash
region to simply due to country cru and try
6091
08:01:59,299 --> 08:02:00,299
country and I want all that should be happen
in place. So in place equals true. So after
6092
08:02:00,299 --> 08:02:01,299
that, if you run that, on this particular
step, and now if you see the state of df,
6093
08:02:01,299 --> 08:02:02,299
you will get like
6094
08:02:02,299 --> 08:02:03,299
so. Okay, these many, so they province country,
confirm debts, and so on. So this is much
6095
08:02:03,299 --> 08:02:04,299
nicer form than earlier. Moreover, we may
have a lot of missing values, oh, one way,
6096
08:02:04,299 --> 08:02:05,299
this date format, the date format is not in
a format that pandas internal date format.
6097
08:02:05,299 --> 08:02:06,299
So let's convert the date format into into
into the internal pandas date format, using
6098
08:02:06,299 --> 08:02:07,299
to to PD to date time function. So let's say
df date equals to PD to date time, and convert
6099
08:02:07,299 --> 08:02:08,299
this df date in that particular format. And
now if you run this TF dot had to might be
6100
08:02:08,299 --> 08:02:09,299
seeing the date format in a different way.
See that that's the that's that's the date
6101
08:02:09,299 --> 08:02:10,299
format that the pandas is expecting. Now,
we that that is just showing showing some
6102
08:02:10,299 --> 08:02:11,299
records if you want to see more records, we
can see those let's say I want to just I want
6103
08:02:11,299 --> 08:02:12,299
to just count or let's say let's just describe
all the data at TF dot describe there is a
6104
08:02:12,299 --> 08:02:13,299
describe function that describe all most of
the statistics of the data, I mean, the total
6105
08:02:13,299 --> 08:02:14,299
count of confirmed cases are these the deaths
are these recovered are these these many columns
6106
08:02:14,299 --> 08:02:15,299
are there these many values are there. The
mean is that and standard deviation is the
6107
08:02:15,299 --> 08:02:16,299
minimum 25. And these are the statistics.
Let's say there is another function info df
6108
08:02:16,299 --> 08:02:17,299
dot d A dog info. If you call that function
info, it will give us the more information
6109
08:02:17,299 --> 08:02:18,299
about the null increase and the nominal increase
and so on. For example, if you see the total
6110
08:02:18,299 --> 08:02:19,299
number of data columns are six, the total
number of records are 6162. The date increase
6111
08:02:19,299 --> 08:02:20,299
is always available. The province entries
are only 3700 available, the rest increase
6112
08:02:20,299 --> 08:02:21,299
our null increase, so province increase most
of the increase or null increase and they
6113
08:02:21,299 --> 08:02:22,299
are there, maybe we want to drop those or
maybe we want to impute those increase and
6114
08:02:22,299 --> 08:02:23,299
stuff like so, but they are not increased
that are available in the province column,
6115
08:02:23,299 --> 08:02:24,299
some of the province, some of the province
values are no longer available. Let's see
6116
08:02:24,299 --> 08:02:25,299
that here. For example, this is not available,
this is not available, this is not available.
6117
08:02:25,299 --> 08:02:26,299
And that's what the real state of the data
is this is not available, this is not available
6118
08:02:26,299 --> 08:02:27,299
and so on. So this can happen. Okay, next,
what we do is, we actually be actually use
6119
08:02:27,299 --> 08:02:28,299
the simple computer just to impute the missing
values. One ways to do that using simple mburo
6120
08:02:28,299 --> 08:02:29,299
from SK learn. Another way is, as we already
know, just df dot fill na fill na with, let's
6121
08:02:29,299 --> 08:02:30,299
say a bit let's say not available with let's
say a string, some string not available, that's
6122
08:02:30,299 --> 08:02:31,299
it that string and with that, if you fill
that fill any using that now, after that,
6123
08:02:31,299 --> 08:02:32,299
we will be having all that data, the missing
values will be filled according to Let's see
6124
08:02:32,299 --> 08:02:33,299
some missing values because in the province
there were some missing values. Now you can
6125
08:02:33,299 --> 08:02:34,299
see for example, let me go on and left Yeah,
so not available not available, we can we
6126
08:02:34,299 --> 08:02:35,299
can use that or we can use a fancy kind of
thing that is available by a psychic learn
6127
08:02:35,299 --> 08:02:36,299
and so on. Okay, after that, if you now see
the information info, now, you will not be
6128
08:02:36,299 --> 08:02:37,299
seeing any null value, all the columns are
there, oh, this was not in place. So don't
6129
08:02:37,299 --> 08:02:38,299
fill na that is let's change the DF with it.
So this doesn't happen in place, df just changed
6130
08:02:38,299 --> 08:02:39,299
the DF. Okay, df changes. Now, if we now call
the info, there is no null value anymore.
6131
08:02:39,299 --> 08:02:40,299
Yeah.
6132
08:02:40,299 --> 08:02:41,299
So I am this video here. In the next video,
I will show you this group by command to just
6133
08:02:41,299 --> 08:02:42,299
see these kind of stuff in a more detailed
way. Because this this particular video is
6134
08:02:42,299 --> 08:02:43,299
getting lamp here lanthier. me I'm stopping
here in this particular location. Next time,
6135
08:02:43,299 --> 08:02:44,299
I will show you the group by command in the
in the panda's data frame. And I will show
6136
08:02:44,299 --> 08:02:45,299
you what that does. So, we will explore all
that code that is written here. And we will
6137
08:02:45,299 --> 08:02:46,299
have in the in the upcoming videos when we
will see the plotting and matplotlib we will
6138
08:02:46,299 --> 08:02:47,299
be using the same data file to work more.
And to get more insight how the how this pandas
6139
08:02:47,299 --> 08:02:48,299
and matplotlib and NumPy in combination how
they can actually how they can actually play
6140
08:02:48,299 --> 08:02:49,299
a very important role in analyzing a very,
very large real data files. Okay, so I end
6141
08:02:49,299 --> 08:02:50,299
this video here. I will start the next video
right from this command. And I will tell you
6142
08:02:50,299 --> 08:02:51,299
what is happening what is the scope baikman
so hope to see you in the next video. Okay,
6143
08:02:51,299 --> 08:02:52,299
in the last video, we were discussing this
COVID-19 file, and we reached here but we
6144
08:02:52,299 --> 08:02:53,299
didn't use this SK learn in pewter, we just
use the fill na function of data frame. Now
6145
08:02:53,299 --> 08:02:54,299
let's discuss this group by command or a Curie
in in pandas that is much more visible. Let's
6146
08:02:54,299 --> 08:02:55,299
say our goal is now for example, if you go
to go back to Jupiter, if you see your dear
6147
08:02:55,299 --> 08:02:56,299
df dot head, or all, at the D f dot head,
let's attend records. If you want to see that
6148
08:02:56,299 --> 08:02:57,299
there are so many records, let's just see
10. Let's see, what you want to do is you
6149
08:02:57,299 --> 08:02:58,299
want to just see how many, how many total
confirmed cases are there in each country,
6150
08:02:58,299 --> 08:02:59,299
regardless of their date. And, for example,
you want to just see all the all the all the
6151
08:02:59,299 --> 08:03:00,299
confirmed cases, all the deaths, and all the
recovered cases in each country for all the
6152
08:03:00,299 --> 08:03:01,299
dates and for all the provinces combined together.
One way to do that is to write a group by
6153
08:03:01,299 --> 08:03:02,299
command for example. That's a df two equals
df dot group by and in group by what you see
6154
08:03:02,299 --> 08:03:03,299
is for what kind of columns you want to you
want to group all these all this data. So
6155
08:03:03,299 --> 08:03:04,299
for example, you want to group by country.
country. So that's your grouping. Now after
6156
08:03:04,299 --> 08:03:05,299
gopeng What do you want to see what kind of
what kind of what kind of, for example the
6157
08:03:05,299 --> 08:03:06,299
values you want to see because now you're
dropping? Well after grouping I really Want
6158
08:03:06,299 --> 08:03:07,299
to see because data is gone once I drop, all
the dates, they are grouped together all the
6159
08:03:07,299 --> 08:03:08,299
prevents that are grouped together. So, what
I really want to see is just the country and
6160
08:03:08,299 --> 08:03:09,299
I want to see the confirmed cases. So, pick
all these records confirmed, and then I want
6161
08:03:09,299 --> 08:03:10,299
to see deaths and recovered. So, for example,
if I want to deaths, and let's say then I
6162
08:03:10,299 --> 08:03:11,299
want to see the recovered cases are E and
just I want a big group all the countries
6163
08:03:11,299 --> 08:03:12,299
together group all these things together and
add all the records under each country. So
6164
08:03:12,299 --> 08:03:13,299
sum all of them, and maybe we want to reset
any index if it is there. So for example,
6165
08:03:13,299 --> 08:03:14,299
preset, we set index. So that So, after this
Curie For example, this group by query, what
6166
08:03:14,299 --> 08:03:15,299
will happen is this df two will contain a
summary of the data with respect to each country
6167
08:03:15,299 --> 08:03:16,299
and the total for example, in this particular
country, the total confirmed cases are these
6168
08:03:16,299 --> 08:03:17,299
all confirmed cases till now, and the deaths
of these and recovered as these for this country
6169
08:03:17,299 --> 08:03:18,299
for each country, now, each country is describing
Australia for example, in our till, till now,
6170
08:03:18,299 --> 08:03:19,299
Australia has total these confirmed cases,
these total deaths, and these are recovered
6171
08:03:19,299 --> 08:03:20,299
cases and so on. So, that is if we want to
group all these with respect to country, what
6172
08:03:20,299 --> 08:03:21,299
if we want to group all these with respect
to country and then date for example. So,
6173
08:03:21,299 --> 08:03:22,299
first we want to group them by country, so
country and then for each country, display
6174
08:03:22,299 --> 08:03:23,299
all the dates, and then do the same stuff,
the the Curie will stay almost the same. A
6175
08:03:23,299 --> 08:03:24,299
group by command will say almost the same
with one kind of
6176
08:03:24,299 --> 08:03:25,299
with one kind of let's say we want to first
group by country, once the, it is grouped
6177
08:03:25,299 --> 08:03:26,299
by the country, then I want to group them
by date. And now I want to see all the results
6178
08:03:26,299 --> 08:03:27,299
in the form of I want to see the data as well.
And what will happen now is for each country,
6179
08:03:27,299 --> 08:03:28,299
its trend with respect to all the dates that
will be displayed here. So let's see df two
6180
08:03:28,299 --> 08:03:29,299
now, df two. So if you see df two now, you
can see, for example, this particular country,
6181
08:03:29,299 --> 08:03:30,299
it has just one record in this country, it
has one record, then this country for this
6182
08:03:30,299 --> 08:03:31,299
date has this record for the same country
and other date has same record and all the
6183
08:03:31,299 --> 08:03:32,299
data is also sorted. I mean, now you can see
all the records in a very incremental way.
6184
08:03:32,299 --> 08:03:33,299
So that may give you a very good look and
feel of what is happening or, for example.
6185
08:03:33,299 --> 08:03:34,299
Another thing What if you want to what if
you want to, for example, find out all the
6186
08:03:34,299 --> 08:03:35,299
records, all the records, you just want to
find out all the records? Let's do three,
6187
08:03:35,299 --> 08:03:36,299
four, which the the confirmed cases, for example,
the confirmed cases are are more than 100.
6188
08:03:36,299 --> 08:03:37,299
Let's find out all the records. Let's, let's
let's let's get just let's just pick all the
6189
08:03:37,299 --> 08:03:38,299
records for which the confirmed cases are
larger than 100. And let's copy all these
6190
08:03:38,299 --> 08:03:39,299
records just those records in this. So if
we do that, we have d3 available, and we have
6191
08:03:39,299 --> 08:03:40,299
d3. This, I mean, these are just the records
in which the confirmed cases are for sure
6192
08:03:40,299 --> 08:03:41,299
larger than 100. Just those. Yeah, so we can
do. I mean a lot of a lot of data analysis,
6193
08:03:41,299 --> 08:03:42,299
the real data analysis, a lot of a lot more,
I've just shown you a very small snapshot
6194
08:03:42,299 --> 08:03:43,299
of what we can do with pandas on the real
data set. I mean, there is a lot more that
6195
08:03:43,299 --> 08:03:44,299
we can do with this pandas library, on real
data sets on multiple data files, combining
6196
08:03:44,299 --> 08:03:45,299
them together, joining them together, seeing
their correlation, a lot of stuff. And this
6197
08:03:45,299 --> 08:03:46,299
pandas really is a very, very fancy and very
high level library, very high level package
6198
08:03:46,299 --> 08:03:47,299
to work with data. So due to time limitations,
I'm just ending this pandas here although
6199
08:03:47,299 --> 08:03:48,299
there is much more to explain in that, but
in the next video we will be jumping towards
6200
08:03:48,299 --> 08:03:49,299
matplotlib just we will see some some functions
of matplotlib. And we will see very briefly
6201
08:03:49,299 --> 08:03:50,299
how can we plot How can we analyze data using
visual graphs or stuff like so. So, that that
6202
08:03:50,299 --> 08:03:51,299
sometimes this visualization of different
attributes of the data give very good insight
6203
08:03:51,299 --> 08:03:52,299
to the data wherever possible, wherever possible.
If the visualization is possible if the data
6204
08:03:52,299 --> 08:03:53,299
dimensionality in a way are the visualization
techniques are in a way that you can visualize
6205
08:03:53,299 --> 08:03:54,299
the trends in the data, that gives you much
more much better insight than the numbers
6206
08:03:54,299 --> 08:03:55,299
or statistical results, but it completely
depends in what situation you can visualize
6207
08:03:55,299 --> 08:03:56,299
the data there are situations, high dimensional
data, for example, is not always visualizable.
6208
08:03:56,299 --> 08:03:57,299
So, in those cases, the statistical results
of the numbers may play a more important role.
6209
08:03:57,299 --> 08:03:58,299
But in more in many cases, visualization give
a very good initial insight into the data
6210
08:03:58,299 --> 08:03:59,299
and the design process can become very, very
fast if you know something about the data,
6211
08:03:59,299 --> 08:04:00,299
whether you get that information by visualization
or by other statistics or whatever. So, in
6212
08:04:00,299 --> 08:04:01,299
the next video, I will be just explaining
some very few functions of matplotlib. And
6213
08:04:01,299 --> 08:04:02,299
then we will be, then we will be exploring
the same file, and we will be doing some stuff.
6214
08:04:02,299 --> 08:04:03,299
Doing some stuff using the plots and matplotlib.
And doing, seeing the trends of death rates,
6215
08:04:03,299 --> 08:04:04,299
seeing the trends of I mean, we'll be playing
with this file a bit more using matplotlib
6216
08:04:04,299 --> 08:04:05,299
as well. So hope to see you in the next video.
Okay, in this video, I'm going to discuss
6217
08:04:05,299 --> 08:04:06,299
matplotlib a very powerful package for plotting
graphs and scatter plots, line plots and 3d
6218
08:04:06,299 --> 08:04:07,299
plots and plots on the globe and whatnot,
I mean, very, very powerful tool. The most
6219
08:04:07,299 --> 08:04:08,299
important module in this matplotlib, or the
most popular module, or the most used module
6220
08:04:08,299 --> 08:04:09,299
is biplot. So we can import matplotlib.pi
plot as PLT. Another way of writing the same
6221
08:04:09,299 --> 08:04:10,299
kind of stuff is we can we can write like
from Matt matplotlib
6222
08:04:10,299 --> 08:04:11,299
from matplotlib import by plot as PLT. So
either way is fine whether we write this as
6223
08:04:11,299 --> 08:04:12,299
a documentation or that one that is fine as
MP is for NumPy. So let's create some points,
6224
08:04:12,299 --> 08:04:13,299
just just just make our first plot. Let's,
let's make some points starting from zero,
6225
08:04:13,299 --> 08:04:14,299
let's say all the points starting from zero
till 10. And let's create 1000 points in between.
6226
08:04:14,299 --> 08:04:15,299
One way to do that is to use built in function
or a method in NumPy, which is linspace or
6227
08:04:15,299 --> 08:04:16,299
linearly spaced points starting from zero
ending at 10. And there are 1000 of those
6228
08:04:16,299 --> 08:04:17,299
points. Let's say this is our x and this is
our let's say y which is NP dot sine, the
6229
08:04:17,299 --> 08:04:18,299
sine function is actually will apply element
by element on this NumPy array. And then this
6230
08:04:18,299 --> 08:04:19,299
PLT will plot will actually plot x comma y
all the points in front of you. So let's go
6231
08:04:19,299 --> 08:04:20,299
to Jupyter Notebook and actually see this
matplotlib in running form for the very first
6232
08:04:20,299 --> 08:04:21,299
time, oh, we have seen this matplotlib. When
we saw NP dot random, we only plotted a histogram.
6233
08:04:21,299 --> 08:04:22,299
While this is not the first time we actually
have seen this once, once, once before. So
6234
08:04:22,299 --> 08:04:23,299
import mat plot lib.pi plot as PLT. That's
your import command. For example. Now PLT
6235
08:04:23,299 --> 08:04:24,299
is available. Let's say x is NP dot Lin. space.
Let's start from zero. Go to 10 and generate
6236
08:04:24,299 --> 08:04:25,299
let's say 1000 points. That's it. That's your
x, y might be your MP dot sine x. That's it.
6237
08:04:25,299 --> 08:04:26,299
That's your y. And then what you do is you
say okay, PLT dot plot, x comma y point by
6238
08:04:26,299 --> 08:04:27,299
point, and then you press Shift, enter. That's
it. Oh, this plot is there in front of you.
6239
08:04:27,299 --> 08:04:28,299
That simple. I mean, that simple. Can you
imagine? This? Is that simple? Yeah, this
6240
08:04:28,299 --> 08:04:29,299
is that simple. So I'm in plotting. This is
a line plot. For example, if we want a scatterplot,
6241
08:04:29,299 --> 08:04:30,299
we can say okay, PLT dot scatter, there is
a scatter function that allows us to plot
6242
08:04:30,299 --> 08:04:31,299
all these endpoints form rather than rather
than this line form. These are all these a
6243
08:04:31,299 --> 08:04:32,299
lot of points. That's why you you're not seeing
these scatters. So let me let me let me take
6244
08:04:32,299 --> 08:04:33,299
this n x s viewer. Let's see. Let's take x
as let's just take a few points, let's say
6245
08:04:33,299 --> 08:04:34,299
just just just 30 points. Let's see the corresponding
30 points, see, they remember the indexing
6246
08:04:34,299 --> 08:04:35,299
of NumPy arrays and just using that. So now
use the scatter plots, and you have this,
6247
08:04:35,299 --> 08:04:36,299
oh, that's a scatter. Maybe we want to use,
let's say, start from the very beginning,
6248
08:04:36,299 --> 08:04:37,299
due to end and big every, let's say, attempt
point. And do the same with why, just to just
6249
08:04:37,299 --> 08:04:38,299
to see a plot in a better way, just sample
some points. So that's the scatterplot. It
6250
08:04:38,299 --> 08:04:39,299
is just like I'm in the points and so on.
It is not a it is not a continuous plot, like
6251
08:04:39,299 --> 08:04:40,299
the line plot, it's a scatterplot, we're going
to annotate this scatter plot, we can change
6252
08:04:40,299 --> 08:04:41,299
these colors to any color we want. For example,
we can we can have a prop property, for example,
6253
08:04:41,299 --> 08:04:42,299
color is equal to let's say, red, and everything
will become red. Yeah, so that's right, we
6254
08:04:42,299 --> 08:04:43,299
can have I mean, we can label it we can x
label it, we can via label, there are a lot
6255
08:04:43,299 --> 08:04:44,299
of properties. But but the but the main point
is plotting is that simple plotting is that
6256
08:04:44,299 --> 08:04:45,299
quick, using matplotlib. So yeah, this matplotlib
is really, really powerful, we have just seen
6257
08:04:45,299 --> 08:04:46,299
a snapshot, just a plot function and a scatter
function there, there are a lot of properties
6258
08:04:46,299 --> 08:04:47,299
to be said, there are a lot of things to be
considered. And we will see we will see actually
6259
08:04:47,299 --> 08:04:48,299
one one lanthier good use on this COVID-19
file. And we will we will actually analyze
6260
08:04:48,299 --> 08:04:49,299
the data trends and the confirmed trends and
some trends that and we will plot them and
6261
08:04:49,299 --> 08:04:50,299
see the trends really using matplotlib. So
But before that, let me let me show you that.
6262
08:04:50,299 --> 08:04:51,299
If you call for if you call this plot multiple
times, for example, maybe with different colors,
6263
08:04:51,299 --> 08:04:52,299
then you will be having a lot of curves on
the same on the same plot, for example. So
6264
08:04:52,299 --> 08:04:53,299
for example, let's see PLT dot plot x comma
y, let's say with with color, let's say color
6265
08:04:53,299 --> 08:04:54,299
equals to blue.
6266
08:04:54,299 --> 08:04:55,299
You can write blue, the whole or you can like
write just be that's fine PLT dot plot, x,
6267
08:04:55,299 --> 08:04:56,299
and let's say NP dot cause x and the color
you are interested in, and let's say the color
6268
08:04:56,299 --> 08:04:57,299
is, let's say green. And that's perfectly
okay. And that will give you two plots in
6269
08:04:57,299 --> 08:04:58,299
the same figure, sort of, and you can just
good to go. Well, yeah, so that more you can,
6270
08:04:58,299 --> 08:04:59,299
for example, you can plot with a green, green
color, and you want the solid line, or you
6271
08:04:59,299 --> 08:05:00,299
want, for example, Seon color in a dashed
line, or you want a dash and dot black line
6272
08:05:00,299 --> 08:05:01,299
or, or maybe you want to completely dotted
line in red color. So there are several things
6273
08:05:01,299 --> 08:05:02,299
that are available in matplotlib. This is
just a very few very simple snapshot. And
6274
08:05:02,299 --> 08:05:03,299
I have given you a very quick start in and
actually actually the whole point is using
6275
08:05:03,299 --> 08:05:04,299
Matlab is that quick, I mean, you can you
have your data, you just plug in their data,
6276
08:05:04,299 --> 08:05:05,299
you just call the plot function, and you're
good to go for analysis. Okay. In the next
6277
08:05:05,299 --> 08:05:06,299
video, we are where we will actually walk
through the we will actually walk through
6278
08:05:06,299 --> 08:05:07,299
the COVID-19 data set. And we'll actually
analyze the trends and to add the death rate
6279
08:05:07,299 --> 08:05:08,299
transfer each country individually, and then
we will see the depth confirmed and the recovery
6280
08:05:08,299 --> 08:05:09,299
trend of the overall world till the 16th of
March till the day till the data data is available.
6281
08:05:09,299 --> 08:05:10,299
So next video will be actually the viewer
will see the running form of pandas and matplotlib.
6282
08:05:10,299 --> 08:05:11,299
Together, so hope to see you in the next video.
Okay, I already have shown you the COVID-19
6283
08:05:11,299 --> 08:05:12,299
file. And here I have a notebook on that that
uses matplotlib and pandas to find out the
6284
08:05:12,299 --> 08:05:13,299
depths conformations and recovery trends using
using different plots. So let me import all
6285
08:05:13,299 --> 08:05:14,299
the packages that I need. I need a plot by
plot function from matplotlib. I need pandas
6286
08:05:14,299 --> 08:05:15,299
somewhere I need NumPy. And I'm using a simple
mburo here for missing values. So let's run
6287
08:05:15,299 --> 08:05:16,299
this. Let's run this command. And yes, everything
is imported. Now let's load the data that
6288
08:05:16,299 --> 08:05:17,299
I've shown you earlier. The data is available
now. And let's run this thing that is the
6289
08:05:17,299 --> 08:05:18,299
first 50 Records. Yeah, remember that? Yeah,
so that's the data that is available if if
6290
08:05:18,299 --> 08:05:19,299
you just want another view another view of
the data That's the data file, which is COVID-19
6291
08:05:19,299 --> 08:05:20,299
file. And it has observation day province
country, last update, confirm, to date, death
6292
08:05:20,299 --> 08:05:21,299
to date and recover to date for each country
and for each province individually. Okay,
6293
08:05:21,299 --> 08:05:22,299
great. So that's what we have. Now what we
can do is, now let's drop the serial numbers
6294
08:05:22,299 --> 08:05:23,299
and last update using in place that and rename
the columns that we did already in a previous
6295
08:05:23,299 --> 08:05:24,299
video as well. Let's convert the date into
the pandas built in date, frame. Okay, let's
6296
08:05:24,299 --> 08:05:25,299
use the psychic learn in pewter, sk learn
in pewter, using the constant strategy, there
6297
08:05:25,299 --> 08:05:26,299
are a lot of strategies there, let's use a
constant strategy. And this period or data
6298
08:05:26,299 --> 08:05:27,299
frame, in pure dot fit transform that will
help imputing all the missing values with
6299
08:05:27,299 --> 08:05:28,299
a constant strategy impure. So that's there.
Okay, next, let's apply this group by command
6300
08:05:28,299 --> 08:05:29,299
and group all of all the records using country
for each country. And for all the dates, let's
6301
08:05:29,299 --> 08:05:30,299
sum all the records that sum all the values
of records deaths and confirms using this,
6302
08:05:30,299 --> 08:05:31,299
but now let's first country and then all it
state, then the second country, then all it
6303
08:05:31,299 --> 08:05:32,299
states and so on. We have seen that in one
of our previous videos just running that again,
6304
08:05:32,299 --> 08:05:33,299
just for a double check. So that's what the
data state is. So country one all it states
6305
08:05:33,299 --> 08:05:34,299
country to all it states. So this country
has a lot of dates, then another country and
6306
08:05:34,299 --> 08:05:35,299
so on. Next, let's see how many countries
are there. In total, how many unique countries
6307
08:05:35,299 --> 08:05:36,299
are there. So what I, what I do is I find
the column, I actually pick the column with
6308
08:05:36,299 --> 08:05:37,299
country and call a unique function on that.
And that gives me all the countries without
6309
08:05:37,299 --> 08:05:38,299
repetition. And I just compute the length
length of countries tell me how many unique
6310
08:05:38,299 --> 08:05:39,299
countries are there in this data file?
6311
08:05:39,299 --> 08:05:40,299
There are 171 countries. So now my goal is
for each country, I want to see what is the
6312
08:05:40,299 --> 08:05:41,299
trend of with respect to the date as the data
is moving from the first day till 16th of
6313
08:05:41,299 --> 08:05:42,299
March? What is the trend of death? patients?
What is the trend of recovered patients and
6314
08:05:42,299 --> 08:05:43,299
what is a trend of confirmed patients as the
data moves on. So because we have 171 countries,
6315
08:05:43,299 --> 08:05:44,299
so let's loop over each country again, again,
and again, let's loop over what we do is for
6316
08:05:44,299 --> 08:05:45,299
ID x in the range of this, that's the loop
you remember that. And what I do is let's
6317
08:05:45,299 --> 08:05:46,299
find out the indices where the country is
like this, let's find out the index all the
6318
08:05:46,299 --> 08:05:47,299
indices where the country is like that. Then
what do you do I make a scatterplot. That,
6319
08:05:47,299 --> 08:05:48,299
with starting from this, and that, I just
pick the confirmed cases and all the confirmed
6320
08:05:48,299 --> 08:05:49,299
cases for this one country, I just pick those.
And I look, I do that using this scatterplot,
6321
08:05:49,299 --> 08:05:50,299
then I use another scatter plot, just to get
all the recovered cases, then I do another
6322
08:05:50,299 --> 08:05:51,299
scatter plot to get all the depth cases. And
then the title of the title of my figure becomes
6323
08:05:51,299 --> 08:05:52,299
the country name, the x labels the days, days
since the first suspect, the wire label is
6324
08:05:52,299 --> 08:05:53,299
the total number of cases, the legend command
actually will be there that will show what
6325
08:05:53,299 --> 08:05:54,299
eat that is in. So these kinds of labels that
are rewriting here, they will appear in the
6326
08:05:54,299 --> 08:05:55,299
figure, then we force them to show that in
each iteration show the show the fourth. So
6327
08:05:55,299 --> 08:05:56,299
this will show the trends of confirms to cover
some deaths for all 171 countries one by one.
6328
08:05:56,299 --> 08:05:57,299
So if we run this command, we'll be having
171 plots in front of us. Let's see all of
6329
08:05:57,299 --> 08:05:58,299
those one by one. So yeah, so this is for
the country. It has just one such thing. This
6330
08:05:58,299 --> 08:05:59,299
is for that this is for Afghanistan. As these
moves on the confirmed cases that are even
6331
08:05:59,299 --> 08:06:00,299
blue, they are moving up. These are the number
of cases. These are the number of days since
6332
08:06:00,299 --> 08:06:01,299
the first day. And the green is the number
of recovered cases for Albania. That's the
6333
08:06:01,299 --> 08:06:02,299
trend for Algeria. That's the trend. I mean,
these are each and everything is a separate
6334
08:06:02,299 --> 08:06:03,299
that is for Argentina. That is for America.
This is for America till 16th March, by the
6335
08:06:03,299 --> 08:06:04,299
way, today. The new says that America is really
in as dangerous position anyways, that's for
6336
08:06:04,299 --> 08:06:05,299
Australia till till the date we have to do
that is for Austria. Yeah, so these are all
6337
08:06:05,299 --> 08:06:06,299
the trends for all the countries. You see
I'm in the matplotlib how powerful that is.
6338
08:06:06,299 --> 08:06:07,299
Although I walked through this code very quickly,
but you can see this video again and again.
6339
08:06:07,299 --> 08:06:08,299
And then check how that happens. Yeah. So
that's what this is for Finland. Oh, Finland
6340
08:06:08,299 --> 08:06:09,299
is also in trouble. So France. Okay. So that
is for Germany. And yeah, so all the countries
6341
08:06:09,299 --> 08:06:10,299
that are available in data set, they have
these kind of plots. This is for Hong Kong.
6342
08:06:10,299 --> 08:06:11,299
And this is for India. And this is for Italy's
or Italy's. Yeah. So that's it. So that is
6343
08:06:11,299 --> 08:06:12,299
for each country individually, what if we
want the overall trend, or the overall confirm
6344
08:06:12,299 --> 08:06:13,299
and the deaths and the recover trend for all
the world together, so what I do is I big
6345
08:06:13,299 --> 08:06:14,299
I grew up all the data with date. So I pick
the first date, and add all the records, then
6346
08:06:14,299 --> 08:06:15,299
the second date for all the records for all
the countries and so on. And then I plot the
6347
08:06:15,299 --> 08:06:16,299
trend using the scatterplot, again, confirmed
record. And that's for all over the world
6348
08:06:16,299 --> 08:06:17,299
and see the trend, where the world is moving.
So that's the trend of the world. As the days
6349
08:06:17,299 --> 08:06:18,299
are going on, these are the depth grand, that's
a recovery trend. And that's a confirmation
6350
08:06:18,299 --> 08:06:19,299
trend that is moving on. Although I walked
through or this notebook, the notebook will
6351
08:06:19,299 --> 08:06:20,299
be available to you. I walk over this notebook
very quickly. But the goal was really to show
6352
08:06:20,299 --> 08:06:21,299
you the the I mean, that was a file may not
be that informative, if you see that in Excel,
6353
08:06:21,299 --> 08:06:22,299
but now it makes much more sense. When you
see these blobs you know what is happening
6354
08:06:22,299 --> 08:06:23,299
and you have insight in the data. And later
on, we may we may want to predict we may want
6355
08:06:23,299 --> 08:06:24,299
to make predictions. And the next date what
is going to happen, we may want to predict
6356
08:06:24,299 --> 08:06:25,299
using this plot or using some Machine Learning
Library like psychic learn or TensorFlow or
6357
08:06:25,299 --> 08:06:26,299
something like that. Okay, so that's it. I
can talk much more about pandas NumPy matplotlib
6358
08:06:26,299 --> 08:06:27,299
of there are so many other data science packages,
very important packages, one of those is SK
6359
08:06:27,299 --> 08:06:28,299
learn, we can that is for machine learning
basic machine learning. Then there are other
6360
08:06:28,299 --> 08:06:29,299
packages like TensorFlow for deep learning
by torch for deep learning. There are a lot
6361
08:06:29,299 --> 08:06:30,299
of packages with a lot of speciality is in
data science and stuff. I just discussed a
6362
08:06:30,299 --> 08:06:31,299
few of those the most important of those do
to manipulate the data to make predictions
6363
08:06:31,299 --> 08:06:32,299
to make classification or regressions. For
one, one way is to go to SK learn or psychic
6364
08:06:32,299 --> 08:06:33,299
learn. And if the data is huge, and you have
a lot of large amount of data, and you have
6365
08:06:33,299 --> 08:06:34,299
good expertise or deep learning, then you
should go to either TensorFlow or pytorch
6366
08:06:34,299 --> 08:06:35,299
these are the Python packages that are available
for predictions, classification, regression
6367
08:06:35,299 --> 08:06:36,299
and a lot more, but either way, whether you
are going to use scikit learn whether you're
6368
08:06:36,299 --> 08:06:37,299
going to use TensorFlow or pytorch either
way, you have to use pandas NumPy and sometimes
6369
08:06:37,299 --> 08:06:38,299
matplotlib to pre process the data and to
make the data ready for for these kind of
6370
08:06:38,299 --> 08:06:39,299
libraries to to perform predictions, either
a either in the form of classification or
6371
08:06:39,299 --> 08:06:40,299
in the form of regression. So so so this whole
course was about for for beginners who want
6372
08:06:40,299 --> 08:06:41,299
to who want to learn Python, specifically,
I discussed a lot about the in a lot about
6373
08:06:41,299 --> 08:06:42,299
Python in general, then then then I spend
some time not a lot amount of time sometimes
6374
08:06:42,299 --> 08:06:43,299
on exploring the data science packages as
well. But, I mean, there is no end we can
6375
08:06:43,299 --> 08:06:44,299
explore more, we can talk about the packages
more we can talk about other features of Python
6376
08:06:44,299 --> 08:06:45,299
more, a lot of I mean, input formatting, output
formatting, modules, packages, standard template
6377
08:06:45,299 --> 08:06:46,299
library, file handling Internet Access database,
6378
08:06:46,299 --> 08:06:47,299
I mean,
6379
08:06:47,299 --> 08:06:48,299
this is a whole universe, I have discussed
a few things for beginners. But But these
6380
08:06:48,299 --> 08:06:49,299
few things were very carefully selected for
data scientists. The if you have this course
6381
08:06:49,299 --> 08:06:50,299
available to you as you have gone through
all the course, you now have a very very good
6382
08:06:50,299 --> 08:06:51,299
understanding and now you can you can move
towards further edit advanced courses towards
6383
08:06:51,299 --> 08:06:52,299
data science and you will be ready to implement
the concepts in Python using using the packages
6384
08:06:52,299 --> 08:06:52,312
I have discussed so far. So I thank you all
and good luck.
786420
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.