Today we shall discuss “Python Identifiers and Naming Conventions”.
A Python identifier is the name of a variable, function, class, module, or other object. We can say that Python Identifier is the name we use to identify a variable, function, class, module or other object in a Python program / script. We use identifiers to refer to the above mentioned entities in our program.
Rules for Naming Identifiers
- An identifier starts with a letter A to Z, or a to z, or an underscore (_).
- We may use zero or more letters, underscores, and digits (0 to 9).
- Python identifiers cannot contain special characters such as @, $, and %.
- Since Python is a case-sensitive language, so “Marks” and “marks” are different identifiers.
Python Naming Conventions
Furthermore, Python has the following naming conventions:
Class names should normally use the CapWords convention. Examples include:
Function and Variable Names
Function names should be lowercase, with words separated by underscores to improve readability.
Variable names follow the same convention as function names. Therefore we may give the following examples of variable names and function names:
Function name examples
Variable name examples
Constants are written in all capital letters with underscores to separate words. Examples of constants include:
Function and Method Arguments
Always use self for the first argument to instance methods.
Always use cls for the first argument to class methods.
Python Identifiers and Naming Conventions
36 total views, 1 views today