Python Variable Naming Conventions
Note: This article is for my reference.
- Variable names cannot start with a number, like
1var
,2x
, and so on. - Variable names cannot start with special characters, like
!
,@
,#
,!y
,+
,-
, and so on. - Variable names are case sensitive. So,
Name
is not the same asname
. - Reserved words cannot be used as variable names. For example,
class
is a reserved word in Python. It cannot be used as a variable name. However,klass
andClass
work fine. Still, using the nameClass
could be regarded as poor programming practice since it could cause confusion for the reader.
These following words are part of Python's syntax and have specific meanings within the language. You cannot use them as variable names or any other identifiers in your Python code. Keep in mind that this list is based on Python 3.x versions, and newer versions might introduce additional reserved words or make changes.
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield
Post Tags: