0:00
hey guys welcome back to this channel if
0:02
you're new then welcome to this channel
0:03
well I'm back with one more interesting
0:05
Python video and today we are going to
0:08
talk about numeric numerical expressions
0:11
so far we have talked about variables
0:13
constants and how Python reads your
0:15
instructions line by line in today's
0:17
video we going to talk about something
0:19
that you'll use all the time which are
0:22
numeric expressions yep we are diving
0:25
into the math in Python but don't worry
0:28
this is not like your high school
0:29
algebra class it's way more chill and
0:33
once you get the hang of it you'll start
0:36
using like second nature and let's talk
0:42
are these numeric expressions
0:46
so what exactly is a numeric expression
0:48
basically it's just a math operation
0:51
like addition subtraction multip
0:54
multiplication and division that uses
0:57
numbers variables and arithmetic
1:00
operators in Python the most common
1:03
symbols that we use are addition
1:06
subtraction multiplication division and
1:10
until this you guys will know but there
1:13
are two more operators which are
1:15
exponent or power and one more which is
1:19
a modulus which we call remainder
1:23
so we'll explore that
1:29
so let's go through some clear examples
1:31
together so if you see the result and
1:35
here you see 10 + 5 so this is nothing
1:41
example if you say result
1:48
+ 5 then you can just print result
1:55
and it will print result for you
2:03
you will see 15 10 + 5 is 15 so this is
2:07
one's way like we are just adding 10 and
2:10
five nothing fancy here python reads it
2:12
and give you the result
2:18
and now let's try expressions with more
2:28
here I'll use comment
2:45
and just print the result
2:59
so the answer is 20 because first it
3:02
will add 7 + 3 which is 10 and into 2
3:08
so if you observe here is where it gets
3:11
interesting because without the
3:13
parenthesis Python would multiply first
3:15
even we do the same we will multi
3:17
multiply 7 into 2 and then we will add +
3:22
3 to it but the brackets force Python to
3:26
add these two numbers first 3 + 7 10 and
3:30
then it multiplies that by 2 so this is
3:34
how it follows and it changes the
3:37
priority of the operators by just
3:40
changing by just adding a bracket
3:46
so always always remember whatever
3:50
inside the bracket it will get done
3:53
first and it's just like doing math on
3:58
and now let's talk about variables in
4:01
expression and if you see here I'm
4:05
we can add let's take two variables X
4:18
like for example x = 5
4:35
and when you print the result
4:51
so here what's going on
4:54
actually 3 into 2 6 6 + 5 11 so it is
4:59
following this priority first these two
5:01
things and then this number adding that
5:05
so if you want to add these two numbers
5:08
first and then multiply it by two what
5:11
you have to do you have to just keep the
5:13
brackets and change the priority of the
5:17
operators and now the change C5 + 3 8 8
5:28
i hope you are getting it
5:32
and now let's talk about
5:38
all right you know division how to do it
5:45
10 by 2 and just print
5:55
it's 5.0 all obviously it will give the
5:58
value in float because division you're
6:01
dividing something then at the time it
6:03
will give you float python division
6:06
always gives you a float by default even
6:09
if the answer is a whole number so
6:11
instead of five you will see 5.0 and
6:13
that little 0 tells you it's a decimal
6:26
the expression with the power
6:30
so actually we can cover this concept in
6:34
here itself it's like you know uh like
6:37
if you have remember the maths
6:43
power 5 2^ 6 so that power operator is
6:46
nothing but these two stars so this is
6:49
nothing but two star 3 which means 2
6:51
cube which is 8 let me show you so
7:07
and you see now it will be 8 the output
7:10
will be 8 which is nothing but 2 cube is
7:16
2 into 2 into 2 like 2 is actually
7:22
multiplied three times
7:25
so that's why we use the power operator
7:28
there that's the only difference
7:31
so it'll be super handy when you're
7:33
dealing with formulas interest rates and
7:36
even you know when you are building
7:37
something cool some game logic so at the
7:41
time this will help you
7:45
so here it's nothing but expression with
7:51
you know whenever you give parenthesis
7:53
like we have did here the priority
7:56
changes so instead of giving priority to
8:01
we can add we can give priority to the
8:03
addition so that is what it meant so
8:05
that's why I gave one more example for
8:08
explaining the expression with
8:15
and now we also have to cover one more
8:18
operator which is modulus which is
8:21
nothing but it's like when you're
8:23
dividing two numbers and whatever the
8:26
remainder thing if when whenever you're
8:29
dividing two numbers like for example
8:42
here the remainder can be
8:54
one but we want that one as output so
8:59
you just have to give seven mod 2 and
9:06
so it'll give one like I'll give you one
9:10
uh good example example for this let's
9:13
say you have seven chocolates and you
9:16
have to share these seven chocolates to
9:22
so in order to share them equally you
9:25
have to give three and three to two
9:27
persons and the leftover chocolate how
9:30
many chocolates will be left so one so
9:33
that is what the output it will give you
9:36
so for example you have 10 chocolates
9:38
and you have to give you have to share
9:40
those chocolates to two members and then
9:43
when you're sharing them equally how
9:45
many chocolates will will left will be
9:47
left in your hand it'll be zero right so
9:51
that will be the remainder so just
9:55
just remember this cute logic my
9:58
professor used to explain us like this
10:01
with this good example I hope that will
10:07
So the remainder is zero i I hope that
10:10
you guys will remember so that's the
10:13
basics of numeric expressions in Python
10:15
like we we have worked with addition
10:17
subtraction multiplication dividing and
10:19
more and we also worked with the
10:22
exponential operation which is the power
10:25
one and we also worked with the modulus
10:35
and you will use this all the time
10:37
whether you are building a calculator or
10:39
when you are designing a game or just
10:42
working with numbers play around with
10:44
different combos try swapping
10:46
parenthesis and see how the results
10:48
change and that's the best way to lock
10:51
this into your brain
10:54
and let me know when you're ready for
10:55
the next part all right if you are
10:58
enjoying this series and learning
10:59
something new do me a quick favor hit
11:02
that like button smash the subscribe and
11:04
turn on the notifications so you don't
11:06
miss the next part where we'll dive into
11:09
the inputs and outputs in Python and
11:11
thanks for hanging out with me and let's
11:13
keep learning Python together and see