Python Identifiers, A Python identifier is a name used to identify a variable, function, class, method, module, or other objects.
Python Identifiers
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:
num =10
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):
return (num1+num2)
result = add(100, 670)
print (x)
Example for A Python Class:
class Calculator():
abc =123
def sub (self, num1, num2):
return (num1-num2)
def mul (self, num1, num2):
return (num1*num2)
def div (self, num1, num2):
return (num1/num2)
myobject = Calculator()
res = myobject.sub(1000, 789)
print(res)
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
1. Introduction to Python Programming Language
2. Download and Install Python
Python Environment Setup (Using PyCharm IDE)
4. Python Keywords and Identifiers
9. Python Conditional Statements
11. Python Branching Statements
14. Python Data Structures – Lists
15. Python Data Structures – Sets
16. Python Data Structures – Tuples
17. Python Data Structures – Dictionaries
18. Python User Defined Functions
25. Python Regular Expressions
26. Python Object-Oriented Programming
29. Abstraction and Encapsulation in Python