Python Variable Names and Keywords

Variable Names:

A Programmer should always choose a meaningful name for their variable.

Rules for Variable Names:
  • A variable can contain both letters and numbers, but they cannot start with a number. So, variable1 is valid while 1variable is a invalid name.
  •  You may use uppercase letters for variable names but it is always perfectly fine to begin variable names with a lowercase letter.
  •  If your Variable name is long, then you can use underscore character (_) in the name. For example, top_five_members, var_1 etc. all are valid example.
  • You can’t use special characters like !, @, #, $, % etc. in variable name.
  • Python keywords cannot be used as variable name.

If you give a variable an illegal name, you will get a syntax error:

1var=20
class=5
global=10
all@1=100

 

Try it Yourself

1var is illegal because it begins with a number. all@ is illegal  because it contains a special character. class and global is illegal because they are keywords.

Keywords:

Python reserves 33 keywords in 3.3 versions for its use. Keywords are case sensitive in python. You can’t use a keyword as variable name, function name or any other identifier name. Here is the list of keywords in python.

 

Values, Variables and Types

Statements