0:00
Hey guys, welcome back to another
0:02
episode of our Python exercise series
0:04
for beginners. And today we are diving
0:06
into exercise 8. And this one's all
0:10
about counting the numbers of characters
0:12
in a string. And it's really sounds
0:14
simple, but there's a small error in the
0:17
code. That might trip you up like
0:20
especially if you're new to Python.
0:22
So let's debug it together and learn a
0:25
simple super important concept while we
0:32
Okay, here is the original code.
1:07
and we are just printing the number of
1:13
So when we when it asks for the output
1:17
so it gives Python right and ideally it
1:20
should print the number of characters
1:21
six but this code won't work in fact
1:25
Python will throw an error and let me
1:27
show you why like there are two problems
1:29
in this line if you see here first look
1:32
very closely that closing quote is not a
1:36
standard double quote this can happen if
1:39
you copy paste code from a document or
1:42
any web page package and Python doesn't
1:44
recognize it and then obviously it will
1:47
throw an error saying that there's
1:49
something wrong with the syntax and the
1:52
second issue is we are trying to add a
1:54
string to an integer.
1:57
So count is actually a number and the
2:00
number of characters is actually a
2:02
string. So Python doesn't like mixing
2:04
types you know like that. So in order to
2:08
fix it, we need to convert the count to
2:19
and then you can add plus and always
2:22
keep the syntax in mind.
2:28
So this will be the corrected version of
2:32
So now if we type Python then obviously
2:40
the number of characters is six and yeah
2:43
you can give actually space here.
2:54
the number of characters is six.
2:57
So the key takeaways from this exercise
3:00
is always make sure the quotation marks
3:03
are standard like you have to follow the
3:06
same standard either a single quote or a
3:09
double quote and when putting if you're
3:12
combining text with numbers convert
3:15
numbers using a string or you can also
3:18
do maybe this one which is f strings
3:32
and you have to give f here
3:36
and this will also will work.
4:05
So now if you see here see the number of
4:08
characters is six. So you can either use
4:11
f strings or always try to keep that in
4:13
mind that whenever you are concatenating
4:16
two things like whenever you adding make
4:19
sure the type is same the left side and
4:22
the right side there's any one of it is
4:24
not right then make sure it's right by
4:27
using the type conversion by you know
4:29
changing the data types according to the
4:32
calculations something like that. So
4:35
these are basic but super important
4:37
habits to develop as you learn Python.
4:40
So if you found this video helpful,
4:42
don't forget to like, comment, and even
4:44
subscribe to stay updated with our
4:46
Python beginner series. And got stuck
4:48
anywhere? Drop your error in the
4:50
comments, and I'd love to help you out.
4:53
And catch you in the next one. Until
4:55
then, keep practicing and keep coding.