Identifiers:
These are the names that are used to identify the variables, functions, classes, modules or other objects. Whenever we define something in python and give it a name then we call it as an identifier.
Identifier Rules:
- Identifier cannot be a keyword.
- It is case sensitive.
- It may contain a single alphabet or a word or alpha-numeric.
- It cannot start with a digit, but can have a digit in the middle or last .
- It cannot have any other special character apart from ‘_’(underscore).
- It cannot start with a space or have a space in the middle.
- It can be of any length, but should be meaningful and readable.
Best Practices of Naming Identifiers
- Use snake_case for variables and functions:
Eg:
student_name, calculate_total, average_score
- Use PascalCase for class names:
Eg:
class StudentDetails:
pass
- Use UPPERCASE for constants:
Eg:
PI = 3.141
- Choose meaningful names:
Eg:
x = 10 # vague
marks_obtained = 10 # better