0% found this document useful (0 votes)
9 views1 page

Python Variable Naming Rules Guide

Variable names in Python must begin with a letter or underscore, can include letters, numbers and underscores, are case sensitive, and cannot use reserved words. Good variable names should be meaningful, use consistent naming conventions like underscores or camel case for multiple words, and be short but meaningful.

Uploaded by

unknown45
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Python Variable Naming Rules Guide

Variable names in Python must begin with a letter or underscore, can include letters, numbers and underscores, are case sensitive, and cannot use reserved words. Good variable names should be meaningful, use consistent naming conventions like underscores or camel case for multiple words, and be short but meaningful.

Uploaded by

unknown45
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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