#02 - Naming A Variable


Coming to naming of a variable, there are certain rules to name a variable ... let's see what are them

  1. 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....

  2. We can use alphabets to name our variable (from a-z and A-Z)

  3. 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

  4. 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:

  1. num
  2. num_2
  3. num3
  4. _num
  5. n_u_m
  6. Num4


INVALID:

  1. 0num - number at the beginning of the name
  2. sum - cannot use keywords in name
  3. -num - special character (-) is not allowed
  4. $dun - sepcial character ($) is not allowed
  5. 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