π₯ Missed This in Part 1! Here's What You Still Need to Know About Variables in Python
In the previous episode, we introduced variables and constants in Python, but guess what? Thereβs more you NEED to know before moving ahead!
In this video, we delve deeper into the best practices and important concepts that are often overlooked by beginners but make a significant difference.
π In this video, you'll learn:
How to name variables correctly in Python
What names should you AVOID (like reserved words)
How to assign values, including multiple assignments in one line
What does dynamic typing mean in Python
How to check the data type of a variable
Why certain words like if, class, or return cannot be used as variable names
No boring theory β just simple explanations, examples, and real talk so you actually get it.
Show More Show Less View Video Transcript
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
video because in the last video we
0:07
learned the basics of variables and
0:09
constants in Python but guess what
0:13
we didn't cover everything and there are
0:15
few more super useful tips and tricks
0:18
that you definitely need to know so
0:19
let's continue right from where we left
0:21
off i did that intentionally because
0:25
variables and constants are really
0:28
important things and and these are
0:30
actually the building blocks of
0:31
programming and I don't want it to be
0:34
more complex by just dumping everything
0:36
in one video so I want to make it a
0:39
parts and in this video we are going to
0:41
cover some more things related to the
0:43
variables so so first things first we
0:48
have to follow some naming rules when it
0:50
comes to assigning or creating a
0:53
variable so the rules of naming these
0:57
variables you have to follow these rules
0:59
you should never start with underscore
1:02
and you should uh start with letters you
1:06
have to always start with letters and
1:08
you can use underscore in between to u
1:11
when you're creating a variable name
1:13
which has more than one word then then
1:16
at that time you can give something like
1:18
this so you should always keep these
1:21
rules in mind whenever you are creating
1:23
a variable okay and now
1:28
let's start with more uh tips for naming
1:30
the variables and if you see here
1:35
the first things first do not use
1:37
reserved words because Python reserved
1:40
words are nothing but the keywords which
1:42
are already defined in Python it could
1:44
be a class or def if else while and
1:49
these you cannot give these as variable
1:51
names because they do have some special
1:53
meaning in programming language not just
1:55
in Python in any other programming
1:57
language when you are creating a
1:58
variable when you are defining a
2:00
variable you have to always keep that in
2:02
mind and check whether is that a
2:04
reserved word like is that word that you
2:07
are giving have any meaning in
2:09
programming especially in programming
2:11
like for example
2:14
class class is having it have some
2:17
meaning it is used in object- oriented
2:19
programming and I don't want you to
2:21
stress about this object- oriented
2:22
programming now this have some specific
2:25
meaning okay so always avoid reserved
2:29
words
2:30
I have to tell you the like the best
2:33
example for avoiding reserved words is
2:35
like if is actually a reserved word
2:38
because if is actually used to check the
2:40
condition of a particular thing and you
2:43
are using it as a variable and Python
2:46
will be really crazy on you thinking
2:49
like it if is if has some other meaning
2:51
and why this guy is using it as a
2:53
variable it will never understand what's
2:56
your intention if you give something
2:57
like this
2:59
so here is a quick example
3:03
so like even before running it is
3:05
actually saying there is something wrong
3:07
here right so it is actually expecting
3:10
me to keep this thing here but we are
3:14
actually assigning a variable and it is
3:16
not understanding what's going on so
3:18
that is why always keep that in mind
3:20
that never use reserved words and always
3:23
try to give a meaningful name because
3:26
instead of just writing X equal to,500
3:30
uh or something you can give something
3:33
like account balance equal to 1500 right
3:36
because now you'll understand rather
3:38
than keeping X here if you keep account
3:40
balance then it is more meaningful even
3:43
for you to understand and go through the
3:44
code
3:46
so that way anyone reading your code not
3:49
just you anyone reading your code
3:51
including the future you knows what that
3:54
value actually means
3:56
and also always try to stick with
3:59
English because even if you're
4:02
comfortable in another language English
4:04
makes it easier for others to
4:06
collaborate with you
4:08
so always try to use English rather than
4:11
any other language
4:14
and always always don't use any special
4:17
characters especially the symbols like
4:20
at the rate hashtag dollar percentage
4:23
and always stick to letters numbers and
4:26
underscores
4:28
so this is what you have to follow
4:32
instead of giving price dollars you can
4:34
give price USD
4:39
so these are the small things but they
4:41
really make your code cleaner easier to
4:43
read and less buggy trust me
4:48
and coming to the assignment in Python
4:51
let's talk about the assignment which is
4:53
just a fancy word for saying but it
4:56
tells Python something like hey Python
4:59
store this value inside this variable
5:04
store the value 10 in the variable
5:06
number store the value Mary in the
5:09
variable name store the value 1 th00and
5:12
in balance true in active so assignment
5:16
is nothing but equal to will tell the
5:20
computer tell the Python to store the
5:22
value inside the variable
5:24
so it is a way you are telling the
5:27
Python to save each of these values
5:29
under a particular name so can you so
5:32
you can use them later easy stuff right
5:36
so you can not just this you can also
5:39
actually store multiple assignments
5:42
multiple you can create multiple
5:44
variables and at the same time you can
5:46
assign multiple values
5:51
if you see here
5:54
I created three variables A B and C and
5:56
I gave 1 2 and three can you guess what
6:00
value is going to stored in what
6:02
variable i want you to pause at this
6:04
particular point and answer comment down
6:07
your answer just want to see how curious
6:10
you are when learning the Python
6:13
so what's going on here is one will be
6:16
stored in A and two will be stored in B
6:19
and three will be stored in C let's try
6:24
like for example A B and C
6:28
1 2 and three and when you print a
6:46
you see a value is one when you give b
6:50
it will be two
6:54
and also remember the small variable A
6:57
is different from the capital variable A
7:00
so this thing is also different and this
7:03
is these two are not same so Python will
7:06
think that this is a different variable
7:08
so always keep that in mind as well
7:13
now let's work on something awesome
7:15
which is dynamic typing so dynamic
7:18
typing is nothing but give whatever the
7:21
value that you want to give python will
7:23
understand you don't have to say that to
7:25
the Python that it is an integer it is a
7:28
float value it is a string it will
7:30
understand it's like I got it if you see
7:36
x = 10
7:39
and print
7:46
type of x this is for you to check
7:49
whether you're giving the right value or
7:51
right data type is running in the
7:53
program or not this is for you so when
7:57
you give the print type of x so it is
8:01
actually giving the class int int is
8:03
nothing but it is an integer value so
8:05
that is how it is giving an integer and
8:08
you can also try something like hello
8:12
and print type of y then it will give
8:14
you a string class then it will give you
8:17
a float class so python will actually
8:20
understand that it is an integer it is a
8:22
string and it is a float you don't have
8:24
to say to it that it is something
8:32
and you can use same variable and you
8:34
can give uh different data type python
8:37
will also understand and it will change
8:40
the type and value of the variable
8:42
accordingly
8:46
but if you want to check what type of
8:48
variable it is then you can check by
8:51
using this type function python type of
8:54
variable name then it will give you what
8:56
type is going on
9:00
so this is super helpful when you are
9:02
debugging or just want to make sure your
9:04
code is doing what you think it is
9:13
so let me just give you a quick heads up
9:16
and these are actually the reserved
9:18
words that you should never use
9:26
like you should never use and as assert
9:29
as sync so these are the keywords that
9:30
you have to keep that in mind whenever
9:33
you're creating a variable and check
9:35
whether it is a valid keyword in the
9:38
Python or not and then you can go and
9:41
also
9:43
this can be the rule one and also follow
9:45
the naming conventions always start with
9:48
the word rather than starting with the
9:50
number and don't use special characters
9:54
especially when you're uh using multiple
9:56
words in between
9:59
all right that was the deep dive into
10:01
the variables that we missed earlier and
10:04
we have covered the smart ways of naming
10:06
the variables and we have covered
10:10
assigning the values
10:13
and we also covered dynamic typing and
10:17
then we have covered the results
10:19
so
10:21
if you have enjoyed this series don't
10:23
forget to hit that like button and drop
10:25
a comment if you have got any questions
10:27
and subscribe to catch the next one
10:30
where we'll explore how Python reads
10:32
lines and how to write helpful comments
10:35
in your code thanks for watching and
10:37
I'll see you in the next
#Programming
#Education
#Computer Education

