You are on page 1of 1

VARIABLE NAMING RULES IN PYTHON

We cannot use arbitrary strings as names of variables. The Python variable naming
rules are:

 Must begin with a letter (a - z, A - Z) or underscore (_).


 Other characters can be letters, numbers or _ only.
 Variable names are case sensitive.
 Reserved words cannot be used as a variable name.

Even when a variable name is “legal” (i.e., follows the rules), it might not be a “good”
name. Here are some generally accepted conventions for designing good names:

 A name should be meaningful: “price” is better than “p”.


 For a multiple-word name, use either the underscore as the delimiter (e.g.,
temp_var and interest_rate) or use camelCase capitalization (e.g., tempVar,
TempVar, interestRate or InterestRate); pick one style and use it consistently
throughout your program.
 Shorter meaningful names are better than longer ones.

You might also like