Python Identifiers, A Python identifier is a name used to identify a variable, function, class, method, module, or other objects.
Python programs can be written using keywords (reserved words), identifiers, functions, data, and special characters.
Identifiers are names given to entities like classes, functions, variables, modules, objects, etc. These help to differentiate one entity from another.
The identifier should start with a character or Underscore then use a digit. The characters are A-Z or a-z, an UnderScore ( _ ), and digit (0-9). we should not use special characters ( #, @, $, %, * ) in identifiers.
Variable: A variable is a named memory location to store temporary data within a program, variables store in computer primary memory (RAM).
Example for Python Variables:
myCountry = “India”
_val = True
CITY = “Hyderabad”
abc789 = 1000
print (num, myCountry, _val, CITY, abc789)
Function: A function is a block of organized, reusable code that is used to perform a single, related action.
Example for A Python Function:
def add (num1, num2):
result = add(100, 670)
Example for A Python Class:
def sub (self, num1, num2):
def mul (self, num1, num2):
def div (self, num1, num2):
myobject = Calculator()
res = myobject.sub(1000, 789)
Naming conventions for Python identifiers:
- Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
- Starting an identifier with a single leading underscore indicates that the identifier is private.
- Starting an identifier with two leading underscores indicates a strongly private identifier.
- If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
Python Programming Language Tutorials