Coming to naming of a variable, there are certain rules to name a variable
... let's see what are them
-
We cannot use keyword as a varibale name.
So, what is a keyword ? A keyword is nothing but a word which has
specific definition for it or which are predefined by the interpreter
some of the key words are followed:
if, else, elif, sum, list, tuple, int, float , bool, class, def, break ,continue, pass , try, except ,etc....
-
We can use alphabets to name our variable
(from a-z and A-Z)
-
We can have numbers in our name of the variable
we can use numbers from 0 - 9
NOTE: we cannot use numbers in the beginning of a variable
like (0num, 234adre, 007number) these are not valid variables
-
We can use (_) underscore in our name of the varibale
NOTE: we can use _ anywhere i.e. in the starting of a variable in middle of
a variable and at the ending of a variable
So any variable name satisfies all the 4 conditions are valid variables
Example:
VALID:
-
num
-
num_2
-
num3
-
_num
-
n_u_m
-
Num4
INVALID:
-
0num - number at the beginning of the name
-
sum - cannot use keywords in name
-
-num - special character (-) is not allowed
-
$dun - sepcial character ($) is not allowed
-
class - keywords are not allowed
NOTE: Num and num are treated diffetent because python is a case sensitive language,
which means N and n are treated differently